Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'test/lib/commands/install.js')
-rw-r--r--test/lib/commands/install.js461
1 files changed, 225 insertions, 236 deletions
diff --git a/test/lib/commands/install.js b/test/lib/commands/install.js
index 9b2d52f6e..632ca22be 100644
--- a/test/lib/commands/install.js
+++ b/test/lib/commands/install.js
@@ -1,273 +1,262 @@
const t = require('tap')
-const path = require('path')
const { load: _loadMockNpm } = require('../../fixtures/mock-npm')
// Make less churn in the test to pass in mocks only signature
const loadMockNpm = (t, mocks) => _loadMockNpm(t, { mocks })
-t.test('with args, dev=true', async t => {
- const SCRIPTS = []
- let ARB_ARGS = null
- let REIFY_CALLED = false
- let ARB_OBJ = null
+t.test('exec commands', async t => {
+ await t.test('with args, dev=true', async t => {
+ const SCRIPTS = []
+ let ARB_ARGS = null
+ let REIFY_CALLED = false
+ let ARB_OBJ = null
- const { npm } = await loadMockNpm(t, {
- '@npmcli/run-script': ({ event }) => {
- SCRIPTS.push(event)
- },
- '@npmcli/arborist': function (args) {
- ARB_ARGS = args
- ARB_OBJ = this
- this.reify = () => {
- REIFY_CALLED = true
- }
- },
- '../../lib/utils/reify-finish.js': (npm, arb) => {
- if (arb !== ARB_OBJ) {
- throw new Error('got wrong object passed to reify-finish')
- }
- },
- })
-
- // This is here because CI calls tests with `--ignore-scripts`, which config
- // picks up from argv
- npm.config.set('ignore-scripts', false)
- npm.config.set('audit-level', 'low')
- npm.config.set('dev', true)
- // tap sets this to
- // D:\\a\\cli\\cli\\test\\lib\\commands/tap-testdir-install-should-install-globally-using-Arborist
- // which gets normalized elsewhere so comparative tests fail
- npm.prefix = path.resolve(t.testdir({}))
-
- await npm.exec('install', ['fizzbuzz'])
+ const { npm } = await loadMockNpm(t, {
+ '@npmcli/run-script': ({ event }) => {
+ SCRIPTS.push(event)
+ },
+ '@npmcli/arborist': function (args) {
+ ARB_ARGS = args
+ ARB_OBJ = this
+ this.reify = () => {
+ REIFY_CALLED = true
+ }
+ },
+ '../../lib/utils/reify-finish.js': (npm, arb) => {
+ if (arb !== ARB_OBJ) {
+ throw new Error('got wrong object passed to reify-finish')
+ }
+ },
+ })
- t.match(
- ARB_ARGS,
- { global: false, path: npm.prefix, auditLevel: null },
- 'Arborist gets correct args and ignores auditLevel'
- )
- t.equal(REIFY_CALLED, true, 'called reify')
- t.strictSame(SCRIPTS, [], 'no scripts when adding dep')
-})
+ // This is here because CI calls tests with `--ignore-scripts`, which config
+ // picks up from argv
+ npm.config.set('ignore-scripts', false)
+ npm.config.set('audit-level', 'low')
+ npm.config.set('dev', true)
-t.test('without args', async t => {
- const SCRIPTS = []
- let ARB_ARGS = null
- let REIFY_CALLED = false
- let ARB_OBJ = null
+ await npm.exec('install', ['fizzbuzz'])
- const { npm } = await loadMockNpm(t, {
- '@npmcli/run-script': ({ event }) => {
- SCRIPTS.push(event)
- },
- '@npmcli/arborist': function (args) {
- ARB_ARGS = args
- ARB_OBJ = this
- this.reify = () => {
- REIFY_CALLED = true
- }
- },
- '../../lib/utils/reify-finish.js': (npm, arb) => {
- if (arb !== ARB_OBJ) {
- throw new Error('got wrong object passed to reify-finish')
- }
- },
+ t.match(
+ ARB_ARGS,
+ { global: false, path: npm.prefix, auditLevel: null },
+ 'Arborist gets correct args and ignores auditLevel'
+ )
+ t.equal(REIFY_CALLED, true, 'called reify')
+ t.strictSame(SCRIPTS, [], 'no scripts when adding dep')
})
- npm.prefix = path.resolve(t.testdir({}))
- npm.config.set('ignore-scripts', false)
- await npm.exec('install', [])
- t.match(ARB_ARGS, { global: false, path: npm.prefix })
- t.equal(REIFY_CALLED, true, 'called reify')
- t.strictSame(SCRIPTS, [
- 'preinstall',
- 'install',
- 'postinstall',
- 'prepublish',
- 'preprepare',
- 'prepare',
- 'postprepare',
- ], 'exec scripts when doing local build')
-})
+ await t.test('without args', async t => {
+ const SCRIPTS = []
+ let ARB_ARGS = null
+ let REIFY_CALLED = false
+ let ARB_OBJ = null
-t.test('should ignore scripts with --ignore-scripts', async t => {
- const SCRIPTS = []
- let REIFY_CALLED = false
- const { npm } = await loadMockNpm(t, {
- '../../lib/utils/reify-finish.js': async () => {},
- '@npmcli/run-script': ({ event }) => {
- SCRIPTS.push(event)
- },
- '@npmcli/arborist': function () {
- this.reify = () => {
- REIFY_CALLED = true
- }
- },
- })
- npm.config.set('ignore-scripts', true)
- npm.prefix = path.resolve(t.testdir({}))
- await npm.exec('install', [])
- t.equal(REIFY_CALLED, true, 'called reify')
- t.strictSame(SCRIPTS, [], 'no scripts when adding dep')
-})
+ const { npm } = await loadMockNpm(t, {
+ '@npmcli/run-script': ({ event }) => {
+ SCRIPTS.push(event)
+ },
+ '@npmcli/arborist': function (args) {
+ ARB_ARGS = args
+ ARB_OBJ = this
+ this.reify = () => {
+ REIFY_CALLED = true
+ }
+ },
+ '../../lib/utils/reify-finish.js': (npm, arb) => {
+ if (arb !== ARB_OBJ) {
+ throw new Error('got wrong object passed to reify-finish')
+ }
+ },
+ })
-t.test('should install globally using Arborist', async t => {
- const SCRIPTS = []
- let ARB_ARGS = null
- let REIFY_CALLED
- const { npm } = await loadMockNpm(t, {
- '@npmcli/run-script': ({ event }) => {
- SCRIPTS.push(event)
- },
- '../../lib/utils/reify-finish.js': async () => {},
- '@npmcli/arborist': function (args) {
- ARB_ARGS = args
- this.reify = () => {
- REIFY_CALLED = true
- }
- },
+ npm.config.set('ignore-scripts', false)
+ await npm.exec('install', [])
+ t.match(ARB_ARGS, { global: false, path: npm.prefix })
+ t.equal(REIFY_CALLED, true, 'called reify')
+ t.strictSame(SCRIPTS, [
+ 'preinstall',
+ 'install',
+ 'postinstall',
+ 'prepublish',
+ 'preprepare',
+ 'prepare',
+ 'postprepare',
+ ], 'exec scripts when doing local build')
})
- npm.config.set('global', true)
- npm.globalPrefix = path.resolve(t.testdir({}))
- await npm.exec('install', [])
- t.match(
- ARB_ARGS,
- { global: true, path: npm.globalPrefix }
- )
- t.equal(REIFY_CALLED, true, 'called reify')
- t.strictSame(SCRIPTS, [], 'no scripts when installing globally')
-})
-t.test('should not install invalid global package name', async t => {
- const { npm } = await loadMockNpm(t, {
- '@npmcli/run-script': () => {},
- '../../lib/utils/reify-finish.js': async () => {},
- '@npmcli/arborist': function (args) {
- throw new Error('should not reify')
- },
+ await t.test('should ignore scripts with --ignore-scripts', async t => {
+ const SCRIPTS = []
+ let REIFY_CALLED = false
+ const { npm } = await loadMockNpm(t, {
+ '../../lib/utils/reify-finish.js': async () => {},
+ '@npmcli/run-script': ({ event }) => {
+ SCRIPTS.push(event)
+ },
+ '@npmcli/arborist': function () {
+ this.reify = () => {
+ REIFY_CALLED = true
+ }
+ },
+ })
+ npm.config.set('ignore-scripts', true)
+ await npm.exec('install', [])
+ t.equal(REIFY_CALLED, true, 'called reify')
+ t.strictSame(SCRIPTS, [], 'no scripts when adding dep')
})
- npm.config.set('global', true)
- npm.globalPrefix = path.resolve(t.testdir({}))
- await t.rejects(
- npm.exec('install', ['']),
- /Usage:/,
- 'should not install invalid package name'
- )
-})
-t.test('npm i -g npm engines check success', async t => {
- const { npm } = await loadMockNpm(t, {
- '../../lib/utils/reify-finish.js': async () => {},
- '@npmcli/arborist': function () {
- this.reify = () => {}
- },
- pacote: {
- manifest: () => {
- return {
- version: '100.100.100',
- engines: {
- node: '>1',
- },
+ await t.test('should install globally using Arborist', async t => {
+ const SCRIPTS = []
+ let ARB_ARGS = null
+ let REIFY_CALLED
+ const { npm } = await loadMockNpm(t, {
+ '@npmcli/run-script': ({ event }) => {
+ SCRIPTS.push(event)
+ },
+ '../../lib/utils/reify-finish.js': async () => {},
+ '@npmcli/arborist': function (args) {
+ ARB_ARGS = args
+ this.reify = () => {
+ REIFY_CALLED = true
}
},
- },
+ })
+ npm.config.set('global', true)
+ await npm.exec('install', [])
+ t.match(
+ ARB_ARGS,
+ { global: true, path: npm.globalPrefix }
+ )
+ t.equal(REIFY_CALLED, true, 'called reify')
+ t.strictSame(SCRIPTS, [], 'no scripts when installing globally')
})
- npm.globalDir = t.testdir({})
- npm.config.set('global', true)
- await npm.exec('install', ['npm'])
- t.ok('No exceptions happen')
-})
-t.test('npm i -g npm engines check failure', async t => {
- const { npm } = await loadMockNpm(t, {
- pacote: {
- manifest: () => {
- return {
- _id: 'npm@1.2.3',
- version: '100.100.100',
- engines: {
- node: '>1000',
- },
- }
+ await t.test('should not install invalid global package name', async t => {
+ const { npm } = await loadMockNpm(t, {
+ '@npmcli/run-script': () => {},
+ '../../lib/utils/reify-finish.js': async () => {},
+ '@npmcli/arborist': function (args) {
+ throw new Error('should not reify')
},
- },
+ })
+ npm.config.set('global', true)
+ await t.rejects(
+ npm.exec('install', ['']),
+ /Usage:/,
+ 'should not install invalid package name'
+ )
})
- npm.globalDir = t.testdir({})
- npm.config.set('global', true)
- await t.rejects(
- npm.exec('install', ['npm']),
- {
- message: 'Unsupported engine',
- pkgid: 'npm@1.2.3',
- current: {
- node: process.version,
- npm: '100.100.100',
+
+ await t.test('npm i -g npm engines check success', async t => {
+ const { npm } = await loadMockNpm(t, {
+ '../../lib/utils/reify-finish.js': async () => {},
+ '@npmcli/arborist': function () {
+ this.reify = () => {}
},
- required: {
- node: '>1000',
+ pacote: {
+ manifest: () => {
+ return {
+ version: '100.100.100',
+ engines: {
+ node: '>1',
+ },
+ }
+ },
},
- code: 'EBADENGINE',
- }
- )
-})
+ })
+ npm.config.set('global', true)
+ await npm.exec('install', ['npm'])
+ t.ok('No exceptions happen')
+ })
-t.test('npm i -g npm engines check failure forced override', async t => {
- const { npm } = await loadMockNpm(t, {
- '../../lib/utils/reify-finish.js': async () => {},
- '@npmcli/arborist': function () {
- this.reify = () => {}
- },
- pacote: {
- manifest: () => {
- return {
- _id: 'npm@1.2.3',
- version: '100.100.100',
- engines: {
- node: '>1000',
- },
- }
+ await t.test('npm i -g npm engines check failure', async t => {
+ const { npm } = await loadMockNpm(t, {
+ pacote: {
+ manifest: () => {
+ return {
+ _id: 'npm@1.2.3',
+ version: '100.100.100',
+ engines: {
+ node: '>1000',
+ },
+ }
+ },
},
- },
+ })
+ npm.config.set('global', true)
+ await t.rejects(
+ npm.exec('install', ['npm']),
+ {
+ message: 'Unsupported engine',
+ pkgid: 'npm@1.2.3',
+ current: {
+ node: process.version,
+ npm: '100.100.100',
+ },
+ required: {
+ node: '>1000',
+ },
+ code: 'EBADENGINE',
+ }
+ )
})
- npm.globalDir = t.testdir({})
- npm.config.set('global', true)
- npm.config.set('force', true)
- await npm.exec('install', ['npm'])
- t.ok('Does not throw')
-})
-t.test('npm i -g npm@version engines check failure', async t => {
- const { npm } = await loadMockNpm(t, {
- pacote: {
- manifest: () => {
- return {
- _id: 'npm@1.2.3',
- version: '100.100.100',
- engines: {
- node: '>1000',
- },
- }
+ await t.test('npm i -g npm engines check failure forced override', async t => {
+ const { npm } = await loadMockNpm(t, {
+ '../../lib/utils/reify-finish.js': async () => {},
+ '@npmcli/arborist': function () {
+ this.reify = () => {}
},
- },
- })
- npm.globalDir = t.testdir({})
- npm.config.set('global', true)
- await t.rejects(
- npm.exec('install', ['npm@100']),
- {
- message: 'Unsupported engine',
- pkgid: 'npm@1.2.3',
- current: {
- node: process.version,
- npm: '100.100.100',
+ pacote: {
+ manifest: () => {
+ return {
+ _id: 'npm@1.2.3',
+ version: '100.100.100',
+ engines: {
+ node: '>1000',
+ },
+ }
+ },
},
- required: {
- node: '>1000',
+ })
+ npm.config.set('global', true)
+ npm.config.set('force', true)
+ await npm.exec('install', ['npm'])
+ t.ok('Does not throw')
+ })
+
+ await t.test('npm i -g npm@version engines check failure', async t => {
+ const { npm } = await loadMockNpm(t, {
+ pacote: {
+ manifest: () => {
+ return {
+ _id: 'npm@1.2.3',
+ version: '100.100.100',
+ engines: {
+ node: '>1000',
+ },
+ }
+ },
},
- code: 'EBADENGINE',
- }
- )
+ })
+ npm.config.set('global', true)
+ await t.rejects(
+ npm.exec('install', ['npm@100']),
+ {
+ message: 'Unsupported engine',
+ pkgid: 'npm@1.2.3',
+ current: {
+ node: process.version,
+ npm: '100.100.100',
+ },
+ required: {
+ node: '>1000',
+ },
+ code: 'EBADENGINE',
+ }
+ )
+ })
})
t.test('completion', async t => {