From 5b54fb03b80625d9824c40546bff1507841f00c6 Mon Sep 17 00:00:00 2001 From: Andrew Bradley Date: Wed, 23 Feb 2022 00:54:03 -0500 Subject: [PATCH] Fix for windows --- src/test/index.spec.ts | 52 +++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/src/test/index.spec.ts b/src/test/index.spec.ts index 16c9a666b..5487a7b64 100644 --- a/src/test/index.spec.ts +++ b/src/test/index.spec.ts @@ -1072,26 +1072,40 @@ test('Falls back to transpileOnly when ts compiler returns emitSkipped', async ( }); test.suite('node environment', (test) => { - test('Sets argv and execArgv correctly in forked processes', async (t) => { - const { err, stderr, stdout } = await exec( - `node --no-warnings ${BIN_PATH} --skipIgnore ./recursive-fork/index.ts argv2` + test.suite('Sets argv and execArgv correctly in forked processes', (test) => { + forkTest(`node --no-warnings ${BIN_PATH_JS}`, BIN_PATH_JS, '--no-warnings'); + forkTest( + `${BIN_PATH}`, + process.platform === 'win32' ? BIN_PATH_JS : BIN_PATH ); - expect(err).toBeNull(); - expect(stderr).toBe(''); - const generations = stdout.split('\n'); - const expectation = { - execArgv: ['--no-warnings', BIN_PATH_JS, '--skipIgnore'], - argv: [ - // Note: argv[0] is BIN_PATH in parent, BIN_PATH_JS in child & grandchild - BIN_PATH, - resolve(TEST_DIR, 'recursive-fork/index.ts'), - 'argv2', - ], - }; - expect(JSON.parse(generations[0])).toMatchObject(expectation); - expectation.argv[0] = BIN_PATH_JS; - expect(JSON.parse(generations[1])).toMatchObject(expectation); - expect(JSON.parse(generations[2])).toMatchObject(expectation); + + function forkTest( + command: string, + expectParentArgv0: string, + nodeFlag?: string + ) { + test(command, async (t) => { + const { err, stderr, stdout } = await exec( + `${command} --skipIgnore ./recursive-fork/index.ts argv2` + ); + expect(err).toBeNull(); + expect(stderr).toBe(''); + const generations = stdout.split('\n'); + const expectation = { + execArgv: [nodeFlag, BIN_PATH_JS, '--skipIgnore'].filter((v) => v), + argv: [ + // Note: argv[0] is *always* BIN_PATH_JS in child & grandchild + expectParentArgv0, + resolve(TEST_DIR, 'recursive-fork/index.ts'), + 'argv2', + ], + }; + expect(JSON.parse(generations[0])).toMatchObject(expectation); + expectation.argv[0] = BIN_PATH_JS; + expect(JSON.parse(generations[1])).toMatchObject(expectation); + expect(JSON.parse(generations[2])).toMatchObject(expectation); + }); + } }); });