Skip to content

test(tiptap): add schema validation tests for md2json and json2md#3263

Merged
yujonglee merged 2 commits intomainfrom
devin/1768948707-tiptap-schema-tests
Jan 21, 2026
Merged

test(tiptap): add schema validation tests for md2json and json2md#3263
yujonglee merged 2 commits intomainfrom
devin/1768948707-tiptap-schema-tests

Conversation

@devin-ai-integration
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot commented Jan 20, 2026

Summary

Adds comprehensive unit tests for the tiptap package to help prevent schema validation errors like the RangeError in #3245. This PR introduces:

  1. New schema-validation.ts utility with reusable validation functions:

    • validateJsonContent() - validates JSON against ProseMirror schema
    • assertValidSchema() - throws on invalid content
  2. Expanded test coverage for md2json (30 new tests):

    • Image handling (standalone, with title, multiple, 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

Review & Testing Checklist for Human

  • Verify the schema validation utilities work correctly - The validateJsonContent function uses schema.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.
  • Check if the exported utilities are appropriate - schema-validation.ts is now exported from the shared module and could be used elsewhere in the codebase.
  • Run pnpm -F @hypr/tiptap test to 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


Open with Devin

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>
@devin-ai-integration
Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR that start with 'DevinAI' or '@devin'.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@netlify
Copy link

netlify bot commented Jan 20, 2026

Deploy Preview for hyprnote-storybook ready!

Name Link
🔨 Latest commit f8f2cd9
🔍 Latest deploy log https://app.netlify.com/projects/hyprnote-storybook/deploys/69700f665ca74d0009f04709
😎 Deploy Preview https://deploy-preview-3263--hyprnote-storybook.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify
Copy link

netlify bot commented Jan 20, 2026

Deploy Preview for hyprnote ready!

Name Link
🔨 Latest commit f8f2cd9
🔍 Latest deploy log https://app.netlify.com/projects/hyprnote/deploys/69700f66f3c9a80008837e61
😎 Deploy Preview https://deploy-preview-3263--hyprnote.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify
Copy link

netlify bot commented Jan 20, 2026

Deploy Preview for howto-fix-macos-audio-selection canceled.

Name Link
🔨 Latest commit f8f2cd9
🔍 Latest deploy log https://app.netlify.com/projects/howto-fix-macos-audio-selection/deploys/69700f666ed98e0008d98b6c

Copy link
Contributor Author

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 3 additional flags.

Open in Devin Review

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>
@yujonglee yujonglee linked an issue Jan 21, 2026 that may be closed by this pull request
@yujonglee yujonglee merged commit d96930e into main Jan 21, 2026
19 of 20 checks passed
@yujonglee yujonglee deleted the devin/1768948707-tiptap-schema-tests branch January 21, 2026 00:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tiptap loading error

1 participant

Comments