diff options
author | Luke Karrys <luke@lukekarrys.com> | 2021-11-03 03:29:19 +0300 |
---|---|---|
committer | Luke Karrys <luke@lukekarrys.com> | 2021-11-04 01:03:58 +0300 |
commit | e5bfdaca455e294109ba026f4d8b5cc80d3dfd20 (patch) | |
tree | a8a1ff16011f55456a211ecdf8c759285f9edd05 /tap-snapshots | |
parent | 8ffeb71dfb248b4a76744bd06cd4d6100f17c8ae (diff) |
fix: shrinkwrap setting incorrect lockfileVersion
Fix: #3962
When created from a hidden lockfile, shrinkwrap was always setting the
lockfileVersion to 3. The shrinkwrap command also needed to be updated
to log the correct message based on the lockfileVersion config instead
of the static lockfileVersion.
With these fixes, it was possible to log a better message whenever we
are changing the lockfileVersion, either from a config or any existing
lockfile.
Lastly, the tests for shrinkwrap were completely refactored to use the
real npm and test all conceivable scenarios, as well as removing usage
of `util.promisify` in favor of `fs.promises` now that we've dropped
support for Node 10.
PR-URL: https://github.com/npm/cli/pull/3978
Credit: @lukekarrys
Close: #3978
Reviewed-by: @wraithgar
Diffstat (limited to 'tap-snapshots')
-rw-r--r-- | tap-snapshots/test/lib/commands/shrinkwrap.js.test.cjs | 396 |
1 files changed, 396 insertions, 0 deletions
diff --git a/tap-snapshots/test/lib/commands/shrinkwrap.js.test.cjs b/tap-snapshots/test/lib/commands/shrinkwrap.js.test.cjs new file mode 100644 index 000000000..a0d579577 --- /dev/null +++ b/tap-snapshots/test/lib/commands/shrinkwrap.js.test.cjs @@ -0,0 +1,396 @@ +/* IMPORTANT + * This snapshot file is auto-generated, but designed for humans. + * It should be checked into source control and tracked carefully. + * Re-generate by setting TAP_SNAPSHOT=1 and running tests. + * Make sure to inspect the output below. Do not ignore changes! + */ +'use strict' +exports[`test/lib/commands/shrinkwrap.js TAP with hidden lockfile ancient > must match snapshot 1`] = ` +{ + "localPrefix": { + "node_modules": { + ".package-lock.json": { + "lockfileVersion": 1 + } + } + }, + "config": {}, + "shrinkwrap": { + "name": "tap-testdir-shrinkwrap-with-hidden-lockfile-ancient", + "lockfileVersion": 1, + "requires": true + }, + "logs": [ + "created a lockfile as npm-shrinkwrap.json" + ] +} +` + +exports[`test/lib/commands/shrinkwrap.js TAP with hidden lockfile ancient upgrade > must match snapshot 1`] = ` +{ + "localPrefix": { + "node_modules": { + ".package-lock.json": { + "lockfileVersion": 1 + } + } + }, + "config": { + "lockfileVersion": 3 + }, + "shrinkwrap": { + "name": "tap-testdir-shrinkwrap-with-hidden-lockfile-ancient-upgrade", + "lockfileVersion": 3, + "requires": true, + "packages": {} + }, + "logs": [ + "created a lockfile as npm-shrinkwrap.json with version 3" + ] +} +` + +exports[`test/lib/commands/shrinkwrap.js TAP with hidden lockfile existing > must match snapshot 1`] = ` +{ + "localPrefix": { + "node_modules": { + ".package-lock.json": { + "lockfileVersion": 2 + } + } + }, + "config": {}, + "shrinkwrap": { + "name": "tap-testdir-shrinkwrap-with-hidden-lockfile-existing", + "lockfileVersion": 2, + "requires": true, + "packages": {} + }, + "logs": [ + "created a lockfile as npm-shrinkwrap.json" + ] +} +` + +exports[`test/lib/commands/shrinkwrap.js TAP with hidden lockfile existing downgrade > must match snapshot 1`] = ` +{ + "localPrefix": { + "node_modules": { + ".package-lock.json": { + "lockfileVersion": 2 + } + } + }, + "config": { + "lockfileVersion": 1 + }, + "shrinkwrap": { + "name": "tap-testdir-shrinkwrap-with-hidden-lockfile-existing-downgrade", + "lockfileVersion": 1, + "requires": true + }, + "logs": [ + "created a lockfile as npm-shrinkwrap.json with version 1" + ] +} +` + +exports[`test/lib/commands/shrinkwrap.js TAP with hidden lockfile existing upgrade > must match snapshot 1`] = ` +{ + "localPrefix": { + "node_modules": { + ".package-lock.json": { + "lockfileVersion": 2 + } + } + }, + "config": { + "lockfileVersion": 3 + }, + "shrinkwrap": { + "name": "tap-testdir-shrinkwrap-with-hidden-lockfile-existing-upgrade", + "lockfileVersion": 3, + "requires": true, + "packages": {} + }, + "logs": [ + "created a lockfile as npm-shrinkwrap.json with version 3" + ] +} +` + +exports[`test/lib/commands/shrinkwrap.js TAP with nothing ancient > must match snapshot 1`] = ` +{ + "localPrefix": {}, + "config": {}, + "shrinkwrap": { + "name": "tap-testdir-shrinkwrap-with-nothing-ancient", + "lockfileVersion": 2, + "requires": true, + "packages": {} + }, + "logs": [ + "created a lockfile as npm-shrinkwrap.json with version 2" + ] +} +` + +exports[`test/lib/commands/shrinkwrap.js TAP with nothing ancient upgrade > must match snapshot 1`] = ` +{ + "localPrefix": {}, + "config": { + "lockfileVersion": 3 + }, + "shrinkwrap": { + "name": "tap-testdir-shrinkwrap-with-nothing-ancient-upgrade", + "lockfileVersion": 3, + "requires": true, + "packages": {} + }, + "logs": [ + "created a lockfile as npm-shrinkwrap.json with version 3" + ] +} +` + +exports[`test/lib/commands/shrinkwrap.js TAP with npm-shrinkwrap.json ancient > must match snapshot 1`] = ` +{ + "localPrefix": { + "npm-shrinkwrap.json": { + "lockfileVersion": 1 + } + }, + "config": {}, + "shrinkwrap": { + "name": "tap-testdir-shrinkwrap-with-npm-shrinkwrap.json-ancient", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "name": "tap-testdir-shrinkwrap-with-npm-shrinkwrap.json-ancient" + } + } + }, + "logs": [ + "npm-shrinkwrap.json updated to version 2" + ] +} +` + +exports[`test/lib/commands/shrinkwrap.js TAP with npm-shrinkwrap.json ancient upgrade > must match snapshot 1`] = ` +{ + "localPrefix": { + "npm-shrinkwrap.json": { + "lockfileVersion": 1 + } + }, + "config": { + "lockfileVersion": 3 + }, + "shrinkwrap": { + "name": "tap-testdir-shrinkwrap-with-npm-shrinkwrap.json-ancient-upgrade", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "tap-testdir-shrinkwrap-with-npm-shrinkwrap.json-ancient-upgrade" + } + } + }, + "logs": [ + "npm-shrinkwrap.json updated to version 3" + ] +} +` + +exports[`test/lib/commands/shrinkwrap.js TAP with npm-shrinkwrap.json existing > must match snapshot 1`] = ` +{ + "localPrefix": { + "npm-shrinkwrap.json": { + "lockfileVersion": 2 + } + }, + "config": {}, + "shrinkwrap": { + "name": "tap-testdir-shrinkwrap-with-npm-shrinkwrap.json-existing", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "name": "tap-testdir-shrinkwrap-with-npm-shrinkwrap.json-existing" + } + } + }, + "logs": [ + "npm-shrinkwrap.json up to date" + ] +} +` + +exports[`test/lib/commands/shrinkwrap.js TAP with npm-shrinkwrap.json existing downgrade > must match snapshot 1`] = ` +{ + "localPrefix": { + "npm-shrinkwrap.json": { + "lockfileVersion": 2 + } + }, + "config": { + "lockfileVersion": 1 + }, + "shrinkwrap": { + "name": "tap-testdir-shrinkwrap-with-npm-shrinkwrap.json-existing-downgrade", + "lockfileVersion": 1, + "requires": true + }, + "logs": [ + "npm-shrinkwrap.json updated to version 1" + ] +} +` + +exports[`test/lib/commands/shrinkwrap.js TAP with npm-shrinkwrap.json existing upgrade > must match snapshot 1`] = ` +{ + "localPrefix": { + "npm-shrinkwrap.json": { + "lockfileVersion": 2 + } + }, + "config": { + "lockfileVersion": 3 + }, + "shrinkwrap": { + "name": "tap-testdir-shrinkwrap-with-npm-shrinkwrap.json-existing-upgrade", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "tap-testdir-shrinkwrap-with-npm-shrinkwrap.json-existing-upgrade" + } + } + }, + "logs": [ + "npm-shrinkwrap.json updated to version 3" + ] +} +` + +exports[`test/lib/commands/shrinkwrap.js TAP with package-lock.json ancient > must match snapshot 1`] = ` +{ + "localPrefix": { + "package-lock.json": { + "lockfileVersion": 1 + } + }, + "config": {}, + "shrinkwrap": { + "name": "tap-testdir-shrinkwrap-with-package-lock.json-ancient", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "name": "tap-testdir-shrinkwrap-with-package-lock.json-ancient" + } + } + }, + "logs": [ + "package-lock.json has been renamed to npm-shrinkwrap.json and updated to version 2" + ] +} +` + +exports[`test/lib/commands/shrinkwrap.js TAP with package-lock.json ancient upgrade > must match snapshot 1`] = ` +{ + "localPrefix": { + "package-lock.json": { + "lockfileVersion": 1 + } + }, + "config": { + "lockfileVersion": 3 + }, + "shrinkwrap": { + "name": "tap-testdir-shrinkwrap-with-package-lock.json-ancient-upgrade", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "tap-testdir-shrinkwrap-with-package-lock.json-ancient-upgrade" + } + } + }, + "logs": [ + "package-lock.json has been renamed to npm-shrinkwrap.json and updated to version 3" + ] +} +` + +exports[`test/lib/commands/shrinkwrap.js TAP with package-lock.json existing > must match snapshot 1`] = ` +{ + "localPrefix": { + "package-lock.json": { + "lockfileVersion": 2 + } + }, + "config": {}, + "shrinkwrap": { + "name": "tap-testdir-shrinkwrap-with-package-lock.json-existing", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "name": "tap-testdir-shrinkwrap-with-package-lock.json-existing" + } + } + }, + "logs": [ + "package-lock.json has been renamed to npm-shrinkwrap.json" + ] +} +` + +exports[`test/lib/commands/shrinkwrap.js TAP with package-lock.json existing downgrade > must match snapshot 1`] = ` +{ + "localPrefix": { + "package-lock.json": { + "lockfileVersion": 2 + } + }, + "config": { + "lockfileVersion": 1 + }, + "shrinkwrap": { + "name": "tap-testdir-shrinkwrap-with-package-lock.json-existing-downgrade", + "lockfileVersion": 1, + "requires": true + }, + "logs": [ + "package-lock.json has been renamed to npm-shrinkwrap.json and updated to version 1" + ] +} +` + +exports[`test/lib/commands/shrinkwrap.js TAP with package-lock.json existing upgrade > must match snapshot 1`] = ` +{ + "localPrefix": { + "package-lock.json": { + "lockfileVersion": 2 + } + }, + "config": { + "lockfileVersion": 3 + }, + "shrinkwrap": { + "name": "tap-testdir-shrinkwrap-with-package-lock.json-existing-upgrade", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "tap-testdir-shrinkwrap-with-package-lock.json-existing-upgrade" + } + } + }, + "logs": [ + "package-lock.json has been renamed to npm-shrinkwrap.json and updated to version 3" + ] +} +` |