1
+ import { access , readFile , writeFile } from "fs/promises" ;
2
+ import { execSync , type SpawnSyncReturns } from "child_process" ;
1
3
import assert from "node:assert" ;
2
- import { spawnSync } from "node:child_process" ;
3
- import { access , readFile , writeFile } from "node:fs/promises" ;
4
4
import { after , describe , test } from "node:test" ;
5
5
6
- const attw = new URL ( "../src/ index.ts " , import . meta. url ) . pathname ;
6
+ const attw = `node ${ new URL ( "../../dist/ index.js " , import . meta. url ) . pathname } ` ;
7
7
const updateSnapshots = process . env . UPDATE_SNAPSHOTS || process . env . U ;
8
8
const testFilter = ( process . env . TEST_FILTER || process . env . T ) ?. toLowerCase ( ) ;
9
9
@@ -34,11 +34,11 @@ const tests = [
34
34
35
35
[
36
36
37
- `--definitely-typed ${ new URL ( "../../core/test/fixtures/@[email protected] " , import . meta. url ) . pathname } ` ,
37
+ `--definitely-typed ${ new URL ( "../../../ core/test/fixtures/@[email protected] " , import . meta. url ) . pathname } ` ,
38
38
] ,
39
39
[
40
40
41
- `--definitely-typed ${ new URL ( "../../core/test/fixtures/@[email protected] " , import . meta. url ) . pathname } ` ,
41
+ `--definitely-typed ${ new URL ( "../../../ core/test/fixtures/@[email protected] " , import . meta. url ) . pathname } ` ,
42
42
] ,
43
43
44
44
[ "[email protected] " , "--entrypoints-legacy --ignore-rules=cjs-only-exports-default" ] ,
@@ -68,22 +68,21 @@ describe("snapshots", async () => {
68
68
}
69
69
70
70
test ( fixture , async ( ) => {
71
- const tarballPath = new URL ( `../../core/test/fixtures/${ tarball } ` , import . meta. url ) . pathname ;
72
- const {
73
- stdout,
74
- stderr,
75
- status = 1 ,
76
- } = spawnSync (
77
- process . execPath ,
78
- [ ...process . execArgv , attw , tarballPath , ...( options ?? defaultOpts ) . split ( " " ) ] ,
79
- {
71
+ const tarballPath = new URL ( `../../../core/test/fixtures/${ tarball } ` , import . meta. url ) . pathname ;
72
+ let stdout ;
73
+ let stderr = "" ;
74
+ let exitCode = 0 ;
75
+ try {
76
+ stdout = execSync ( `${ attw } ${ tarballPath } ${ options ?? defaultOpts } ` , {
80
77
encoding : "utf8" ,
81
- stdio : "pipe" ,
82
- env : { ...process . env , FORCE_COLOR : "0" , NODE_OPTIONS : "--no-warnings" } ,
83
- } ,
84
- ) ;
85
-
86
- const snapshotURL = new URL ( `snapshots/${ fixture } .md` , import . meta. url ) ;
78
+ env : { ...process . env , FORCE_COLOR : "0" } ,
79
+ } ) ;
80
+ } catch ( error ) {
81
+ stdout = ( error as SpawnSyncReturns < string > ) . stdout ;
82
+ stderr = ( error as SpawnSyncReturns < string > ) . stderr ;
83
+ exitCode = ( error as SpawnSyncReturns < string > ) . status ?? 1 ;
84
+ }
85
+ const snapshotURL = new URL ( `../snapshots/${ fixture } .md` , import . meta. url ) ;
87
86
// prettier-ignore
88
87
const expectedSnapshot = [
89
88
`# ${ fixture } ` ,
@@ -95,7 +94,7 @@ describe("snapshots", async () => {
95
94
"" ,
96
95
"```" ,
97
96
"" ,
98
- `Exit code: ${ status } ` ,
97
+ `Exit code: ${ exitCode } ` ,
99
98
] . join ( "\n" ) ;
100
99
101
100
if (
0 commit comments