From 2525b376e4b937f12d9f1e30045db0a276b12b4f Mon Sep 17 00:00:00 2001 From: Hung-I Wang Date: Fri, 20 Nov 2020 19:28:46 +0800 Subject: [PATCH] Avoid spawning a shell when running node in test (#155) `execSync` by default spawns a shell to exec the specified command. And, without specifying an absolute path to the node binary, it will be searched in `PATH` where yarn prepends a temporary directory containing a shell script called **node** that wraps the original node binary with exec, resulting in implicitly chaining a shell again. On some Linux distros, the default non-interactive shell, such as the Dash shell of Debian, silently discards dashes (`-`) in names of environment variables. But GitHub Actions allows dashes in names of input variables which are then converted to environment variables in the form of `INPUT_`. So the commit fix the error-prone test code by using execFileSync, which by default exec directly without spawning a shell, to run node with its absolute path. --- __tests__/main.test.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index efcf95e..62ac756 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -19,9 +19,10 @@ test('wait 500 ms', async () => { // shows how the runner will run a javascript action with env / stdout protocol test('test runs', () => { process.env['INPUT_MILLISECONDS'] = '500' + const np = process.execPath const ip = path.join(__dirname, '..', 'lib', 'main.js') - const options: cp.ExecSyncOptions = { + const options: cp.ExecFileSyncOptions = { env: process.env } - console.log(cp.execSync(`node ${ip}`, options).toString()) + console.log(cp.execFileSync(np, [ip], options).toString()) })