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
path: root/test
diff options
context:
space:
mode:
authorLuke Karrys <luke@lukekarrys.com>2022-04-13 20:19:58 +0300
committerNathan Fritz <fritzy@github.com>2022-04-14 01:02:47 +0300
commitba8b2a753d63c8a8c7a44a48c2e13626b12025fe (patch)
tree971c44b3d8e7a23eb2546f8af4b7c603d282b549 /test
parentc22fb1e756d43b54fefd826f2c3f459d4f1204b5 (diff)
fix(ls): make `--omit` filter `npm ls`
This makes `npm ls` use the same logic as other commands (eg `outdated`) when parsing config items that filter the output based on package type. Previously `--development` and `--production` has special semantics when used with `npm ls` that were inconsistent with the rest of the CLI. To achieve the same behavior as these deprecated flags use: - in place of `--development` use `--omit peer --omit prod --omit optional` - in place of `--production` use `--omit dev --omit peer` Fixes #4739
Diffstat (limited to 'test')
-rw-r--r--test/lib/commands/ls.js224
-rw-r--r--test/lib/commands/outdated.js25
2 files changed, 32 insertions, 217 deletions
diff --git a/test/lib/commands/ls.js b/test/lib/commands/ls.js
index 9fd4db167..412d5ce65 100644
--- a/test/lib/commands/ls.js
+++ b/test/lib/commands/ls.js
@@ -99,14 +99,12 @@ const LS = t.mock('../../../lib/commands/ls.js', {
const config = {
all: true,
color: false,
- dev: false,
depth: Infinity,
global: false,
json: false,
link: false,
- only: null,
+ omit: [],
parseable: false,
- production: false,
'package-lock-only': false,
}
const flatOptions = {
@@ -456,7 +454,7 @@ t.test('ls', t => {
})
t.test('--dev', async t => {
- config.dev = true
+ flatOptions.omit = ['peer', 'prod', 'optional']
npm.prefix = t.testdir({
'package.json': JSON.stringify({
name: 'test-npm-ls',
@@ -479,34 +477,7 @@ t.test('ls', t => {
})
await ls.exec([])
t.matchSnapshot(redactCwd(result), 'should output tree containing dev deps')
- config.dev = false
- })
-
- t.test('--only=development', async t => {
- config.only = 'development'
- npm.prefix = t.testdir({
- 'package.json': JSON.stringify({
- name: 'test-npm-ls',
- version: '1.0.0',
- dependencies: {
- 'prod-dep': '^1.0.0',
- chai: '^1.0.0',
- },
- devDependencies: {
- 'dev-dep': '^1.0.0',
- },
- optionalDependencies: {
- 'optional-dep': '^1.0.0',
- },
- peerDependencies: {
- 'peer-dep': '^1.0.0',
- },
- }),
- ...diffDepTypesNmFixture,
- })
- await ls.exec([])
- t.matchSnapshot(redactCwd(result), 'should output tree containing only development deps')
- config.only = null
+ flatOptions.omit = []
})
t.test('--link', async t => {
@@ -581,7 +552,7 @@ t.test('ls', t => {
})
t.test('--production', async t => {
- config.production = true
+ flatOptions.omit = ['dev', 'peer']
npm.prefix = t.testdir({
'package.json': JSON.stringify({
name: 'test-npm-ls',
@@ -604,34 +575,7 @@ t.test('ls', t => {
})
await ls.exec([])
t.matchSnapshot(redactCwd(result), 'should output tree containing production deps')
- config.production = false
- })
-
- t.test('--only=prod', async t => {
- config.only = 'prod'
- npm.prefix = t.testdir({
- 'package.json': JSON.stringify({
- name: 'test-npm-ls',
- version: '1.0.0',
- dependencies: {
- 'prod-dep': '^1.0.0',
- chai: '^1.0.0',
- },
- devDependencies: {
- 'dev-dep': '^1.0.0',
- },
- optionalDependencies: {
- 'optional-dep': '^1.0.0',
- },
- peerDependencies: {
- 'peer-dep': '^1.0.0',
- },
- }),
- ...diffDepTypesNmFixture,
- })
- await ls.exec([])
- t.matchSnapshot(redactCwd(result), 'should output tree containing only prod deps')
- config.only = null
+ flatOptions.omit = []
})
t.test('--long', async t => {
@@ -1484,12 +1428,12 @@ t.test('ls', t => {
t.matchSnapshot(redactCwd(result), 'should list --all workspaces properly')
// --production
- config.production = true
+ flatOptions.omit = ['dev', 'peer', 'optional']
await ls.exec([])
t.matchSnapshot(redactCwd(result), 'should list only prod deps of workspaces')
- config.production = false
+ flatOptions.omit = []
// filter out a single workspace using args
await ls.exec(['d'])
@@ -1811,7 +1755,7 @@ t.test('ls --parseable', t => {
})
t.test('--dev', async t => {
- config.dev = true
+ flatOptions.omit = ['peer', 'prod', 'optional']
npm.prefix = t.testdir({
'package.json': JSON.stringify({
name: 'test-npm-ls',
@@ -1834,34 +1778,7 @@ t.test('ls --parseable', t => {
})
await ls.exec([])
t.matchSnapshot(redactCwd(result), 'should output tree containing dev deps')
- config.dev = false
- })
-
- t.test('--only=development', async t => {
- config.only = 'development'
- npm.prefix = t.testdir({
- 'package.json': JSON.stringify({
- name: 'test-npm-ls',
- version: '1.0.0',
- dependencies: {
- 'prod-dep': '^1.0.0',
- chai: '^1.0.0',
- },
- devDependencies: {
- 'dev-dep': '^1.0.0',
- },
- optionalDependencies: {
- 'optional-dep': '^1.0.0',
- },
- peerDependencies: {
- 'peer-dep': '^1.0.0',
- },
- }),
- ...diffDepTypesNmFixture,
- })
- await ls.exec([])
- t.matchSnapshot(redactCwd(result), 'should output tree containing only development deps')
- config.only = null
+ flatOptions.omit = []
})
t.test('--link', async t => {
@@ -1902,7 +1819,7 @@ t.test('ls --parseable', t => {
})
t.test('--production', async t => {
- config.production = true
+ flatOptions.omit = ['dev', 'peer']
npm.prefix = t.testdir({
'package.json': JSON.stringify({
name: 'test-npm-ls',
@@ -1925,34 +1842,7 @@ t.test('ls --parseable', t => {
})
await ls.exec([])
t.matchSnapshot(redactCwd(result), 'should output tree containing production deps')
- config.production = false
- })
-
- t.test('--only=prod', async t => {
- config.only = 'prod'
- npm.prefix = t.testdir({
- 'package.json': JSON.stringify({
- name: 'test-npm-ls',
- version: '1.0.0',
- dependencies: {
- 'prod-dep': '^1.0.0',
- chai: '^1.0.0',
- },
- devDependencies: {
- 'dev-dep': '^1.0.0',
- },
- optionalDependencies: {
- 'optional-dep': '^1.0.0',
- },
- peerDependencies: {
- 'peer-dep': '^1.0.0',
- },
- }),
- ...diffDepTypesNmFixture,
- })
- await ls.exec([])
- t.matchSnapshot(redactCwd(result), 'should output tree containing only prod deps')
- config.only = null
+ flatOptions.omit = []
})
t.test('--long', async t => {
@@ -2935,7 +2825,7 @@ t.test('ls --json', t => {
})
t.test('--dev', async t => {
- config.dev = true
+ flatOptions.omit = ['prod', 'optional', 'peer']
npm.prefix = t.testdir({
'package.json': JSON.stringify({
name: 'test-npm-ls',
@@ -2976,52 +2866,7 @@ t.test('ls --json', t => {
},
'should output json containing dev deps'
)
- config.dev = false
- })
-
- t.test('--only=development', async t => {
- config.only = 'development'
- npm.prefix = t.testdir({
- 'package.json': JSON.stringify({
- name: 'test-npm-ls',
- version: '1.0.0',
- dependencies: {
- 'prod-dep': '^1.0.0',
- chai: '^1.0.0',
- },
- devDependencies: {
- 'dev-dep': '^1.0.0',
- },
- optionalDependencies: {
- 'optional-dep': '^1.0.0',
- },
- peerDependencies: {
- 'peer-dep': '^1.0.0',
- },
- }),
- ...diffDepTypesNmFixture,
- })
- await ls.exec([])
- t.same(
- jsonParse(result),
- {
- name: 'test-npm-ls',
- version: '1.0.0',
- dependencies: {
- 'dev-dep': {
- version: '1.0.0',
- dependencies: {
- foo: {
- version: '1.0.0',
- dependencies: { dog: { version: '1.0.0' } },
- },
- },
- },
- },
- },
- 'should output json containing only development deps'
- )
- config.only = null
+ flatOptions.omit = []
})
t.test('--link', async t => {
@@ -3075,7 +2920,7 @@ t.test('ls --json', t => {
})
t.test('--production', async t => {
- config.production = true
+ flatOptions.omit = ['dev', 'peer']
npm.prefix = t.testdir({
'package.json': JSON.stringify({
name: 'test-npm-ls',
@@ -3110,46 +2955,7 @@ t.test('ls --json', t => {
},
'should output json containing production deps'
)
- config.production = false
- })
-
- t.test('--only=prod', async t => {
- config.only = 'prod'
- npm.prefix = t.testdir({
- 'package.json': JSON.stringify({
- name: 'test-npm-ls',
- version: '1.0.0',
- dependencies: {
- 'prod-dep': '^1.0.0',
- chai: '^1.0.0',
- },
- devDependencies: {
- 'dev-dep': '^1.0.0',
- },
- optionalDependencies: {
- 'optional-dep': '^1.0.0',
- },
- peerDependencies: {
- 'peer-dep': '^1.0.0',
- },
- }),
- ...diffDepTypesNmFixture,
- })
- await ls.exec([])
- t.same(
- jsonParse(result),
- {
- name: 'test-npm-ls',
- version: '1.0.0',
- dependencies: {
- chai: { version: '1.0.0' },
- 'optional-dep': { version: '1.0.0' },
- 'prod-dep': { version: '1.0.0', dependencies: { dog: { version: '2.0.0' } } },
- },
- },
- 'should output json containing only prod deps'
- )
- config.only = null
+ flatOptions.omit = []
})
t.test('from lockfile', async t => {
diff --git a/test/lib/commands/outdated.js b/test/lib/commands/outdated.js
index 3bf42b10a..14647ce6c 100644
--- a/test/lib/commands/outdated.js
+++ b/test/lib/commands/outdated.js
@@ -84,10 +84,6 @@ const globalDir = t.testdir({
},
})
-const flatOptions = {
- workspacesEnabled: true,
-}
-
const outdated = (dir, opts) => {
logs = ''
const Outdated = t.mock('../../../lib/commands/outdated.js', {
@@ -95,11 +91,22 @@ const outdated = (dir, opts) => {
packument,
},
})
+ if (opts.config && opts.config.omit) {
+ opts.flatOptions = {
+ omit: opts.config.omit,
+ ...opts.flatOptions,
+ }
+ delete opts.config.omit
+ }
const npm = mockNpm({
...opts,
localPrefix: dir,
prefix: dir,
- flatOptions,
+ flatOptions: {
+ workspacesEnabled: true,
+ omit: [],
+ ...opts.flatOptions,
+ },
globalDir: `${globalDir}/node_modules`,
output,
})
@@ -529,14 +536,16 @@ t.test('workspaces', async t => {
t.matchSnapshot(logs, 'should display ws outdated deps human output')
t.equal(process.exitCode, 1)
- flatOptions.workspacesEnabled = false
- await outdated(testDir, {}).exec([])
+ await outdated(testDir, {
+ flatOptions: {
+ workspacesEnabled: false,
+ },
+ }).exec([])
// TODO: This should display dog, but doesn't because arborist filters
// workspace deps even if they're also root deps
// This will be fixed in a future arborist version
t.matchSnapshot(logs, 'should display only root outdated when ws disabled')
- flatOptions.workspacesEnabled = true
await outdated(testDir, {
config: {