Skip to content

Commit

Permalink
test(plugin-commands-installation): add test for "updates old resolut…
Browse files Browse the repository at this point in the history
…ions from package block"
  • Loading branch information
gluxon committed Jan 23, 2023
1 parent 832e6f8 commit 8010d61
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "bar",
"dependencies": {
"uri-js": "=4.2.2"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "foo",
"dependencies": {
"uri-js": "=4.4.1"
}
}
42 changes: 42 additions & 0 deletions __fixtures__/workspace-with-lockfile-subdep-dupes/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
packages:
- 'packages/**'
1 change: 1 addition & 0 deletions pkg-manager/plugin-commands-installation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"@types/yarnpkg__lockfile": "^1.1.5",
"@types/zkochan__table": "npm:@types/table@6.0.0",
"delay": "^5.0.0",
"jest-diff": "^29.3.1",
"path-name": "^1.0.0",
"proxyquire": "^2.1.3",
"read-yaml-file": "^2.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,34 @@ exports[`pnpm dedupe updates old resolutions from importers block and removes ol
},
"/uri-js/4.4.1": Object {"
`;
exports[`pnpm dedupe updates old resolutions from package block 1`] = `
"- Expected
+ Received
@@ -22,15 +22,6 @@
},
"lockfileVersion": 5.4,
"packages": Object {
- "/punycode/2.1.1": Object {
- "dev": false,
- "engines": Object {
- "node": ">=6",
- },
- "resolution": Object {
- "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==",
- },
- },
"/punycode/2.3.0": Object {
"dev": false,
"engines": Object {
@@ -42,7 +33,7 @@
},
"/uri-js/4.2.2": Object {
"dependencies": Object {
- "punycode": "2.1.1",
+ "punycode": "2.3.0",
},
"dev": false,
"resolution": Object {"
`;
9 changes: 8 additions & 1 deletion pkg-manager/plugin-commands-installation/test/dedupe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ describe('pnpm dedupe', () => {
// Many old packages should be deleted as result of deduping. See snapshot file for details.
expect(diff(originalLockfile, dedupedLockfile, diffOptsForLockfile)).toMatchSnapshot()
})

test('updates old resolutions from package block', async () => {
const { originalLockfile, dedupedLockfile } = await testFixture('workspace-with-lockfile-subdep-dupes')
// This is a smaller scale test that should just update uri-js@4.2.2 to
// punycode@2.3.0 and remove punycode@2.1.1. See snapshot file for details.
expect(diff(originalLockfile, dedupedLockfile, diffOptsForLockfile)).toMatchSnapshot()
})
})

const noColor = (str: string) => str
Expand Down Expand Up @@ -65,7 +72,7 @@ async function testFixture (fixtureName: string) {

const dedupedLockfile = await readProjectLockfile()

// It's possible to remove many packages from the fixture lockfile.
// It should be possible to remove packages from the fixture lockfile.
const originalLockfilePackageNames = Object.keys(originalLockfile.packages ?? {})
const dedupedLockfilePackageNames = Object.keys(dedupedLockfile.packages ?? {})
expect(dedupedLockfilePackageNames.length).toBeLessThan(originalLockfilePackageNames.length)
Expand Down

0 comments on commit 8010d61

Please sign in to comment.