Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(markdownit): separate directory for markdowit tests #5357

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 0 additions & 48 deletions src/tests/markdown.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import spec from "./fixtures/spec"
import markdownit from './../markdownit'
import { typesAvailable } from './../markdownit/callouts'
import {
Expand All @@ -15,53 +14,6 @@ import createEditor from "../EditorFactory";
* Please add test belonging to some Node or Mark to the corresponding file in './nodes/` or `./marks/`
*/

describe('Commonmark', () => {
const skippedMarkdownTests = [
// we interpret this as front matter
96, 98,
// contain HTML
21, 31, 201, 344, 474, 475, 476, 490, 493, 523, 535, 642, 643,
// contain comments
309, 308,
];

const normalize = (str) => {
// https://github.com/markdown-it/markdown-it/blob/df4607f1d4d4be7fdc32e71c04109aea8cc373fa/test/commonmark.js#L10
return str.replace(/<blockquote><\/blockquote>/g, '<blockquote>\n</blockquote>')
.replace(/<span class="keep-md">([^<]+)<\/span>/g, '$1')
.replace(/<br data-syntax=".{1,2}" \/>/g, '<br />\n')
.replace(/<ul data-bullet="."/g, '<ul')
}

// special treatment because we use markdown-it-image-figures
const figureImageMarkdownTests = [
516, 519, 530, 571, 572, 573, 574, 575, 576, 577, 579, 580, 581, 582, 583, 584, 585, 587, 588, 590
]

spec.forEach((entry) => {
// We do not support HTML
if (entry.section === 'HTML blocks' || entry.section === 'Raw HTML') return;

if (skippedMarkdownTests.indexOf(entry.example) !== -1) {
return
}

test('commonmark parsing ' + entry.example, () => {
let expected = entry.markdown.includes('__')
? entry.html.replace(/<strong>/g, '<u>').replace(/<\/strong>/g, '</u>')
: entry.html
if (figureImageMarkdownTests.indexOf(entry.example) !== -1) {
expected = expected.replace(/<p>/g, '<figure>').replace(/<\/p>/g, '</figure>')
}

const rendered = markdownit.render(entry.markdown)

// Ignore special markup for untouched markdown
expect(normalize(rendered)).toBe(expected)
})
})
})

describe('Markdown though editor', () => {
test('headlines', () => {
expect(markdownThroughEditor('# Test')).toBe('# Test')
Expand Down
74 changes: 0 additions & 74 deletions src/tests/markdownit.spec.js

This file was deleted.

30 changes: 30 additions & 0 deletions src/tests/markdownit/bulletList.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import markdownit from '../../markdownit'
import stripIndent from './stripIndent'

describe('markdownit', () => {

it('exposes bullet list markup', () => {
['*', '-'].forEach(bullet => {
const rendered = markdownit.render(`${bullet} first\n${bullet} second`)
expect(stripIndent(rendered)).toBe(stripIndent(`
<ul data-bullet="${bullet}">
<li>first</li>
<li>second</li>
</ul>`
))
})
})

it('renders bullet and task lists separately', () => {
const rendered = markdownit.render('* not a task\n* [ ] task')
expect(stripIndent(rendered)).toBe(stripIndent(`
<ul data-bullet="*">
<li>not a task</li>
</ul>
<ul class="contains-task-list" data-bullet="*">
<li class="task-list-item "><input class="task-list-item-checkbox" type="checkbox" disabled="" id="task-item-1" />task</li>
</ul>`
))
})

})
17 changes: 17 additions & 0 deletions src/tests/markdownit/callouts.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import markdownit from '../../markdownit'
import { typesAvailable } from '../../markdownit/callouts'
import stripIndent from './stripIndent.js'

describe('callouts', () => {
typesAvailable.forEach((type) => {
it(`render ${type}`, () => {
const rendered = markdownit.render(`::: ${type}\nHey there!\n:::`)
expect(stripIndent(rendered)).toBe(stripIndent(
`<div data-callout="${type}" class="callout callout-${type}">
<p>Hey there!</p>
</div>`
))
})
})
})

49 changes: 49 additions & 0 deletions src/tests/markdownit/commonmark.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import spec from "../fixtures/spec"
import markdownit from '../../markdownit'

describe('Commonmark', () => {
const skippedMarkdownTests = [
// we interpret this as front matter
96, 98,
// contain HTML
21, 31, 201, 344, 474, 475, 476, 490, 493, 523, 535, 642, 643,
// contain comments
309, 308,
];

const normalize = (str) => {
// https://github.com/markdown-it/markdown-it/blob/df4607f1d4d4be7fdc32e71c04109aea8cc373fa/test/commonmark.js#L10
return str.replace(/<blockquote><\/blockquote>/g, '<blockquote>\n</blockquote>')
.replace(/<span class="keep-md">([^<]+)<\/span>/g, '$1')
.replace(/<br data-syntax=".{1,2}" \/>/g, '<br />\n')
.replace(/<ul data-bullet="."/g, '<ul')
}

// special treatment because we use markdown-it-image-figures
const figureImageMarkdownTests = [
516, 519, 530, 571, 572, 573, 574, 575, 576, 577, 579, 580, 581, 582, 583, 584, 585, 587, 588, 590
]

spec.forEach((entry) => {
// We do not support HTML
if (entry.section === 'HTML blocks' || entry.section === 'Raw HTML') return;

if (skippedMarkdownTests.indexOf(entry.example) !== -1) {
return
}

test('commonmark parsing ' + entry.example, () => {
let expected = entry.markdown.includes('__')
? entry.html.replace(/<strong>/g, '<u>').replace(/<\/strong>/g, '</u>')
: entry.html
if (figureImageMarkdownTests.indexOf(entry.example) !== -1) {
expected = expected.replace(/<p>/g, '<figure>').replace(/<\/p>/g, '</figure>')
}

const rendered = markdownit.render(entry.markdown)

// Ignore special markup for untouched markdown
expect(normalize(rendered)).toBe(expected)
})
})
})
10 changes: 10 additions & 0 deletions src/tests/markdownit/imageFigures.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import markdownit from '../../markdownit'

describe('image figures extension', () => {

it('renders images as figures', () => {
expect(markdownit.render('[![moon](moon.jpg)](/uri)\n'))
.toBe('<figure><a href=\"/uri\"><img src=\"moon.jpg\" alt=\"moon\" /></a></figure>\n')
})

})
13 changes: 13 additions & 0 deletions src/tests/markdownit/mentions.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import markdownit from '../../markdownit'
import stripIndent from './stripIndent.js'

describe('markdownit', () => {

it('renders mentions of users with escaped whitespace', () => {
const rendered = markdownit.render('@[whitespace user](mention://user/whitespace%20user)')
expect(stripIndent(rendered)).toBe(stripIndent(`
<p><span class="mention" data-type="user" data-id="whitespace%20user">whitespace user</span></p>`
))
})

})
7 changes: 7 additions & 0 deletions src/tests/markdownit/stripIndent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function stripIndent(content) {
return content
.replace(/\n/g, "")
.replace(/[\t ]+\</g, "<")
.replace(/\>[\t ]+\</g, "><")
.replace(/\>[\t ]+$/g, ">")
}
19 changes: 19 additions & 0 deletions src/tests/markdownit/taskLists.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import markdownit from '../../markdownit'
import stripIndent from './stripIndent'

describe('task list extension', () => {

it('renders task lists', () => {
const rendered = markdownit.render('* [ ] task\n* not a task')
expect(stripIndent(rendered)).toBe(stripIndent(`
<ul class="contains-task-list" data-bullet="*">
<li class="task-list-item "><input class="task-list-item-checkbox" type="checkbox" disabled="" id="task-item-0" />task</li>
</ul>
<ul data-bullet="*">
<li>not a task</li>
</ul>`
))
})

})

Loading