From 2e30ee5a5bf640872ee705b20de79cdd224e6f73 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Fri, 28 Oct 2022 13:02:03 +0200 Subject: [PATCH 1/2] Test also markdown serialization 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 https://github.com/ProseMirror/prosemirror-markdown/issues/82 Signed-off-by: Ferdinand Thiessen --- src/tests/markdown.spec.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/tests/markdown.spec.js b/src/tests/markdown.spec.js index 05f288d49ab..9f1ef7adf4e 100644 --- a/src/tests/markdown.spec.js +++ b/src/tests/markdown.spec.js @@ -20,9 +20,11 @@ describe('Commonmark', () => { // we interpret this as front matter 96, 98, // 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) => { @@ -59,6 +61,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) + } + }) }) }) From c80460458d554b305f5dbf70051f3c1e7e4e0fe0 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Thu, 17 Nov 2022 19:00:59 +0100 Subject: [PATCH 2/2] Remove hacky testing of commonmark parsing testing The commonmark parsing tests are already done by markdownit, as suche we only need to test serializing. And of cause parsing of markdown extensions we added. The current "CommonMark" testing also had quite a lot of hacks as even if we are commonmark compatible we do not yield the same html representation (html is only a interim stage to tiptap). Signed-off-by: Ferdinand Thiessen --- src/tests/markdown.spec.js | 38 ++++++-------------------------------- 1 file changed, 6 insertions(+), 32 deletions(-) diff --git a/src/tests/markdown.spec.js b/src/tests/markdown.spec.js index 9f1ef7adf4e..169ef2280d8 100644 --- a/src/tests/markdown.spec.js +++ b/src/tests/markdown.spec.js @@ -15,6 +15,7 @@ import createEditor from "../EditorFactory"; * Please add test belonging to some Node or Mark to the corresponding file in './nodes/` or `./marks/` */ +// Goal: Input (commonmark) markdown should result in same output markdown describe('Commonmark', () => { const skippedMarkdownTests = [ // we interpret this as front matter @@ -24,45 +25,18 @@ describe('Commonmark', () => { // contain comments 309, 308, // < > are escaped, because HTML is disabled for markdown-it - 201, 490, 493, 523, 535 + //201, 490, 493, 523, 535 ]; - const normalize = (str) => { - // https://github.com/markdown-it/markdown-it/blob/df4607f1d4d4be7fdc32e71c04109aea8cc373fa/test/commonmark.js#L10 - return str.replace(/
<\/blockquote>/g, '
\n
') - .replace(/([^<]+)<\/span>/g, '$1') - .replace(/
/g, '
\n') - .replace(/
    { // We do not support HTML - if (entry.section === 'HTML blocks' || entry.section === 'Raw HTML') return; - - if (skippedMarkdownTests.indexOf(entry.example) !== -1) { + if (entry.section === 'HTML blocks' || + entry.section === 'Raw HTML' || + skippedMarkdownTests.indexOf(entry.example) !== -1) { return } - test('commonmark parsing ' + entry.example, () => { - let expected = entry.markdown.includes('__') - ? entry.html.replace(//g, '').replace(/<\/strong>/g, '') - : entry.html - if (figureImageMarkdownTests.indexOf(entry.example) !== -1) { - expected = expected.replace(/

    /g, '

    ').replace(/<\/p>/g, '
    ') - } - - const rendered = markdownit.render(entry.markdown) - - // Ignore special markup for untouched markdown - expect(normalize(rendered)).toBe(expected) - }) - - test('commonmark serialization ' + entry.example, () => { + test('serializing ' + entry.example, () => { const expected = markdownit.render(entry.markdown) const serialized = markdownThroughEditorHtml(expected)