Skip to content

Commit

Permalink
Test also markdown serialization
Browse files Browse the repository at this point in the history
As two different markdown strings can be semantically the same,
we can test if the resulting rendered HTML are syntactically equal.

Currently about hundred test cases fail because of a known limitation of
`prosemirror-markdown` not able to serialize nested marks correctly, see
ProseMirror/prosemirror-markdown#82

Signed-off-by: Ferdinand Thiessen <rpm@fthiessen.de>
  • Loading branch information
susnux committed Oct 28, 2022
1 parent 4cb7bf3 commit 39037a7
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/tests/markdown.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ const markdownThroughEditorHtml = (html) => {
describe('Commonmark', () => {
const skippedMarkdownTests = [
// contain HTML
21, 31, 201, 344, 474, 475, 476, 490, 493, 523, 535, 642, 643,
21, 31, 344, 474, 475, 476, 642, 643,
// contain comments
309, 308,
// < > are escaped, because HTML is disabled for markdown-it
201, 490, 493, 523, 535
];

const normalize = (str) => {
Expand All @@ -52,6 +54,18 @@ describe('Commonmark', () => {
// Ignore special markup for untouched markdown
expect(normalize(rendered)).toBe(expected)
})

test('commonmark serialization ' + entry.example, () => {
const expected = markdownit.render(entry.markdown)
const serialized = markdownThroughEditorHtml(expected)

try {
expect(markdownit.render(serialized)).toBe(expected)
} catch(e) {
// This is just for debugging, so jest shows also the difference within the two markdown source codes
expect(markdownit.render(serialized) + '\n\n' + serialized).toBe(expected + '\n\n' + entry.markdown)
}
})
})
})

Expand Down

0 comments on commit 39037a7

Please sign in to comment.