44 */
55
66import { getExtensionField } from '@tiptap/core'
7- import { test as baseTest } from 'vitest'
8- import { createRichEditor } from '../../EditorFactory.ts'
9- import { createMarkdownSerializer } from '../../extensions/Markdown.js'
107import markdownit from '../../markdownit/index.js'
118import { MathBlock , MathInline } from '../../nodes/Mathematics.js'
12- import { markdownThroughEditor } from '../testHelpers/markdown.js'
13-
14- const test = baseTest . extend ( {
15- // eslint-disable-next-line no-empty-pattern
16- editor : async ( { } , use ) => {
17- const editor = createRichEditor ( )
18- await use ( editor )
19- editor . destroy ( )
20- } ,
21- } )
9+ import testEditor from '../testHelpers/testEditor.ts'
10+
11+ const test = testEditor . override ( 'extensions' , [ MathBlock , MathInline ] )
2212
2313describe ( 'Mathematics nodes' , ( ) => {
2414 describe ( 'Node structure' , ( ) => {
@@ -38,38 +28,38 @@ describe('Mathematics nodes', () => {
3828 } )
3929
4030 describe ( 'Markdown roundtrip - Inline math' , ( ) => {
41- test ( 'simple inline formula' , ( ) => {
31+ test ( 'simple inline formula' , ( { markdownThroughEditor } ) => {
4232 expect ( markdownThroughEditor ( '$E=mc^2$' ) ) . toBe ( '$E=mc^2$' )
4333 } )
4434
45- test ( 'inline formula with complex LaTeX' , ( ) => {
35+ test ( 'inline formula with complex LaTeX' , ( { markdownThroughEditor } ) => {
4636 expect ( markdownThroughEditor ( '$\\sum_{i=1}^n i$' ) ) . toBe ( '$\\sum_{i=1}^n i$' )
4737 } )
4838
49- test ( 'inline formula with fractions' , ( ) => {
39+ test ( 'inline formula with fractions' , ( { markdownThroughEditor } ) => {
5040 expect ( markdownThroughEditor ( '$\\frac{a}{b}$' ) ) . toBe ( '$\\frac{a}{b}$' )
5141 } )
5242
53- test ( 'multiple inline formulas' , ( ) => {
43+ test ( 'multiple inline formulas' , ( { markdownThroughEditor } ) => {
5444 expect ( markdownThroughEditor ( '$a$ and $b$' ) ) . toBe ( '$a$ and $b$' )
5545 } )
5646
57- test ( 'inline formula in text' , ( ) => {
47+ test ( 'inline formula in text' , ( { markdownThroughEditor } ) => {
5848 expect ( markdownThroughEditor ( 'The formula $E=mc^2$ is famous.' ) ) . toBe ( 'The formula $E=mc^2$ is famous.' )
5949 } )
6050 } )
6151
6252 describe ( 'Markdown roundtrip - Block math' , ( ) => {
63- test ( 'simple block formula' , ( ) => {
53+ test ( 'simple block formula' , ( { markdownThroughEditor } ) => {
6454 expect ( markdownThroughEditor ( '$$\nE=mc^2\n$$' ) ) . toBe ( '$$\nE=mc^2\n$$' )
6555 } )
6656
67- test ( 'block formula with complex LaTeX' , ( ) => {
57+ test ( 'block formula with complex LaTeX' , ( { markdownThroughEditor } ) => {
6858 const input = '$$\n\\sum_{i=1}^n i = \\frac{n(n+1)}{2}\n$$'
6959 expect ( markdownThroughEditor ( input ) ) . toBe ( input )
7060 } )
7161
72- test ( 'block formula without newlines' , ( ) => {
62+ test ( 'block formula without newlines' , ( { markdownThroughEditor } ) => {
7363 // markdown-it-katex accepts this format too
7464 expect ( markdownThroughEditor ( '$$E=mc^2$$' ) ) . toBe ( '$$\nE=mc^2\n$$' )
7565 } )
@@ -152,23 +142,15 @@ describe('Mathematics nodes', () => {
152142 } )
153143
154144 describe ( 'Serialization to markdown' , ( ) => {
155- test ( 'serializes inline math node' , ( { editor } ) => {
145+ test ( 'serializes inline math node' , ( { editor, serializeMarkdown } ) => {
156146 editor . commands . insertInlineMath ( { latex : 'E=mc^2' } )
157147 editor . commands . insertContent ( ' some more text.' )
158-
159- const serializer = createMarkdownSerializer ( editor . schema )
160- const markdown = serializer . serialize ( editor . state . doc )
161-
162- expect ( markdown ) . toBe ( '$E=mc^2$ some more text.' )
148+ expect ( serializeMarkdown ( ) ) . toBe ( '$E=mc^2$ some more text.' )
163149 } )
164150
165- test ( 'serializes block math node' , ( { editor } ) => {
151+ test ( 'serializes block math node' , ( { editor, serializeMarkdown } ) => {
166152 editor . commands . insertBlockMath ( { latex : 'E=mc^2' } )
167-
168- const serializer = createMarkdownSerializer ( editor . schema )
169- const markdown = serializer . serialize ( editor . state . doc )
170-
171- expect ( markdown ) . toBe ( '$$\nE=mc^2\n$$' )
153+ expect ( serializeMarkdown ( ) ) . toBe ( '$$\nE=mc^2\n$$' )
172154 } )
173155 } )
174156} )
0 commit comments