-
Notifications
You must be signed in to change notification settings - Fork 371
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GR: Add simple test for package-lock.json writing (#891)
Added a basic-ish lockfile write test, which needs the mock npm registry. Also, fixed a bug on an edge-case where if the new version has new dependency types (e.g. newly added `optionalDependencies`) it wouldn't get added to the newly-written lockfile. I had to change how I attempt to preserve formatting to do that.
- Loading branch information
1 parent
49223c7
commit 785b6c2
Showing
8 changed files
with
358 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
192 changes: 192 additions & 0 deletions
192
internal/resolution/lockfile/__snapshots__/npm_test.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
|
||
[TestNpmWrite - 1] | ||
{ | ||
"name": "r", | ||
"version": "1.0.0", | ||
"lockfileVersion": 2, | ||
"requires": true, | ||
"packages": { | ||
"": { | ||
"name": "r", | ||
"version": "1.0.0", | ||
"license": "ISC", | ||
"workspaces": [ | ||
"W" | ||
], | ||
"dependencies": { | ||
"@fake-registry/a": "^1.2.3", | ||
"@fake-registry/b": "^1.0.1" | ||
}, | ||
"devDependencies": { | ||
"a-dev": "npm:@fake-registry/a@^2.3.4" | ||
} | ||
}, | ||
"node_modules/@fake-registry/a": { | ||
"version": "1.2.4", | ||
"resolved": "http://localhost:4873/@fake-registry%2fa/-/a-1.2.4.tgz", | ||
"integrity": "sha512-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa==", | ||
"license": "OriginalLicenseDoNotSteal", | ||
"dependencies": { | ||
"@fake-registry/b": "^1.0.0", | ||
"@fake-registry/e": "^1.0.0" | ||
} | ||
}, | ||
"node_modules/@fake-registry/b": { | ||
"version": "1.0.1", | ||
"resolved": "http://localhost:4873/@fake-registry%2fb/-/b-1.0.1.tgz", | ||
"integrity": "sha512-uocjkNUbEPBa/oFFYNq+CkWkkr4My+gJQHnB1fFqIrIQtvjbQ/4dtp/6Kmfb5SFJ/bVfAGZ8mmC+c3Bz4JISYQ==", | ||
"license": "ISC" | ||
}, | ||
"node_modules/@fake-registry/c": { | ||
"version": "1.1.1", | ||
"resolved": "http://localhost:4873/@fake-registry%2fc/-/c-1.1.1.tgz", | ||
"integrity": "sha512-bihWUzvU62dcwPN4TguhntQpC1zpj7H0fHAhffya6tl3BCrEdjqO4oEpNHF/jtU5PPvY0L60mJNUS6MbizEVrA==", | ||
"dev": true, | ||
"license": "BSD-2-Clause", | ||
"peerDependencies": { | ||
"@fake-registry/d": "^2.0.0" | ||
} | ||
}, | ||
"node_modules/@fake-registry/d": { | ||
"version": "2.2.2", | ||
"resolved": "http://localhost:4873/@fake-registry%2fd/-/d-2.2.2.tgz", | ||
"integrity": "sha512-YLeJVbfOCJZcUizGgpvPesIVSY9TYmWz2HcF+7mWxSuXuvu13FABprnRSDGEhljBRM+QAaUD+nbUHWenq2vL4w==", | ||
"dev": true, | ||
"license": "ISC" | ||
}, | ||
"node_modules/a-dev": { | ||
"name": "@fake-registry/a", | ||
"version": "2.3.5", | ||
"resolved": "http://localhost:4873/@fake-registry%2fa/-/a-2.3.5.tgz", | ||
"integrity": "none", | ||
"dev": true, | ||
"license": "Stolen", | ||
"optionalDependencies": { | ||
"@fake-registry/b": "*" | ||
} | ||
}, | ||
"node_modules/a-dev/node_modules/@fake-registry/b": { | ||
"version": "2.0.0", | ||
"resolved": "http://localhost:4873/@fake-registry%2fb/-/b-2.0.0.tgz", | ||
"integrity": "sha512-ZYMUG0g+wowBRAVWuRMI9mV8/3IJ5tYw1i+Xedy5LjVo7RAQaOqJbhEWvdubBlkmaXSoI666cdnJIX/SI6FPpw==", | ||
"dev": true, | ||
"license": "ISC", | ||
"dependencies": { | ||
"@fake-registry/c": "^1.0.0", | ||
"@fake-registry/d": "^2.0.0" | ||
} | ||
}, | ||
"node_modules/w": { | ||
"resolved": "W", | ||
"link": true | ||
}, | ||
"W": { | ||
"name": "w", | ||
"version": "1.0.0", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"@fake-registry/a": "^2.3.4" | ||
} | ||
}, | ||
"W/node_modules/@fake-registry/a": { | ||
"version": "2.3.5", | ||
"resolved": "http://localhost:4873/@fake-registry%2fa/-/a-2.3.5.tgz", | ||
"integrity": "none", | ||
"dev": true, | ||
"license": "Stolen", | ||
"optionalDependencies": { | ||
"@fake-registry/b": "*" | ||
} | ||
}, | ||
"W/node_modules/@fake-registry/b": { | ||
"version": "2.0.0", | ||
"resolved": "http://localhost:4873/@fake-registry%2fb/-/b-2.0.0.tgz", | ||
"integrity": "sha512-ZYMUG0g+wowBRAVWuRMI9mV8/3IJ5tYw1i+Xedy5LjVo7RAQaOqJbhEWvdubBlkmaXSoI666cdnJIX/SI6FPpw==", | ||
"dev": true, | ||
"license": "ISC", | ||
"dependencies": { | ||
"@fake-registry/c": "^1.0.0", | ||
"@fake-registry/d": "^2.0.0" | ||
} | ||
} | ||
}, | ||
"dependencies": { | ||
"@fake-registry/a": { | ||
"version": "1.2.4", | ||
"resolved": "http://localhost:4873/@fake-registry%2fa/-/a-1.2.4.tgz", | ||
"integrity": "sha512-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa==", | ||
"requires": { | ||
"@fake-registry/b": "^1.0.0", | ||
"@fake-registry/e": "^1.0.0" | ||
} | ||
}, | ||
"@fake-registry/b": { | ||
"version": "1.0.1", | ||
"resolved": "http://localhost:4873/@fake-registry%2fb/-/b-1.0.1.tgz", | ||
"integrity": "sha512-uocjkNUbEPBa/oFFYNq+CkWkkr4My+gJQHnB1fFqIrIQtvjbQ/4dtp/6Kmfb5SFJ/bVfAGZ8mmC+c3Bz4JISYQ==" | ||
}, | ||
"@fake-registry/c": { | ||
"version": "1.1.1", | ||
"resolved": "http://localhost:4873/@fake-registry%2fc/-/c-1.1.1.tgz", | ||
"integrity": "sha512-bihWUzvU62dcwPN4TguhntQpC1zpj7H0fHAhffya6tl3BCrEdjqO4oEpNHF/jtU5PPvY0L60mJNUS6MbizEVrA==", | ||
"dev": true, | ||
"requires": {} | ||
}, | ||
"@fake-registry/d": { | ||
"version": "2.2.2", | ||
"resolved": "http://localhost:4873/@fake-registry%2fd/-/d-2.2.2.tgz", | ||
"integrity": "sha512-YLeJVbfOCJZcUizGgpvPesIVSY9TYmWz2HcF+7mWxSuXuvu13FABprnRSDGEhljBRM+QAaUD+nbUHWenq2vL4w==", | ||
"dev": true | ||
}, | ||
"a-dev": { | ||
"version": "npm:@fake-registry/[email protected]", | ||
"resolved": "http://localhost:4873/@fake-registry%2fa/-/a-2.3.5.tgz", | ||
"integrity": "none", | ||
"dev": true, | ||
"requires": { | ||
"@fake-registry/b": "*" | ||
}, | ||
"dependencies": { | ||
"@fake-registry/b": { | ||
"version": "2.0.0", | ||
"resolved": "http://localhost:4873/@fake-registry%2fb/-/b-2.0.0.tgz", | ||
"integrity": "sha512-ZYMUG0g+wowBRAVWuRMI9mV8/3IJ5tYw1i+Xedy5LjVo7RAQaOqJbhEWvdubBlkmaXSoI666cdnJIX/SI6FPpw==", | ||
"dev": true, | ||
"requires": { | ||
"@fake-registry/c": "^1.0.0", | ||
"@fake-registry/d": "^2.0.0" | ||
} | ||
} | ||
} | ||
}, | ||
"w": { | ||
"version": "file:W", | ||
"requires": { | ||
"@fake-registry/a": "^2.3.4" | ||
}, | ||
"dependencies": { | ||
"@fake-registry/a": { | ||
"version": "2.3.5", | ||
"resolved": "http://localhost:4873/@fake-registry%2fa/-/a-2.3.5.tgz", | ||
"integrity": "none", | ||
"dev": true, | ||
"requires": { | ||
"@fake-registry/b": "*" | ||
} | ||
}, | ||
"@fake-registry/b": { | ||
"version": "2.0.0", | ||
"resolved": "http://localhost:4873/@fake-registry%2fb/-/b-2.0.0.tgz", | ||
"integrity": "sha512-ZYMUG0g+wowBRAVWuRMI9mV8/3IJ5tYw1i+Xedy5LjVo7RAQaOqJbhEWvdubBlkmaXSoI666cdnJIX/SI6FPpw==", | ||
"dev": true, | ||
"requires": { | ||
"@fake-registry/c": "^1.0.0", | ||
"@fake-registry/d": "^2.0.0" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
--- |
26 changes: 26 additions & 0 deletions
26
internal/resolution/lockfile/fixtures/npm_registry/@fake-registry-a-1.2.4.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"name": "@fake-registry/a", | ||
"version": "1.2.4", | ||
"description": "package a", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": { | ||
"name": "a author" | ||
}, | ||
"license": "OriginalLicenseDoNotSteal", | ||
"dependencies": { | ||
"@fake-registry/b": "^1.0.0", | ||
"@fake-registry/e": "^1.0.0" | ||
}, | ||
"_id": "@fake-registry/[email protected]", | ||
"_nodeVersion": "10.24.1", | ||
"_npmVersion": "7.24.2", | ||
"dist": { | ||
"integrity": "sha512-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa==", | ||
"shasum": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", | ||
"tarball": "http://localhost:4873/@fake-registry%2fa/-/a-1.2.4.tgz" | ||
}, | ||
"contributors": [] | ||
} |
28 changes: 28 additions & 0 deletions
28
internal/resolution/lockfile/fixtures/npm_registry/@fake-registry-a-2.3.5.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "@fake-registry/a", | ||
"version": "2.3.5", | ||
"description": "package a@2", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": { | ||
"name": "a@2 author" | ||
}, | ||
"license": "Stolen", | ||
"optionalDependencies": { | ||
"@fake-registry/b": "*" | ||
}, | ||
"dependencies": { | ||
"@fake-registry/b": "*" | ||
}, | ||
"_id": "@fake-registry/[email protected]", | ||
"_nodeVersion": "10.24.1", | ||
"_npmVersion": "7.24.2", | ||
"dist": { | ||
"integrity": "none", | ||
"shasum": "ffffffff", | ||
"tarball": "http://localhost:4873/@fake-registry%2fa/-/a-2.3.5.tgz" | ||
}, | ||
"contributors": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.