From eac1bf26f28e9e8fc07e1350c3d7b14a94005ebf Mon Sep 17 00:00:00 2001 From: nlf Date: Mon, 1 Aug 2022 11:02:18 -0700 Subject: fix(ls): when filtering workspaces, make sure the edge has a to before checking if its a workspace (#5164) --- test/lib/commands/ls.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'test') diff --git a/test/lib/commands/ls.js b/test/lib/commands/ls.js index 412d5ce65..f4cd4ef33 100644 --- a/test/lib/commands/ls.js +++ b/test/lib/commands/ls.js @@ -178,6 +178,44 @@ t.test('ls', t => { ) }) + t.test('workspace and missing optional dep', async t => { + npm.prefix = npm.localPrefix = t.testdir({ + 'package.json': JSON.stringify({ + name: 'root', + dependencies: { + foo: '^1.0.0', + }, + optionalDependencies: { + bar: '^1.0.0', + }, + workspaces: ['./baz'], + }), + baz: { + 'package.json': JSON.stringify({ + name: 'baz', + version: '1.0.0', + }), + }, + node_modules: { + baz: t.fixture('symlink', '../baz'), + foo: { + 'package.json': JSON.stringify({ + name: 'foo', + version: '1.0.0', + }), + }, + }, + }) + + npm.flatOptions.includeWorkspaceRoot = true + t.teardown(() => { + delete npm.flatOptions.includeWorkspaceRoot + }) + + await ls.execWorkspaces([], ['baz']) + t.matchSnapshot(redactCwd(result), 'should omit missing optional dep') + }) + t.test('extraneous deps', async t => { npm.prefix = t.testdir({ 'package.json': JSON.stringify({ -- cgit v1.2.3