11import { access , readFile , writeFile } from "fs/promises" ;
22import { execSync , type SpawnSyncReturns } from "child_process" ;
33import assert from "node:assert" ;
4+ import path from "node:path" ;
45import { after , describe , test } from "node:test" ;
6+ import { fileURLToPath } from "node:url" ;
57
6- const attw = `node ${ new URL ( "../../dist/index.js" , import . meta. url ) . pathname } ` ;
8+ const directoryPath = path . dirname ( fileURLToPath ( import . meta. url ) ) ;
9+ function resolveFileRelativePath ( relPath : string ) {
10+ return path . resolve ( directoryPath , relPath ) ;
11+ }
12+
13+ const attw = `node ${ resolveFileRelativePath ( "../../dist/index.js" ) } ` ;
714const updateSnapshots = process . env . UPDATE_SNAPSHOTS || process . env . U ;
815const testFilter = ( process . env . TEST_FILTER || process . env . T ) ?. toLowerCase ( ) ;
916
@@ -34,11 +41,11 @@ const tests = [
3441
3542 [
364337- `--definitely-typed ${ new URL ( "../../../core/test/fixtures/@[email protected] " , import . meta . url ) . pathname } ` , 44+ `--definitely-typed ${ resolveFileRelativePath ( "../../../core/test/fixtures/@[email protected] " ) } ` , 3845 ] ,
3946 [
404741- `--definitely-typed ${ new URL ( "../../../core/test/fixtures/@[email protected] " , import . meta . url ) . pathname } ` , 48+ `--definitely-typed ${ resolveFileRelativePath ( "../../../core/test/fixtures/@[email protected] " ) } ` , 4249 ] ,
4350
4451 [ "[email protected] " , "--entrypoints-legacy --ignore-rules=cjs-only-exports-default" ] , @@ -69,7 +76,7 @@ describe("snapshots", async () => {
6976 }
7077
7178 test ( fixture , async ( ) => {
72- const tarballPath = new URL ( `../../../core/test/fixtures/${ tarball } ` , import . meta . url ) . pathname ;
79+ const tarballPath = resolveFileRelativePath ( `../../../core/test/fixtures/${ tarball } ` ) ;
7380 let stdout ;
7481 let stderr = "" ;
7582 let exitCode = 0 ;
@@ -85,7 +92,7 @@ describe("snapshots", async () => {
8592 }
8693 const snapshotURL = new URL ( `../snapshots/${ fixture } .md` , import . meta. url ) ;
8794 // prettier-ignore
88- const expectedSnapshot = [
95+ const actualSnapshot = [
8996 `# ${ fixture } ` ,
9097 "" ,
9198 "```" ,
@@ -99,19 +106,16 @@ describe("snapshots", async () => {
99106 ] . join ( "\n" ) ;
100107
101108 if (
102- await access ( snapshotURL )
109+ ! updateSnapshots &&
110+ ( await access ( snapshotURL )
103111 . then ( ( ) => true )
104- . catch ( ( ) => false )
112+ . catch ( ( ) => false ) )
105113 ) {
106114 const snapshot = await readFile ( snapshotURL , "utf8" ) ;
107- if ( updateSnapshots ) {
108- await writeFile ( snapshotURL , expectedSnapshot ) ;
109- snapshotsWritten . push ( snapshotURL ) ;
110- } else {
111- assert . strictEqual ( snapshot , expectedSnapshot ) ;
112- }
115+ const expectedSnapshot = snapshot . replace ( / \r \n / g, "\n" ) ;
116+ assert . strictEqual ( actualSnapshot , expectedSnapshot ) ;
113117 } else {
114- await writeFile ( snapshotURL , expectedSnapshot ) ;
118+ await writeFile ( snapshotURL , actualSnapshot ) ;
115119 snapshotsWritten . push ( snapshotURL ) ;
116120 }
117121 } ) ;
0 commit comments