diff options
author | isaacs <i@izs.me> | 2021-02-09 02:16:01 +0300 |
---|---|---|
committer | Gar <gar+gh@danger.computer> | 2021-02-11 21:42:15 +0300 |
commit | ef687f545b177d0496ce74faacf1bf738978355a (patch) | |
tree | 3402da4a69fc53c395d51e1121393b2101560c75 /test | |
parent | e815cd4f79dafcc8fa1b8b2bec4c9b4acac89175 (diff) |
fix(env): Do not clobber defined 'env' script
If an env script is already defined, run that
instead of the default.
PR-URL: https://github.com/npm/cli/pull/2655
Credit: @isaacs
Close: #2655
Reviewed-by: @ljharb
Diffstat (limited to 'test')
-rw-r--r-- | test/lib/run-script.js | 67 |
1 files changed, 65 insertions, 2 deletions
diff --git a/test/lib/run-script.js b/test/lib/run-script.js index bad8a63c0..070f766b4 100644 --- a/test/lib/run-script.js +++ b/test/lib/run-script.js @@ -126,12 +126,14 @@ t.test('default env, start, and restart scripts', async t => { scriptShell: undefined, stdio: 'inherit', stdioString: true, - pkg: { name: 'x', + pkg: { + name: 'x', version: '1.2.3', _id: 'x@1.2.3', scripts: { env: 'env', - } }, + }, + }, event: 'env', }, ]) @@ -185,6 +187,67 @@ t.test('default env, start, and restart scripts', async t => { RUN_SCRIPTS.length = 0 }) +t.test('non-default env script', async t => { + npm.localPrefix = t.testdir({ + 'package.json': JSON.stringify({ + name: 'x', + version: '1.2.3', + scripts: { + env: 'hello', + }, + }), + }) + + await runScript(['env'], er => { + if (er) + throw er + + t.match(RUN_SCRIPTS, [ + { + path: npm.localPrefix, + args: [], + scriptShell: undefined, + stdio: 'inherit', + stdioString: true, + pkg: { + name: 'x', + version: '1.2.3', + _id: 'x@1.2.3', + scripts: { + env: 'hello', + }, + }, + event: 'env', + }, + ]) + }) + RUN_SCRIPTS.length = 0 + + await runScriptWin(['env'], er => { + if (er) + throw er + + t.match(RUN_SCRIPTS, [ + { + path: npm.localPrefix, + args: [], + scriptShell: undefined, + stdio: 'inherit', + stdioString: true, + pkg: { name: 'x', + version: '1.2.3', + _id: 'x@1.2.3', + scripts: { + env: 'hello', + }, + }, + event: 'env', + }, + ]) + }) + RUN_SCRIPTS.length = 0 +}) + t.test('try to run missing script', t => { npm.localPrefix = t.testdir({ 'package.json': JSON.stringify({ |