/
index.test.js
51 lines (41 loc) · 1.52 KB
/
index.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
45
46
47
48
49
50
51
/**
* @typedef {import('mdx/types').MDXContent} MDXContent
*/
import {promises as fs} from 'fs'
import {fileURLToPath} from 'url'
import {test} from 'uvu'
import * as assert from 'uvu/assert'
import {rollup} from 'rollup'
import React from 'react'
import {renderToStaticMarkup} from 'react-dom/server'
import rollupMdx from '../index.js'
test('@mdx-js/rollup', async () => {
await fs.writeFile(
new URL('rollup.mdx', import.meta.url),
'export const Message = () => <>World!</>\n\n# Hello, <Message />'
)
const bundle = await rollup({
input: fileURLToPath(new URL('rollup.mdx', import.meta.url)),
external: ['react/jsx-runtime'],
plugins: [rollupMdx()]
})
const {output} = await bundle.generate({format: 'es', sourcemap: true})
await fs.writeFile(new URL('rollup.js', import.meta.url), output[0].code)
const Content = /** @type {MDXContent} */ (
/* @ts-expect-error file is dynamically generated */
(await import('./rollup.js')).default // type-coverage:ignore-line
)
assert.equal(
output[0].map ? output[0].map.mappings : undefined,
';;;MAAaA,OAAU,GAAA,MAAAC,GAAA,CAAAC,QAAA,EAAA;AAAQ,EAAA,QAAA,EAAA,QAAA;;;;;;;AAE7B,IAAA,QAAA,EAAA,CAAA,SAAA,EAAAD,GAAA,CAAA,OAAA,EAAA,EAAA,CAAA,CAAA;;;;;;;;;;;;',
'should add a source map'
)
assert.equal(
renderToStaticMarkup(React.createElement(Content)),
'<h1>Hello, World!</h1>',
'should compile'
)
await fs.unlink(new URL('rollup.mdx', import.meta.url))
await fs.unlink(new URL('rollup.js', import.meta.url))
})
test.run()