From 8f2bd9422c977a727497b65839ab70ac33210265 Mon Sep 17 00:00:00 2001 From: Trevor Burnham Date: Tue, 18 Feb 2025 14:10:34 -0500 Subject: [PATCH] chore: add load-virtual and reify tests for workspace override test coverage --- .../test/arborist/load-virtual.js.test.cjs | 83 ++++ .../test/arborist/reify.js.test.cjs | 33 ++ .../test/audit-report.js.test.cjs | 369 ------------------ .../tap-snapshots/test/shrinkwrap.js.test.cjs | 75 ++++ .../arborist/test/arborist/load-virtual.js | 6 + workspaces/arborist/test/arborist/reify.js | 7 + .../reify-cases/workspaces-with-overrides.js | 54 +++ .../package-lock.json | 29 ++ .../workspaces-with-overrides/package.json | 9 + .../workspaces-with-overrides/ws/package.json | 7 + 10 files changed, 303 insertions(+), 369 deletions(-) create mode 100644 workspaces/arborist/test/fixtures/reify-cases/workspaces-with-overrides.js create mode 100644 workspaces/arborist/test/fixtures/workspaces-with-overrides/package-lock.json create mode 100644 workspaces/arborist/test/fixtures/workspaces-with-overrides/package.json create mode 100644 workspaces/arborist/test/fixtures/workspaces-with-overrides/ws/package.json diff --git a/workspaces/arborist/tap-snapshots/test/arborist/load-virtual.js.test.cjs b/workspaces/arborist/tap-snapshots/test/arborist/load-virtual.js.test.cjs index c0210aabc54f3..f43e00d2c0e2f 100644 --- a/workspaces/arborist/tap-snapshots/test/arborist/load-virtual.js.test.cjs +++ b/workspaces/arborist/tap-snapshots/test/arborist/load-virtual.js.test.cjs @@ -16375,6 +16375,89 @@ ArboristNode { } ` +exports[`test/arborist/load-virtual.js TAP workspaces load installed workspace with dependency overrides > virtual tree with overrides 1`] = ` +ArboristNode { + "children": Map { + "arg" => ArboristNode { + "edgesIn": Set { + EdgeIn { + "error": "INVALID", + "from": "ws", + "name": "arg", + "spec": "4.1.2", + "type": "prod", + }, + }, + "location": "node_modules/arg", + "name": "arg", + "path": "{CWD}/test/fixtures/workspaces-with-overrides/node_modules/arg", + "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", + "version": "4.1.3", + }, + "ws" => ArboristLink { + "edgesIn": Set { + EdgeIn { + "from": "", + "name": "ws", + "spec": "file:{CWD}/test/fixtures/workspaces-with-overrides/ws", + "type": "workspace", + }, + }, + "isWorkspace": true, + "location": "node_modules/ws", + "name": "ws", + "overrides": Map { + "arg" => "4.1.3", + }, + "path": "{CWD}/test/fixtures/workspaces-with-overrides/node_modules/ws", + "realpath": "{CWD}/test/fixtures/workspaces-with-overrides/ws", + "resolved": "file:../ws", + "target": ArboristNode { + "location": "ws", + }, + "version": "1.0.0", + }, + }, + "edgesOut": Map { + "ws" => EdgeOut { + "name": "ws", + "spec": "file:{CWD}/test/fixtures/workspaces-with-overrides/ws", + "to": "node_modules/ws", + "type": "workspace", + }, + }, + "fsChildren": Set { + ArboristNode { + "edgesOut": Map { + "arg" => EdgeOut { + "error": "INVALID", + "name": "arg", + "spec": "4.1.2", + "to": "node_modules/arg", + "type": "prod", + }, + }, + "isWorkspace": true, + "location": "ws", + "name": "ws", + "path": "{CWD}/test/fixtures/workspaces-with-overrides/ws", + "version": "1.0.0", + }, + }, + "isProjectRoot": true, + "location": "", + "name": "workspaces-with-overrides", + "overrides": Map { + "arg" => "4.1.3", + }, + "packageName": "workspace-with-overrides", + "path": "{CWD}/test/fixtures/workspaces-with-overrides", + "workspaces": Map { + "ws" => "ws", + }, +} +` + exports[`test/arborist/load-virtual.js TAP workspaces load installed workspace with transitive dependencies > virtual tree with transitive deps 1`] = ` ArboristNode { "children": Map { diff --git a/workspaces/arborist/tap-snapshots/test/arborist/reify.js.test.cjs b/workspaces/arborist/tap-snapshots/test/arborist/reify.js.test.cjs index cec3560033241..797f102234f5d 100644 --- a/workspaces/arborist/tap-snapshots/test/arborist/reify.js.test.cjs +++ b/workspaces/arborist/tap-snapshots/test/arborist/reify.js.test.cjs @@ -53497,6 +53497,39 @@ Object { } ` +exports[`test/arborist/reify.js TAP workspaces reify workspaces with overrides > should retain override version (4.1.3) 1`] = ` +Object { + "lockfileVersion": 3, + "name": "workspace-with-overrides", + "packages": Object { + "": Object { + "name": "workspace-with-overrides", + "workspaces": Array [ + "ws", + ], + }, + "node_modules/a": Object { + "link": true, + "resolved": "ws", + }, + "node_modules/arg": Object { + "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==", + "license": "MIT", + "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", + "version": "4.1.3", + }, + "ws": Object { + "dependencies": Object { + "arg": "4.1.2", + }, + "name": "a", + "version": "1.0.0", + }, + }, + "requires": true, +} +` + exports[`test/arborist/reify.js TAP workspaces root as-a-workspace > should produce expected package-lock file 1`] = ` Object { "lockfileVersion": 3, diff --git a/workspaces/arborist/tap-snapshots/test/audit-report.js.test.cjs b/workspaces/arborist/tap-snapshots/test/audit-report.js.test.cjs index cc1354e64c818..2d2374afff4af 100644 --- a/workspaces/arborist/tap-snapshots/test/audit-report.js.test.cjs +++ b/workspaces/arborist/tap-snapshots/test/audit-report.js.test.cjs @@ -1269,375 +1269,6 @@ exports[`test/audit-report.js TAP audit outdated nyc and mkdirp with before: opt } ` -exports[`test/audit-report.js TAP audit outdated nyc and mkdirp with newer endpoint > json version 1`] = ` -{ - "auditReportVersion": 2, - "vulnerabilities": { - "handlebars": { - "name": "handlebars", - "severity": "critical", - "isDirect": false, - "via": [ - { - "source": 1164, - "name": "handlebars", - "dependency": "handlebars", - "title": "Prototype Pollution", - "url": "https://npmjs.com/advisories/1164", - "severity": "high", - "range": "<3.0.8 || >=4.0.0 <4.3.0" - }, - { - "source": 1300, - "name": "handlebars", - "dependency": "handlebars", - "title": "Denial of Service", - "url": "https://npmjs.com/advisories/1300", - "severity": "moderate", - "range": ">=4.0.0 <4.4.5" - }, - { - "source": 1316, - "name": "handlebars", - "dependency": "handlebars", - "title": "Arbitrary Code Execution", - "url": "https://npmjs.com/advisories/1316", - "severity": "high", - "range": "<3.0.8 || >=4.0.0 <4.5.2" - }, - { - "source": 1324, - "name": "handlebars", - "dependency": "handlebars", - "title": "Arbitrary Code Execution", - "url": "https://npmjs.com/advisories/1324", - "severity": "high", - "range": "<3.0.8 || >=4.0.0 <4.5.3" - }, - { - "source": 1325, - "name": "handlebars", - "dependency": "handlebars", - "title": "Prototype Pollution", - "url": "https://npmjs.com/advisories/1325", - "severity": "high", - "range": "<3.0.8 || >=4.0.0 <4.5.3" - }, - { - "source": 755, - "name": "handlebars", - "dependency": "handlebars", - "title": "Prototype Pollution", - "url": "https://npmjs.com/advisories/755", - "severity": "critical", - "range": "<=4.0.13 || >=4.1.0 <4.1.2" - }, - "optimist" - ], - "effects": [], - "range": "<=4.7.3", - "nodes": [ - "node_modules/nyc/node_modules/handlebars" - ], - "fixAvailable": true - }, - "kind-of": { - "name": "kind-of", - "severity": "low", - "isDirect": false, - "via": [ - { - "source": 1490, - "name": "kind-of", - "dependency": "kind-of", - "title": "Validation Bypass", - "url": "https://npmjs.com/advisories/1490", - "severity": "low", - "range": ">=6.0.0 <6.0.3" - } - ], - "effects": [], - "range": "6.0.0 - 6.0.2", - "nodes": [ - "node_modules/nyc/node_modules/base/node_modules/kind-of", - "node_modules/nyc/node_modules/define-property/node_modules/kind-of", - "node_modules/nyc/node_modules/extglob/node_modules/kind-of", - "node_modules/nyc/node_modules/micromatch/node_modules/kind-of", - "node_modules/nyc/node_modules/nanomatch/node_modules/kind-of", - "node_modules/nyc/node_modules/snapdragon-node/node_modules/kind-of", - "node_modules/nyc/node_modules/test-exclude/node_modules/kind-of", - "node_modules/nyc/node_modules/use/node_modules/kind-of" - ], - "fixAvailable": true - }, - "lodash": { - "name": "lodash", - "severity": "high", - "isDirect": false, - "via": [ - { - "source": 1065, - "name": "lodash", - "dependency": "lodash", - "title": "Prototype Pollution", - "url": "https://npmjs.com/advisories/1065", - "severity": "high", - "range": "<4.17.12" - }, - { - "source": 782, - "name": "lodash", - "dependency": "lodash", - "title": "Prototype Pollution", - "url": "https://npmjs.com/advisories/782", - "severity": "high", - "range": "<4.17.11" - } - ], - "effects": [], - "range": "<=4.17.11", - "nodes": [ - "node_modules/nyc/node_modules/lodash" - ], - "fixAvailable": true - }, - "mem": { - "name": "mem", - "severity": "low", - "isDirect": false, - "via": [ - { - "source": 1084, - "name": "mem", - "dependency": "mem", - "title": "Denial of Service", - "url": "https://npmjs.com/advisories/1084", - "severity": "low", - "range": "<4.0.0" - } - ], - "effects": [ - "os-locale" - ], - "range": "<4.0.0", - "nodes": [ - "node_modules/nyc/node_modules/mem" - ], - "fixAvailable": { - "name": "nyc", - "version": "15.1.0", - "isSemVerMajor": true - } - }, - "minimist": { - "name": "minimist", - "severity": "low", - "isDirect": false, - "via": [ - { - "source": 1179, - "name": "minimist", - "dependency": "minimist", - "title": "Prototype Pollution", - "url": "https://npmjs.com/advisories/1179", - "severity": "low", - "range": "<0.2.1 || >=1.0.0 <1.2.3" - } - ], - "effects": [ - "mkdirp", - "optimist" - ], - "range": "<0.2.1 || >=1.0.0 <1.2.3", - "nodes": [ - "node_modules/minimist", - "node_modules/nyc/node_modules/minimist" - ], - "fixAvailable": { - "name": "nyc", - "version": "15.1.0", - "isSemVerMajor": true - } - }, - "mixin-deep": { - "name": "mixin-deep", - "severity": "high", - "isDirect": false, - "via": [ - { - "source": 1013, - "name": "mixin-deep", - "dependency": "mixin-deep", - "title": "Prototype Pollution", - "url": "https://npmjs.com/advisories/1013", - "severity": "high", - "range": "<1.3.2 || >=2.0.0 <2.0.1" - } - ], - "effects": [], - "range": "<=1.3.1 || 2.0.0", - "nodes": [ - "node_modules/nyc/node_modules/mixin-deep" - ], - "fixAvailable": true - }, - "mkdirp": { - "name": "mkdirp", - "severity": "low", - "isDirect": true, - "via": [ - "minimist" - ], - "effects": [ - "nyc" - ], - "range": "0.4.1 - 0.5.1", - "nodes": [ - "node_modules/mkdirp", - "node_modules/nyc/node_modules/mkdirp" - ], - "fixAvailable": { - "name": "nyc", - "version": "15.1.0", - "isSemVerMajor": true - } - }, - "nyc": { - "name": "nyc", - "severity": "low", - "isDirect": true, - "via": [ - "mkdirp", - "yargs" - ], - "effects": [], - "range": "6.2.0-alpha - 13.1.0", - "nodes": [ - "node_modules/nyc" - ], - "fixAvailable": { - "name": "nyc", - "version": "15.1.0", - "isSemVerMajor": true - } - }, - "optimist": { - "name": "optimist", - "severity": "low", - "isDirect": false, - "via": [ - "minimist" - ], - "effects": [ - "handlebars" - ], - "range": ">=0.6.0", - "nodes": [ - "node_modules/nyc/node_modules/optimist" - ], - "fixAvailable": true - }, - "os-locale": { - "name": "os-locale", - "severity": "low", - "isDirect": false, - "via": [ - "mem" - ], - "effects": [ - "yargs" - ], - "range": "2.0.0 - 3.0.0", - "nodes": [ - "node_modules/nyc/node_modules/os-locale" - ], - "fixAvailable": { - "name": "nyc", - "version": "15.1.0", - "isSemVerMajor": true - } - }, - "set-value": { - "name": "set-value", - "severity": "high", - "isDirect": false, - "via": [ - { - "source": 1012, - "name": "set-value", - "dependency": "set-value", - "title": "Prototype Pollution", - "url": "https://npmjs.com/advisories/1012", - "severity": "high", - "range": "<2.0.1 || >=3.0.0 <3.0.1" - } - ], - "effects": [ - "union-value" - ], - "range": "<=2.0.0 || 3.0.0", - "nodes": [ - "node_modules/nyc/node_modules/set-value", - "node_modules/nyc/node_modules/union-value/node_modules/set-value" - ], - "fixAvailable": true - }, - "union-value": { - "name": "union-value", - "severity": "high", - "isDirect": false, - "via": [ - "set-value" - ], - "effects": [], - "range": "<=1.0.0 || 2.0.0", - "nodes": [ - "node_modules/nyc/node_modules/union-value" - ], - "fixAvailable": true - }, - "yargs": { - "name": "yargs", - "severity": "low", - "isDirect": false, - "via": [ - "os-locale" - ], - "effects": [ - "nyc" - ], - "range": "8.0.1 - 11.1.0 || 12.0.0-candidate.0 - 12.0.1", - "nodes": [ - "node_modules/nyc/node_modules/yargs" - ], - "fixAvailable": { - "name": "nyc", - "version": "15.1.0", - "isSemVerMajor": true - } - } - }, - "metadata": { - "vulnerabilities": { - "info": 0, - "low": 8, - "moderate": 0, - "high": 4, - "critical": 1, - "total": 13 - }, - "dependencies": { - "prod": 318, - "dev": 0, - "optional": 12, - "peer": 0, - "peerOptional": 0, - "total": 329 - } - } -} -` - exports[`test/audit-report.js TAP audit report with a lying v5 lockfile > must match snapshot 1`] = ` Object { "auditReportVersion": 2, diff --git a/workspaces/arborist/tap-snapshots/test/shrinkwrap.js.test.cjs b/workspaces/arborist/tap-snapshots/test/shrinkwrap.js.test.cjs index 9103febb644ee..e2fde91c439e3 100644 --- a/workspaces/arborist/tap-snapshots/test/shrinkwrap.js.test.cjs +++ b/workspaces/arborist/tap-snapshots/test/shrinkwrap.js.test.cjs @@ -2719,6 +2719,81 @@ Object { } ` +exports[`test/shrinkwrap.js TAP loadActual tests selflink > shrinkwrap data 2`] = ` +Object { + "lockfileVersion": 3, + "name": "selflink", + "packages": Object { + "": Object { + "dependencies": Object { + "@scope/x": "", + "@scope/y": "", + "foo": "", + }, + "name": "selflink", + "version": "1.2.3", + }, + "node_modules/@scope/y": Object { + "dependencies": Object { + "foo": "*", + }, + "version": "1.2.3", + }, + "node_modules/@scope/z": Object { + "dependencies": Object { + "glob": "4", + }, + "extraneous": true, + "version": "1.2.3", + }, + "node_modules/@scope/z/node_modules/glob": Object { + "link": true, + "resolved": "node_modules/foo/node_modules/glob", + }, + "node_modules/foo": Object { + "dependencies": Object { + "glob": "4", + "selflink": "*", + }, + "version": "1.2.3", + }, + "node_modules/foo/node_modules/glob": Object { + "version": "4.0.5", + }, + "node_modules/foo/node_modules/glob/node_modules/graceful-fs": Object { + "extraneous": true, + "version": "3.0.2", + }, + "node_modules/foo/node_modules/glob/node_modules/inherits": Object { + "extraneous": true, + "version": "2.0.1", + }, + "node_modules/foo/node_modules/glob/node_modules/minimatch": Object { + "extraneous": true, + "version": "1.0.0", + }, + "node_modules/foo/node_modules/glob/node_modules/minimatch/node_modules/lru-cache": Object { + "extraneous": true, + "version": "2.5.0", + }, + "node_modules/foo/node_modules/glob/node_modules/minimatch/node_modules/sigmund": Object { + "extraneous": true, + "version": "1.0.0", + }, + "node_modules/foo/node_modules/glob/node_modules/once": Object { + "extraneous": true, + "version": "1.3.0", + }, + "node_modules/foo/node_modules/selflink": Object { + "link": true, + "resolved": "", + }, + }, + "requires": true, + "version": "1.2.3", +} +` + exports[`test/shrinkwrap.js TAP loadActual tests symlinked-node-modules/example > shrinkwrap data 1`] = ` Object { "lockfileVersion": 3, diff --git a/workspaces/arborist/test/arborist/load-virtual.js b/workspaces/arborist/test/arborist/load-virtual.js index 3b50444c851ae..4540d969d71a9 100644 --- a/workspaces/arborist/test/arborist/load-virtual.js +++ b/workspaces/arborist/test/arborist/load-virtual.js @@ -204,6 +204,12 @@ t.test('workspaces', t => { ).then(tree => t.matchSnapshot(printTree(tree), 'virtual tree ignoring nested node_modules'))) + t.test('load installed workspace with dependency overrides', t => + loadVirtual( + resolve(__dirname, '../fixtures/workspaces-with-overrides') + ).then(tree => + t.matchSnapshot(printTree(tree), 'virtual tree with overrides'))) + t.end() }) diff --git a/workspaces/arborist/test/arborist/reify.js b/workspaces/arborist/test/arborist/reify.js index 65148c9993f80..a85678d2acd45 100644 --- a/workspaces/arborist/test/arborist/reify.js +++ b/workspaces/arborist/test/arborist/reify.js @@ -1348,6 +1348,13 @@ t.test('workspaces', async t => { t.matchSnapshot(require(path + '/package-lock.json'), 'should lock workspaces config') }) + await t.test('reify workspaces with overrides', async t => { + const path = fixture(t, 'workspaces-with-overrides') + createRegistry(t, true) + await reify(path, { workspacesEnabled: true, workspaces: ['ws'] }) + t.matchSnapshot(require(path + '/package-lock.json'), 'should retain override version (4.1.3)') + }) + await t.test('reify workspaces bin files', t => { const path = fixture(t, 'workspaces-link-bin') createRegistry(t, false) diff --git a/workspaces/arborist/test/fixtures/reify-cases/workspaces-with-overrides.js b/workspaces/arborist/test/fixtures/reify-cases/workspaces-with-overrides.js new file mode 100644 index 0000000000000..b20ba236d87e1 --- /dev/null +++ b/workspaces/arborist/test/fixtures/reify-cases/workspaces-with-overrides.js @@ -0,0 +1,54 @@ +// generated from test/fixtures/workspaces-with-overrides +module.exports = t => { + const path = t.testdir({ + "package-lock.json": JSON.stringify({ + "name": "workspace-with-overrides", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "workspace-with-overrides", + "workspaces": [ + "ws" + ] + }, + "node_modules/a": { + "resolved": "ws", + "link": true + }, + "node_modules/arg": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", + "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==", + "license": "MIT" + }, + "ws": { + "name": "a", + "version": "1.0.0", + "dependencies": { + "arg": "4.1.2" + } + } + } + }), + "package.json": JSON.stringify({ + "name": "workspace-with-overrides", + "workspaces": [ + "ws" + ], + "overrides": { + "arg": "4.1.3" + } + }), + "ws": { + "package.json": JSON.stringify({ + "name": "a", + "version": "1.0.0", + "dependencies": { + "arg": "4.1.2" + } + }) + } +}) + return path +} diff --git a/workspaces/arborist/test/fixtures/workspaces-with-overrides/package-lock.json b/workspaces/arborist/test/fixtures/workspaces-with-overrides/package-lock.json new file mode 100644 index 0000000000000..a7bbd20bbcb93 --- /dev/null +++ b/workspaces/arborist/test/fixtures/workspaces-with-overrides/package-lock.json @@ -0,0 +1,29 @@ +{ + "name": "workspace-with-overrides", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "workspace-with-overrides", + "workspaces": [ + "ws" + ] + }, + "node_modules/arg": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", + "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==", + "license": "MIT" + }, + "node_modules/ws": { + "resolved": "ws", + "link": true + }, + "ws": { + "version": "1.0.0", + "dependencies": { + "arg": "4.1.2" + } + } + } +} diff --git a/workspaces/arborist/test/fixtures/workspaces-with-overrides/package.json b/workspaces/arborist/test/fixtures/workspaces-with-overrides/package.json new file mode 100644 index 0000000000000..9f35f2abd82fc --- /dev/null +++ b/workspaces/arborist/test/fixtures/workspaces-with-overrides/package.json @@ -0,0 +1,9 @@ +{ + "name": "workspace-with-overrides", + "workspaces": [ + "ws" + ], + "overrides": { + "arg": "4.1.3" + } +} diff --git a/workspaces/arborist/test/fixtures/workspaces-with-overrides/ws/package.json b/workspaces/arborist/test/fixtures/workspaces-with-overrides/ws/package.json new file mode 100644 index 0000000000000..b44d12e431fbe --- /dev/null +++ b/workspaces/arborist/test/fixtures/workspaces-with-overrides/ws/package.json @@ -0,0 +1,7 @@ +{ + "name": "ws", + "version": "1.0.0", + "dependencies": { + "arg": "4.1.2" + } +}