|
| 1 | +import test from 'ava' |
| 2 | +import { promises as fs } from 'fs' |
| 3 | +import { rollup } from 'rollup' |
| 4 | +import { fileURLToPath } from 'url' |
| 5 | +import rollupOrg from './index.js' |
| 6 | +import { renderToStaticMarkup } from 'react-dom/server' |
| 7 | +import { createElement } from 'react' |
| 8 | + |
| 9 | +test('@orgajs/rollup', async (t) => { |
| 10 | + await fs.writeFile(new URL('rollup.org', import.meta.url), '* Hi') |
| 11 | + |
| 12 | + const bundle = await rollup({ |
| 13 | + input: fileURLToPath(new URL('rollup.org', import.meta.url)), |
| 14 | + external: ['react/jsx-runtime'], |
| 15 | + plugins: [rollupOrg()], |
| 16 | + }) |
| 17 | + |
| 18 | + const { output } = await bundle.generate({ format: 'es', sourcemap: true }) |
| 19 | + |
| 20 | + await fs.writeFile(new URL('rollup.js', import.meta.url), output[0].code) |
| 21 | + |
| 22 | + /* @ts-expect-error file is dynamically generated */ |
| 23 | + // eslint-disable-next-line import/no-unresolved |
| 24 | + const { default: Content } = await import('./rollup.js') |
| 25 | + |
| 26 | + // t.is(output[0].map ? output[0].map.mappings : undefined, undefined) |
| 27 | + |
| 28 | + t.is( |
| 29 | + renderToStaticMarkup(createElement(Content)), |
| 30 | + '<div class="section"><h1>Hi</h1></div>' |
| 31 | + ) |
| 32 | + |
| 33 | + await fs.unlink(new URL('rollup.org', import.meta.url)) |
| 34 | + await fs.unlink(new URL('rollup.js', import.meta.url)) |
| 35 | +}) |
0 commit comments