|
| 1 | +import assert from 'node:assert/strict'; |
| 2 | +import { describe, it } from 'node:test'; |
| 3 | + |
| 4 | +import { loadGenerator } from '@doc-kit/core/generators/loader.mjs'; |
| 5 | +import { setConfig } from '@doc-kit/core/utils/configuration/index.mjs'; |
| 6 | +import { loadMarkdownPlugins } from '@doc-kit/core/utils/markdown/plugins.mjs'; |
| 7 | + |
| 8 | +import { processChunk } from '../generate.mjs'; |
| 9 | + |
| 10 | +await loadMarkdownPlugins( |
| 11 | + await loadGenerator(import.meta.resolve('../index.mjs')) |
| 12 | +); |
| 13 | + |
| 14 | +const createEntry = (api, name) => { |
| 15 | + const heading = { |
| 16 | + type: 'heading', |
| 17 | + depth: 1, |
| 18 | + children: [{ type: 'text', value: name }], |
| 19 | + data: { name, text: name, slug: api, type: 'module' }, |
| 20 | + }; |
| 21 | + |
| 22 | + return { |
| 23 | + api, |
| 24 | + path: `/${api}`, |
| 25 | + heading, |
| 26 | + stability: null, |
| 27 | + content: { |
| 28 | + type: 'root', |
| 29 | + children: [ |
| 30 | + heading, |
| 31 | + { |
| 32 | + type: 'paragraph', |
| 33 | + children: [{ type: 'text', value: `${name} body` }], |
| 34 | + }, |
| 35 | + ], |
| 36 | + }, |
| 37 | + }; |
| 38 | +}; |
| 39 | + |
| 40 | +describe('legacy-html processChunk', () => { |
| 41 | + it('does not change its input on the main thread', async () => { |
| 42 | + await setConfig({ target: ['legacy-html'] }); |
| 43 | + |
| 44 | + const fs = createEntry('fs', 'File system'); |
| 45 | + const before = structuredClone(fs); |
| 46 | + |
| 47 | + const [page] = await processChunk( |
| 48 | + [{ head: fs, nodes: [fs], headNodes: [fs] }], |
| 49 | + [0], |
| 50 | + '<a class="nav-fs" href="fs.html">File system</a>' |
| 51 | + ); |
| 52 | + |
| 53 | + assert.match(page.content, /File system body/); |
| 54 | + assert.deepEqual(fs, before); |
| 55 | + }); |
| 56 | +}); |
0 commit comments