test(tiptap): add schema validation tests for md2json and json2md#3263
Merged
test(tiptap): add schema validation tests for md2json and json2md#3263
Conversation
Add comprehensive unit tests for the tiptap package to prevent schema validation errors like RangeError when loading content into the editor. Tests include: - md2json image handling (standalone, with title, multiple images, inline) - Nested structures (lists with images, blockquotes, headings) - Edge cases (empty markdown, whitespace, malformed syntax, long URLs) - Mixed content (text + images + lists + code blocks + task lists) - Schema validation using getSchema().nodeFromJSON() - Roundtrip validation (md -> json -> md -> json) - isValidTiptapContent function tests Also adds schema-validation.ts with reusable validation utilities: - validateJsonContent(): Returns validation result - assertValidSchema(): Throws on invalid content Related: #3245 Co-Authored-By: yujonglee <yujonglee.dev@gmail.com>
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
✅ Deploy Preview for hyprnote-storybook ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for hyprnote ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for howto-fix-macos-audio-selection canceled.
|
Add wrapInlineNodesInParagraphs() function that post-processes parsed JSON to ensure inline nodes (like images) are wrapped in paragraphs instead of being direct children of the doc node. This fixes the RangeError: Invalid content for node doc error that occurred when loading markdown with standalone images. The fix handles: - Standalone images at the doc level - Multiple consecutive images (each wrapped in separate paragraph) - Images mixed with other block content - Nested structures are not affected Also adds tests that specifically verify: - Standalone images are wrapped in paragraphs - Consecutive images are each wrapped separately - Issue #3245 scenario with _memo.md content Fixes #3245 Co-Authored-By: yujonglee <yujonglee.dev@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds comprehensive unit tests for the tiptap package to help prevent schema validation errors like the
RangeErrorin #3245. This PR introduces:New
schema-validation.tsutility with reusable validation functions:validateJsonContent()- validates JSON against ProseMirror schemaassertValidSchema()- throws on invalid contentExpanded test coverage for
md2json(30 new tests):getSchema().nodeFromJSON()isValidTiptapContentfunction testsReview & Testing Checklist for Human
validateJsonContentfunction usesschema.nodeFromJSON()which may pass even when the actual editor would throw a RangeError at runtime (as noted in Tiptap loading error #3245). Consider whether additional runtime validation is needed.schema-validation.tsis now exported from the shared module and could be used elsewhere in the codebase.pnpm -F @hypr/tiptap testto verify all 33 tests pass.Notes
These tests validate the current behavior of
md2json, not the fixed behavior proposed in #3245. The tests will help catch regressions and provide a foundation for testing future fixes.Related: #3245
Requested by: @yujonglee
Link to Devin run