Skip to content

Commit 8c3e4fa

Browse files
committed
test: fix lint formatting and jsx act warnings
1 parent 6c5e671 commit 8c3e4fa

4 files changed

Lines changed: 29 additions & 8 deletions

File tree

src/plugins/codemirror/CodeMirrorEditor.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@ import { indentWithTab } from '@codemirror/commands'
1212
import { basicLight } from 'cm6-theme-basic-light'
1313
import { basicSetup } from 'codemirror'
1414
import { $setSelection } from 'lexical'
15-
import { EMPTY_VALUE, codeBlockLanguages$, codeMirrorAutoLoadLanguageSupport$, codeMirrorExtensions$, getCodeBlockLanguageSelectData } from '.'
15+
import {
16+
EMPTY_VALUE,
17+
codeBlockLanguages$,
18+
codeMirrorAutoLoadLanguageSupport$,
19+
codeMirrorExtensions$,
20+
getCodeBlockLanguageSelectData
21+
} from '.'
1622
import { useCodeMirrorRef } from '../sandpack/useCodeMirrorRef'
1723
import { Select } from '../toolbar/primitives/select'
1824

src/plugins/core/MdastHTMLNode.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ export type MdxNodeType = MdastHTMLNode['type']
4343
*/
4444
export function isMdastHTMLNode(node: Mdast.Nodes): node is MdastHTMLNode {
4545
return (
46-
MDX_NODE_TYPES.includes(node.type as unknown as MdxNodeType) &&
47-
(htmlTags as readonly string[]).includes((node as MdastHTMLNode).name)
46+
MDX_NODE_TYPES.includes(node.type as unknown as MdxNodeType) && (htmlTags as readonly string[]).includes((node as MdastHTMLNode).name)
4847
)
4948
}
5049

src/test/codemirror.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { describe, expect, it } from 'vitest'
2-
import { getCodeBlockLanguageSelectData, normalizeCodeBlockLanguages, EMPTY_VALUE, type CodeBlockLanguageSupport } from '../plugins/codemirror'
2+
import {
3+
getCodeBlockLanguageSelectData,
4+
normalizeCodeBlockLanguages,
5+
EMPTY_VALUE,
6+
type CodeBlockLanguageSupport
7+
} from '../plugins/codemirror'
38

49
describe('normalizeCodeBlockLanguages', () => {
510
describe('record format', () => {

src/test/jsx.test.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react'
22
import { afterEach, describe, expect, it, vi } from 'vitest'
33
import { GenericJsxEditor, JsxComponentDescriptor, MDXEditor, MDXEditorMethods, jsxPlugin } from '../'
4-
import { render, act } from '@testing-library/react'
4+
import { render, act, waitFor } from '@testing-library/react'
55

66
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
77
;(globalThis as any).IS_REACT_ACT_ENVIRONMENT = true
@@ -23,6 +23,12 @@ afterEach(() => {
2323
vi.restoreAllMocks()
2424
})
2525

26+
const flushEditorUpdates = async () => {
27+
await act(async () => {
28+
await new Promise((resolve) => setTimeout(resolve, 0))
29+
})
30+
}
31+
2632
describe('jsx markdown import export', () => {
2733
// produces a warning about act
2834
it.todo('skips jsx import if not specified', async () => {
@@ -39,7 +45,7 @@ describe('jsx markdown import export', () => {
3945
expect(processedMarkdown).toEqual(markdown.trim())
4046
})
4147

42-
it('routes capitalized jsx components sharing an html tag name to the jsx visitor', () => {
48+
it('routes capitalized jsx components sharing an html tag name to the jsx visitor', async () => {
4349
const descriptors: JsxComponentDescriptor[] = [
4450
{
4551
name: 'Section',
@@ -52,6 +58,7 @@ describe('jsx markdown import export', () => {
5258
const { container } = render(
5359
<MDXEditor markdown={`<Section>Section content</Section>`} plugins={[jsxPlugin({ jsxComponentDescriptors: descriptors })]} />
5460
)
61+
await flushEditorUpdates()
5562
expect(container.querySelector('section')).toBeNull()
5663
})
5764

@@ -84,9 +91,13 @@ describe('jsx markdown import export', () => {
8491
]
8592

8693
act(() => {
87-
render(<MDXEditor ref={ref} markdown={`<Wrapper><Section /></Wrapper>`} plugins={[jsxPlugin({ jsxComponentDescriptors: descriptors })]} />)
94+
render(
95+
<MDXEditor ref={ref} markdown={`<Wrapper><Section /></Wrapper>`} plugins={[jsxPlugin({ jsxComponentDescriptors: descriptors })]} />
96+
)
97+
})
98+
await waitFor(() => {
99+
expect(ref.current?.getMarkdown() ?? '').toContain(`import { Wrapper, Section } from './components'`)
88100
})
89-
await new Promise((resolve) => setTimeout(resolve, 100))
90101

91102
const processedMarkdown = ref.current?.getMarkdown() ?? ''
92103

0 commit comments

Comments
 (0)