1
1
import assert from 'node:assert/strict'
2
- import fs from 'node:fs'
3
- import path from 'node:path'
2
+ import fs from 'node:fs/promises'
4
3
import test from 'tape'
5
4
import { toHtml } from 'hast-util-to-html'
6
5
import { toHast } from 'mdast-util-to-hast'
@@ -171,7 +170,7 @@ test('markdown -> mdast', (t) => {
171
170
t . end ( )
172
171
} )
173
172
174
- test ( 'mdast -> markdown' , ( t ) => {
173
+ test ( 'mdast -> markdown' , async ( t ) => {
175
174
t . deepEqual (
176
175
toMarkdown (
177
176
{
@@ -386,14 +385,25 @@ test('mdast -> markdown', (t) => {
386
385
'should not escape colons in image (resource) labels'
387
386
)
388
387
389
- const files = fs . readdirSync ( 'test' ) . filter ( ( d ) => path . extname ( d ) === '.md' )
388
+ const root = new URL ( './' , import . meta. url )
389
+
390
+ const files = await fs . readdir ( root )
390
391
let index = - 1
391
392
392
393
while ( ++ index < files . length ) {
393
- const d = files [ index ]
394
- const stem = path . basename ( d , '.md' )
394
+ const file = files [ index ]
395
+
396
+ if ( ! / \. m d $ / . test ( file ) ) continue
397
+
398
+ const stem = file . split ( '.' ) . slice ( 0 , - 1 ) . join ( '.' )
399
+ const inputUrl = new URL ( file , root )
400
+ const expectedUrl = new URL ( stem + '.html' , root )
401
+
402
+ const input = await fs . readFile ( inputUrl )
403
+ const expected = String ( await fs . readFile ( expectedUrl ) )
404
+
395
405
const hast = toHast (
396
- fromMarkdown ( fs . readFileSync ( path . join ( 'test' , d ) ) , {
406
+ fromMarkdown ( input , {
397
407
extensions : [ gfmAutolinkLiteral ] ,
398
408
mdastExtensions : [ gfmAutolinkLiteralFromMarkdown ]
399
409
} ) ,
@@ -404,7 +414,6 @@ test('mdast -> markdown', (t) => {
404
414
allowDangerousHtml : true ,
405
415
entities : { useNamedReferences : true }
406
416
} )
407
- const expected = String ( fs . readFileSync ( path . join ( 'test' , stem + '.html' ) ) )
408
417
409
418
if ( actual . charCodeAt ( actual . length - 1 ) !== 10 ) {
410
419
actual += '\n'
0 commit comments