1
- import { promises as fs , readdirSync } from 'fs' ;
2
- import { join } from 'path' ;
1
+ import { readdir , readFile , writeFile } from 'node:fs/promises' ;
3
2
4
3
import { compile , compileSync } from '@mdx-js/mdx' ;
5
4
import remarkFrontmatter from 'remark-frontmatter' ;
@@ -8,14 +7,15 @@ import { equal, throws } from 'uvu/assert';
8
7
9
8
import remarkMdxFrontmatter from './index.js' ;
10
9
11
- const tests = readdirSync ( '__fixtures__' ) ;
10
+ const fixturesDir = new URL ( '__fixtures__/' , import . meta. url ) ;
11
+ const tests = await readdir ( fixturesDir ) ;
12
12
13
13
for ( const name of tests ) {
14
14
test ( name , async ( ) => {
15
- const path = join ( '__fixtures__' , name ) ;
16
- const input = await fs . readFile ( join ( path , 'input.md' ) ) ;
17
- const expected = join ( path , 'expected.jsx' ) ;
18
- const options = JSON . parse ( await fs . readFile ( join ( path , 'options.json' ) , 'utf8' ) ) ;
15
+ const url = new URL ( ` ${ name } /` , fixturesDir ) ;
16
+ const input = await readFile ( new URL ( 'input.md' , url ) ) ;
17
+ const expected = new URL ( 'expected.jsx' , url ) ;
18
+ const options = JSON . parse ( await readFile ( new URL ( 'options.json' , url ) , 'utf8' ) ) ;
19
19
const { value } = await compile ( input , {
20
20
remarkPlugins : [
21
21
[ remarkFrontmatter , [ 'yaml' , 'toml' ] ] ,
@@ -24,9 +24,9 @@ for (const name of tests) {
24
24
jsx : true ,
25
25
} ) ;
26
26
if ( process . argv . includes ( '--write' ) ) {
27
- await fs . writeFile ( expected , value ) ;
27
+ await writeFile ( expected , value ) ;
28
28
}
29
- equal ( value , await fs . readFile ( expected , 'utf8' ) ) ;
29
+ equal ( value , await readFile ( expected , 'utf8' ) ) ;
30
30
} ) ;
31
31
}
32
32
0 commit comments