@@ -3,7 +3,7 @@ import * as expect from 'expect';
3
3
import { join , resolve , sep as pathSep } from 'path' ;
4
4
import { tmpdir } from 'os' ;
5
5
import semver = require( 'semver' ) ;
6
- import { nodeSupportsEsmHooks , ts } from './helpers' ;
6
+ import { BIN_PATH_JS , nodeSupportsEsmHooks , ts } from './helpers' ;
7
7
import { lstatSync , mkdtempSync } from 'fs' ;
8
8
import { npath } from '@yarnpkg/fslib' ;
9
9
import type _createRequire from 'create-require' ;
@@ -1071,6 +1071,44 @@ test('Falls back to transpileOnly when ts compiler returns emitSkipped', async (
1071
1071
expect ( stdout ) . toBe ( 'foo\n' ) ;
1072
1072
} ) ;
1073
1073
1074
+ test . suite ( 'node environment' , ( test ) => {
1075
+ test . suite ( 'Sets argv and execArgv correctly in forked processes' , ( test ) => {
1076
+ forkTest ( `node --no-warnings ${ BIN_PATH_JS } ` , BIN_PATH_JS , '--no-warnings' ) ;
1077
+ forkTest (
1078
+ `${ BIN_PATH } ` ,
1079
+ process . platform === 'win32' ? BIN_PATH_JS : BIN_PATH
1080
+ ) ;
1081
+
1082
+ function forkTest (
1083
+ command : string ,
1084
+ expectParentArgv0 : string ,
1085
+ nodeFlag ?: string
1086
+ ) {
1087
+ test ( command , async ( t ) => {
1088
+ const { err, stderr, stdout } = await exec (
1089
+ `${ command } --skipIgnore ./recursive-fork/index.ts argv2`
1090
+ ) ;
1091
+ expect ( err ) . toBeNull ( ) ;
1092
+ expect ( stderr ) . toBe ( '' ) ;
1093
+ const generations = stdout . split ( '\n' ) ;
1094
+ const expectation = {
1095
+ execArgv : [ nodeFlag , BIN_PATH_JS , '--skipIgnore' ] . filter ( ( v ) => v ) ,
1096
+ argv : [
1097
+ // Note: argv[0] is *always* BIN_PATH_JS in child & grandchild
1098
+ expectParentArgv0 ,
1099
+ resolve ( TEST_DIR , 'recursive-fork/index.ts' ) ,
1100
+ 'argv2' ,
1101
+ ] ,
1102
+ } ;
1103
+ expect ( JSON . parse ( generations [ 0 ] ) ) . toMatchObject ( expectation ) ;
1104
+ expectation . argv [ 0 ] = BIN_PATH_JS ;
1105
+ expect ( JSON . parse ( generations [ 1 ] ) ) . toMatchObject ( expectation ) ;
1106
+ expect ( JSON . parse ( generations [ 2 ] ) ) . toMatchObject ( expectation ) ;
1107
+ } ) ;
1108
+ }
1109
+ } ) ;
1110
+ } ) ;
1111
+
1074
1112
test ( 'Detect when typescript adds new ModuleKind values; flag as a failure so we can update our code flagged [MUST_UPDATE_FOR_NEW_MODULEKIND]' , async ( ) => {
1075
1113
// We have marked a few places in our code with MUST_UPDATE_FOR_NEW_MODULEKIND to make it easier to update them when TS adds new ModuleKinds
1076
1114
const foundKeys : string [ ] = [ ] ;
0 commit comments