From 30a4248b48d8c2f7cceaf8ff65107f4e8fb637d3 Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Sat, 4 May 2024 17:27:05 -0400 Subject: [PATCH] test: add env variable test for --run PR-URL: https://github.com/nodejs/node/pull/52811 Reviewed-By: Daniel Lemire Reviewed-By: Antoine du Hamel Reviewed-By: Richard Lau Reviewed-By: Geoffrey Booth Reviewed-By: James M Snell --- test/fixtures/run-script/node_modules/.bin/path-env | 2 ++ .../run-script/node_modules/.bin/path-env.bat | 2 ++ test/fixtures/run-script/package.json | 4 +++- test/message/node_run_non_existent.out | 2 ++ test/parallel/test-node-run.js | 11 +++++++++++ 5 files changed, 20 insertions(+), 1 deletion(-) create mode 100755 test/fixtures/run-script/node_modules/.bin/path-env create mode 100644 test/fixtures/run-script/node_modules/.bin/path-env.bat diff --git a/test/fixtures/run-script/node_modules/.bin/path-env b/test/fixtures/run-script/node_modules/.bin/path-env new file mode 100755 index 00000000000000..88738a86701bd7 --- /dev/null +++ b/test/fixtures/run-script/node_modules/.bin/path-env @@ -0,0 +1,2 @@ +#!/bin/sh +echo "$PATH" diff --git a/test/fixtures/run-script/node_modules/.bin/path-env.bat b/test/fixtures/run-script/node_modules/.bin/path-env.bat new file mode 100644 index 00000000000000..11e37c63dec9ef --- /dev/null +++ b/test/fixtures/run-script/node_modules/.bin/path-env.bat @@ -0,0 +1,2 @@ +@shift +echo %PATH% diff --git a/test/fixtures/run-script/package.json b/test/fixtures/run-script/package.json index 79017b44450f96..822b753e3db61e 100644 --- a/test/fixtures/run-script/package.json +++ b/test/fixtures/run-script/package.json @@ -6,6 +6,8 @@ "positional-args": "positional-args", "positional-args-windows": "positional-args.bat", "custom-env": "custom-env", - "custom-env-windows": "custom-env.bat" + "custom-env-windows": "custom-env.bat", + "path-env": "path-env", + "path-env-windows": "path-env.bat" } } diff --git a/test/message/node_run_non_existent.out b/test/message/node_run_non_existent.out index 8d98465fa80606..a248a010a9b365 100644 --- a/test/message/node_run_non_existent.out +++ b/test/message/node_run_non_existent.out @@ -8,3 +8,5 @@ Available scripts are: positional-args-windows: positional-args.bat custom-env: custom-env custom-env-windows: custom-env.bat + path-env: path-env + path-env-windows: path-env.bat diff --git a/test/parallel/test-node-run.js b/test/parallel/test-node-run.js index ce0c21215fda58..69a7c9d9a46db1 100644 --- a/test/parallel/test-node-run.js +++ b/test/parallel/test-node-run.js @@ -64,4 +64,15 @@ describe('node run [command]', () => { assert.strictEqual(child.stderr, ''); assert.strictEqual(child.code, 0); }); + + it('should set PATH environment variable to node_modules/.bin', async () => { + const child = await common.spawnPromisified( + process.execPath, + [ '--no-warnings', '--run', `path-env${envSuffix}`], + { cwd: fixtures.path('run-script') }, + ); + assert.ok(child.stdout.includes(fixtures.path('run-script/node_modules/.bin'))); + assert.strictEqual(child.stderr, ''); + assert.strictEqual(child.code, 0); + }); });