-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
44 lines (38 loc) · 1.33 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import assert from 'node:assert/strict'
import { test } from 'node:test'
import { compile, evaluate } from '@mdx-js/mdx'
import recmaPluginIsMdxComponent from 'recma-mdx-is-mdx-component'
// eslint-disable-next-line no-empty-function
function noop() {}
test('define isMDXComponent', async () => {
const { value } = await compile('', { recmaPlugins: [recmaPluginIsMdxComponent] })
assert.equal(
value,
[
'/*@jsxRuntime automatic @jsxImportSource react*/',
'MDXContent.isMDXComponent = true;',
'import {Fragment as _Fragment, jsx as _jsx} from "react/jsx-runtime";',
'function _createMdxContent(props) {',
' return _jsx(_Fragment, {});',
'}',
'function MDXContent(props = {}) {',
' const {wrapper: MDXLayout} = props.components || ({});',
' return MDXLayout ? _jsx(MDXLayout, Object.assign({}, props, {',
' children: _jsx(_createMdxContent, props)',
' })) : _createMdxContent(props);',
'}',
'export default MDXContent;',
''
].join('\n')
)
})
test('Can be evaluated', async () => {
const module = await evaluate('', {
recmaPlugins: [recmaPluginIsMdxComponent],
Fragment: noop,
jsx: noop,
jsxs: noop
})
// @ts-expect-error The type definitions don’t understand this property.
assert.equal(module.default.isMDXComponent, true)
})