|
2 | 2 | * @typedef {import('mdast').Root} Root
|
3 | 3 | */
|
4 | 4 |
|
5 |
| -import fs from 'node:fs' |
6 |
| -import path from 'node:path' |
7 |
| -import test from 'tape' |
8 |
| -import {remark} from 'remark' |
| 5 | +import assert from 'node:assert/strict' |
| 6 | +import fs from 'node:fs/promises' |
| 7 | +import test from 'node:test' |
| 8 | +import {fromMarkdown} from 'mdast-util-from-markdown' |
9 | 9 | import {removePosition} from 'unist-util-remove-position'
|
10 | 10 | import {normalizeHeadings} from '../index.js'
|
11 | 11 |
|
12 |
| -test('Multiple top-level headings', (t) => { |
13 |
| - check(t, 'no-headings', 'No-op if there is no headings') |
14 |
| - check(t, 'no-titles', 'No-op if there is no top-level headings') |
15 |
| - check(t, 'one-title', 'No-op if there is a single top-level heading') |
16 |
| - check(t, 'two-titles', 'Makes the second header one level deeper') |
17 |
| - check(t, 'more-titles', 'Shifts all other headings one level deeper') |
18 |
| - t.end() |
| 12 | +test('Multiple top-level headings', async () => { |
| 13 | + await check('no-headings', 'No-op if there is no headings') |
| 14 | + await check('no-titles', 'No-op if there is no top-level headings') |
| 15 | + await check('one-title', 'No-op if there is a single top-level heading') |
| 16 | + await check('two-titles', 'Makes the second header one level deeper') |
| 17 | + await check('more-titles', 'Shifts all other headings one level deeper') |
19 | 18 | })
|
20 | 19 |
|
21 |
| -test('Level 7', (t) => { |
22 |
| - check(t, 'hierarchy', 'There is no depth level 7') |
23 |
| - t.end() |
| 20 | +test('Level 7', async () => { |
| 21 | + await check('hierarchy', 'There is no depth level 7') |
24 | 22 | })
|
25 | 23 |
|
26 | 24 | /**
|
27 |
| - * @param {import('tape').Test} t |
28 | 25 | * @param {string} test
|
29 | 26 | * @param {string} message
|
| 27 | + * @returns {Promise<void>} |
30 | 28 | */
|
31 |
| -function check(t, test, message) { |
32 |
| - const input = fs.readFileSync(path.join('test', 'fixture', test + '.in')) |
33 |
| - const output = fs.readFileSync(path.join('test', 'fixture', test + '.out')) |
34 |
| - const root = /** @type {Root} */ (remark().parse(input)) |
| 29 | +async function check(test, message) { |
| 30 | + const input = await fs.readFile( |
| 31 | + new URL('fixture/' + test + '.in', import.meta.url) |
| 32 | + ) |
| 33 | + const output = await fs.readFile( |
| 34 | + new URL('fixture/' + test + '.out', import.meta.url) |
| 35 | + ) |
| 36 | + const actual = fromMarkdown(input) |
| 37 | + const expected = fromMarkdown(output) |
| 38 | + normalizeHeadings(actual) |
35 | 39 |
|
36 |
| - t.deepEqual( |
37 |
| - removePosition(normalizeHeadings(root), true), |
38 |
| - removePosition(remark().parse(output), true), |
| 40 | + assert.deepEqual( |
| 41 | + removePosition(actual, true), |
| 42 | + removePosition(expected, true), |
39 | 43 | message
|
40 | 44 | )
|
41 | 45 | }
|
0 commit comments