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 file = path . join ( dirname , 'test' , 'want.json' ) ;
13
+ const want = JSON . parse ( fs . readFileSync ( file , 'utf8' ) ) [ 0 ] ;
9
14
10
15
for ( const file of [ 'escape.txt' , 'no_escape.txt' ] ) {
11
16
console . log ( `Testing test/${ file } ` ) ;
12
- const escaped = path . join ( __dirname , 'test' , file ) ;
17
+ const escaped = path . join ( dirname , 'test' , file ) ;
13
18
const lines = fs . readFileSync ( escaped , 'utf8' ) . split ( '\n' ) ;
14
19
const m = lines [ 0 ] . match ( regexp ) ;
15
20
assert . ok ( m ) ; // not null
@@ -23,7 +28,7 @@ const regexp = new RegExp(pattern.regexp);
23
28
}
24
29
25
30
for ( const parent of [ 'examples' , 'err' ] ) {
26
- const dir = path . join ( __dirname , '..' , '..' , 'testdata' , parent ) ;
31
+ const dir = path . join ( dirname , '..' , '..' , 'testdata' , parent ) ;
27
32
for ( const name of fs . readdirSync ( dir ) ) {
28
33
if ( ! name . endsWith ( '.out' ) ) {
29
34
continue ;
0 commit comments