1
- const path = require ( 'path' ) ;
2
- const fs = require ( 'fs' ) ;
3
- const assert = require ( 'assert' ) . strict ;
4
- const pattern = require ( './object.js' ) . problemMatcher [ 0 ] . pattern [ 0 ] ;
1
+ import path from 'node:path' ;
2
+ import fs from 'node:fs' ;
3
+ import assert from 'node:assert' ;
4
+ import { fileURLToPath } from 'node:url' ;
5
+ import object from './object.mjs' ;
6
+
7
+ const pattern = object . problemMatcher [ 0 ] . pattern [ 0 ] ;
5
8
const regexp = new RegExp ( pattern . regexp ) ;
9
+ const dirname = path . dirname ( fileURLToPath ( import . meta. url ) ) ;
6
10
7
11
{
8
- const want = require ( './ test/want.json') [ 0 ] ;
12
+ const want = JSON . parse ( fs . readFileSync ( path . join ( dirname , ' test/want.json') , 'utf8' ) ) [ 0 ] ;
9
13
10
14
for ( const file of [ 'escape.txt' , 'no_escape.txt' ] ) {
11
15
console . log ( `Testing test/${ file } ` ) ;
12
- const escaped = path . join ( __dirname , 'test' , file ) ;
16
+ const escaped = path . join ( dirname , 'test' , file ) ;
13
17
const lines = fs . readFileSync ( escaped , 'utf8' ) . split ( '\n' ) ;
14
18
const m = lines [ 0 ] . match ( regexp ) ;
15
19
assert . ok ( m ) ; // not null
@@ -23,7 +27,7 @@ const regexp = new RegExp(pattern.regexp);
23
27
}
24
28
25
29
for ( const parent of [ 'examples' , 'err' ] ) {
26
- const dir = path . join ( __dirname , '..' , '..' , 'testdata' , parent ) ;
30
+ const dir = path . join ( dirname , '..' , '..' , 'testdata' , parent ) ;
27
31
for ( const name of fs . readdirSync ( dir ) ) {
28
32
if ( ! name . endsWith ( '.out' ) ) {
29
33
continue ;
0 commit comments