diff options
author | Michael Garvin <gar+gh@danger.computer> | 2021-01-07 20:14:09 +0300 |
---|---|---|
committer | isaacs <i@izs.me> | 2021-01-07 23:44:29 +0300 |
commit | 907b34b2ecc34ac376d989f824f7492064e43ef4 (patch) | |
tree | 7bac484eca5f34dc8fd2a2f454eb16179e90069c /test | |
parent | 99156df8099f55bc69dfa99d7ddcf8d1d569016e (diff) |
fix(ci): pay attention to --ignore-scripts
Added a test for install too for this specific condition
PR-URL: https://github.com/npm/cli/pull/2455
Credit: @wraithgar
Close: #2455
Reviewed-by: @isaacs
Diffstat (limited to 'test')
-rw-r--r-- | test/lib/ci.js | 35 | ||||
-rw-r--r-- | test/lib/install.js | 36 |
2 files changed, 70 insertions, 1 deletions
diff --git a/test/lib/ci.js b/test/lib/ci.js index c32fb8327..c8d8e169e 100644 --- a/test/lib/ci.js +++ b/test/lib/ci.js @@ -6,6 +6,41 @@ const { test } = require('tap') const requireInject = require('require-inject') +test('should ignore scripts with --ignore-scripts', (t) => { + const SCRIPTS = [] + let REIFY_CALLED = false + const ci = requireInject('../../lib/ci.js', { + '../../lib/utils/reify-finish.js': async () => {}, + '../../lib/npm.js': { + globalDir: 'path/to/node_modules/', + prefix: 'foo', + flatOptions: { + global: false, + ignoreScripts: true + }, + config: { + get: () => false, + }, + }, + '@npmcli/run-script': ({ event }) => { + SCRIPTS.push(event) + }, + '@npmcli/arborist': function () { + this.loadVirtual = async () => {} + this.reify = () => { + REIFY_CALLED = true + } + }, + }) + ci([], er => { + if (er) + throw er + t.equal(REIFY_CALLED, true, 'called reify') + t.strictSame(SCRIPTS, [], 'no scripts when running ci') + t.end() + }) +}) + test('should use Arborist and run-script', (t) => { const scripts = [ 'preinstall', diff --git a/test/lib/install.js b/test/lib/install.js index 7e243e7ff..d94c9b5f1 100644 --- a/test/lib/install.js +++ b/test/lib/install.js @@ -72,6 +72,40 @@ test('should install using Arborist', (t) => { t.end() }) +test('should ignore scripts with --ignore-scripts', (t) => { + const SCRIPTS = [] + let REIFY_CALLED = false + const install = requireInject('../../lib/install.js', { + '../../lib/utils/reify-finish.js': async () => {}, + '../../lib/npm.js': { + globalDir: 'path/to/node_modules/', + prefix: 'foo', + flatOptions: { + global: false, + ignoreScripts: true + }, + config: { + get: () => false, + }, + }, + '@npmcli/run-script': ({ event }) => { + SCRIPTS.push(event) + }, + '@npmcli/arborist': function () { + this.reify = () => { + REIFY_CALLED = true + } + }, + }) + install([], er => { + if (er) + throw er + t.equal(REIFY_CALLED, true, 'called reify') + t.strictSame(SCRIPTS, [], 'no scripts when adding dep') + t.end() + }) +}) + test('should install globally using Arborist', (t) => { const install = requireInject('../../lib/install.js', { '../../lib/utils/reify-finish.js': async () => {}, @@ -79,7 +113,7 @@ test('should install globally using Arborist', (t) => { globalDir: 'path/to/node_modules/', prefix: 'foo', flatOptions: { - global: 'true', + global: true, }, config: { get: () => false, |