@@ -8,41 +8,40 @@ import test from 'node:test'
8
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
- import * as mod from '../index.js'
12
11
13
- test ( 'normalizeHeadings' , async ( ) => {
14
- assert . deepEqual (
15
- Object . keys ( mod ) . sort ( ) ,
16
- [ 'normalizeHeadings' ] ,
17
- 'should expose the public api'
18
- )
12
+ test ( 'normalizeHeadings' , async function ( t ) {
13
+ await t . test ( 'should expose the public api' , async function ( ) {
14
+ assert . deepEqual ( Object . keys ( await import ( '../index.js' ) ) . sort ( ) , [
15
+ 'normalizeHeadings'
16
+ ] )
17
+ } )
19
18
20
- await check ( 'no-headings' , 'No-op if there is no headings' )
21
- await check ( 'no-titles' , 'No-op if there is no top-level headings' )
22
- await check ( 'one-title' , 'No-op if there is a single top-level heading' )
23
- await check ( 'two-titles' , 'Makes the second header one level deeper' )
24
- await check ( 'more-titles' , 'Shifts all other headings one level deeper' )
25
- await check ( 'hierarchy' , 'There is no depth level 7' )
26
- } )
27
- /**
28
- * @param {string } test
29
- * @param {string } message
30
- * @returns {Promise<void> }
31
- */
32
- async function check ( test , message ) {
33
- const input = await fs . readFile (
34
- new URL ( 'fixture/' + test + '.in' , import . meta. url )
35
- )
36
- const output = await fs . readFile (
37
- new URL ( 'fixture/' + test + '.out' , import . meta. url )
38
- )
39
- const actual = fromMarkdown ( input )
40
- const expected = fromMarkdown ( output )
41
- normalizeHeadings ( actual )
19
+ /** @type {Record<string, string> } */
20
+ const cases = {
21
+ 'no-headings' : 'should be a no-op if there are no headings' ,
22
+ 'no-titles' : 'should be a no-op if there are no top-level headings' ,
23
+ 'one-title' : 'should be a no-op if there is a single top-level heading' ,
24
+ 'two-titles' : 'should make the second header one level deeper' ,
25
+ 'more-titles' : 'should shift all other headings one level deeper' ,
26
+ hierarchy : 'should be create a depth level 7'
27
+ }
42
28
43
- assert . deepEqual (
44
- removePosition ( actual , true ) ,
45
- removePosition ( expected , true ) ,
46
- message
47
- )
48
- }
29
+ for ( const [ name , message ] of Object . entries ( cases ) ) {
30
+ await t . test ( message , async function ( ) {
31
+ const input = await fs . readFile (
32
+ new URL ( 'fixture/' + name + '.in' , import . meta. url )
33
+ )
34
+ const output = await fs . readFile (
35
+ new URL ( 'fixture/' + name + '.out' , import . meta. url )
36
+ )
37
+ const actual = fromMarkdown ( input )
38
+ const expected = fromMarkdown ( output )
39
+ normalizeHeadings ( actual )
40
+
41
+ assert . deepEqual (
42
+ removePosition ( actual , true ) ,
43
+ removePosition ( expected , true )
44
+ )
45
+ } )
46
+ }
47
+ } )
0 commit comments