Skip to content

Commit

Permalink
test(plugin-commands-installation): refactor dedupe test to use jest-…
Browse files Browse the repository at this point in the history
…diff
  • Loading branch information
gluxon committed Jan 23, 2023
1 parent d7b14a3 commit 832e6f8
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 199 deletions.
Original file line number Diff line number Diff line change
@@ -1,197 +1,93 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`removes packages from pnpm-lock.yaml 1`] = `
{
"importers": {
".": {
"specifiers": {},
},
"packages/bar": {
"dependencies": {
"ajv": "6.10.2",
},
"specifiers": {
"ajv": "^6.10.2",
},
},
"packages/foo": {
"dependencies": {
"ajv": "6.12.6",
},
"specifiers": {
"ajv": "^6.12.5",
},
},
},
"lockfileVersion": 5.4,
"packages": {
"/ajv/6.10.2": {
"dependencies": {
"fast-deep-equal": "2.0.1",
"fast-json-stable-stringify": "2.0.0",
"json-schema-traverse": "0.4.1",
"uri-js": "4.2.2",
},
"dev": false,
"resolution": {
"integrity": "sha512-TXtUUEYHuaTEbLZWIKUr5pmBuhDLy+8KYtPYdcV8qC+pOZL+NKqYwvWSRrVXHn+ZmRRAu8vJTAznH7Oag6RVRw==",
},
},
"/ajv/6.12.6": {
"dependencies": {
"fast-deep-equal": "3.1.3",
"fast-json-stable-stringify": "2.1.0",
"json-schema-traverse": "0.4.1",
"uri-js": "4.4.1",
},
"dev": false,
"resolution": {
"integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==",
},
},
"/fast-deep-equal/2.0.1": {
"dev": false,
"resolution": {
"integrity": "sha512-bCK/2Z4zLidyB4ReuIsvALH6w31YfAQDmXMqMx6FyfHqvBxtjC0eRumeSu4Bs3XtXwpyIywtSTrVT99BxY1f9w==",
},
},
"/fast-deep-equal/3.1.3": {
"dev": false,
"resolution": {
"integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==",
},
},
"/fast-json-stable-stringify/2.0.0": {
"dev": false,
"resolution": {
"integrity": "sha1-1RQsDK7msRifh9OnYREGT4bIu/I=",
},
},
"/fast-json-stable-stringify/2.1.0": {
"dev": false,
"resolution": {
"integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==",
},
},
"/json-schema-traverse/0.4.1": {
"dev": false,
"resolution": {
"integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==",
},
},
"/punycode/2.1.1": {
"dev": false,
"engines": {
"node": ">=6",
},
"resolution": {
"integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==",
},
},
"/punycode/2.3.0": {
"dev": false,
"engines": {
"node": ">=6",
},
"resolution": {
"integrity": "sha512-rRV+zQD8tVFys26lAGR9WUuS4iUAngJScM+ZRSKtvl5tKeZ2t5bvdNFdNHBW9FWR4guGHlgmsZ1G7BSm2wTbuA==",
},
},
"/uri-js/4.2.2": {
"dependencies": {
"punycode": "2.1.1",
},
"dev": false,
"resolution": {
"integrity": "sha512-KY9Frmirql91X2Qgjry0Wd4Y+YTdrdZheS8TFwvkbLWf/G5KNJDCh6pKL5OZctEW4+0Baa5idK2ZQuELRwPznQ==",
},
},
"/uri-js/4.4.1": {
"dependencies": {
"punycode": "2.3.0",
},
"dev": false,
"resolution": {
"integrity": "sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==",
},
},
},
}
`;
exports[`pnpm dedupe updates old resolutions from importers block and removes old packages 1`] = `
"- Expected
+ Received
exports[`removes packages from pnpm-lock.yaml 2`] = `
{
"importers": {
".": {
"specifiers": {},
},
"packages/bar": {
"dependencies": {
"ajv": "6.12.6",
},
"specifiers": {
"ajv": "^6.10.2",
},
},
"packages/foo": {
"dependencies": {
"ajv": "6.12.6",
},
"specifiers": {
"ajv": "^6.12.5",
},
},
},
"lockfileVersion": 5.4,
"packages": {
"/ajv/6.12.6": {
"dependencies": {
"fast-deep-equal": "3.1.3",
"fast-json-stable-stringify": "2.1.0",
"json-schema-traverse": "0.4.1",
"uri-js": "4.4.1",
},
"dev": false,
"resolution": {
"integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==",
},
},
"/fast-deep-equal/3.1.3": {
"dev": false,
"resolution": {
"integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==",
},
},
"/fast-json-stable-stringify/2.1.0": {
"dev": false,
"resolution": {
"integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==",
},
},
"/json-schema-traverse/0.4.1": {
"dev": false,
"resolution": {
"integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==",
},
},
"/punycode/2.3.0": {
"dev": false,
"engines": {
"node": ">=6",
},
"resolution": {
"integrity": "sha512-rRV+zQD8tVFys26lAGR9WUuS4iUAngJScM+ZRSKtvl5tKeZ2t5bvdNFdNHBW9FWR4guGHlgmsZ1G7BSm2wTbuA==",
},
},
"/uri-js/4.4.1": {
"dependencies": {
"punycode": "2.3.0",
},
"dev": false,
"resolution": {
"integrity": "sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==",
},
},
},
}
@@ -5,7 +5,7 @@
},
"packages/bar": Object {
"dependencies": Object {
- "ajv": "6.10.2",
+ "ajv": "6.12.6",
},
"specifiers": Object {
"ajv": "^6.10.2",
@@ -22,18 +22,6 @@
},
"lockfileVersion": 5.4,
"packages": Object {
- "/ajv/6.10.2": Object {
- "dependencies": Object {
- "fast-deep-equal": "2.0.1",
- "fast-json-stable-stringify": "2.0.0",
- "json-schema-traverse": "0.4.1",
- "uri-js": "4.2.2",
- },
- "dev": false,
- "resolution": Object {
- "integrity": "sha512-TXtUUEYHuaTEbLZWIKUr5pmBuhDLy+8KYtPYdcV8qC+pOZL+NKqYwvWSRrVXHn+ZmRRAu8vJTAznH7Oag6RVRw==",
- },
- },
"/ajv/6.12.6": Object {
"dependencies": Object {
"fast-deep-equal": "3.1.3",
@@ -44,24 +32,12 @@
"dev": false,
"resolution": Object {
"integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==",
- },
- },
- "/fast-deep-equal/2.0.1": Object {
- "dev": false,
- "resolution": Object {
- "integrity": "sha512-bCK/2Z4zLidyB4ReuIsvALH6w31YfAQDmXMqMx6FyfHqvBxtjC0eRumeSu4Bs3XtXwpyIywtSTrVT99BxY1f9w==",
},
},
"/fast-deep-equal/3.1.3": Object {
"dev": false,
"resolution": Object {
"integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==",
- },
- },
- "/fast-json-stable-stringify/2.0.0": Object {
- "dev": false,
- "resolution": Object {
- "integrity": "sha1-1RQsDK7msRifh9OnYREGT4bIu/I=",
},
},
"/fast-json-stable-stringify/2.1.0": Object {
@@ -75,16 +51,7 @@
"resolution": Object {
"integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==",
},
- },
- "/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 {
@@ -92,15 +59,6 @@
},
"resolution": Object {
"integrity": "sha512-rRV+zQD8tVFys26lAGR9WUuS4iUAngJScM+ZRSKtvl5tKeZ2t5bvdNFdNHBW9FWR4guGHlgmsZ1G7BSm2wTbuA==",
- },
- },
- "/uri-js/4.2.2": Object {
- "dependencies": Object {
- "punycode": "2.1.1",
- },
- "dev": false,
- "resolution": Object {
- "integrity": "sha512-KY9Frmirql91X2Qgjry0Wd4Y+YTdrdZheS8TFwvkbLWf/G5KNJDCh6pKL5OZctEW4+0Baa5idK2ZQuELRwPznQ==",
},
},
"/uri-js/4.4.1": Object {"
`;
37 changes: 31 additions & 6 deletions pkg-manager/plugin-commands-installation/test/dedupe.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,42 @@
import path from 'path'
import { readProjects } from '@pnpm/filter-workspace-packages'
import { Lockfile } from '@pnpm/lockfile-types'
import { dedupe, install } from '@pnpm/plugin-commands-installation'
import { prepare } from '@pnpm/prepare'
import { fixtures } from '@pnpm/test-fixtures'
import { diff } from 'jest-diff'
import readYamlFile from 'read-yaml-file'
import { DEFAULT_OPTS } from './utils'
import { Lockfile } from '@pnpm/lockfile-types'

const f = fixtures(__dirname)

test('removes packages from pnpm-lock.yaml', async () => {
describe('pnpm dedupe', () => {
test('updates old resolutions from importers block and removes old packages', async () => {
const { originalLockfile, dedupedLockfile } = await testFixture('workspace-with-lockfile-dupes')
// Many old packages should be deleted as result of deduping. See snapshot file for details.
expect(diff(originalLockfile, dedupedLockfile, diffOptsForLockfile)).toMatchSnapshot()
})
})

const noColor = (str: string) => str
const diffOptsForLockfile = {
// Avoid showing common lines to make the snapshot smaller and less noisy.
// https://github.com/facebook/jest/tree/05deb8393c4ad71/packages/jest-diff#example-of-options-to-limit-common-lines
contextLines: 3,
expand: false,

// Remove color from snapshots
// https://github.com/facebook/jest/tree/05deb8393c4ad71/packages/jest-diff#example-of-options-for-no-colors
aColor: noColor,
bColor: noColor,
changeColor: noColor,
commonColor: noColor,
patchColor: noColor,
}

async function testFixture (fixtureName: string) {
const project = prepare(undefined)
f.copy('workspace-with-lockfile-dupes', project.dir())
f.copy(fixtureName, project.dir())

const { allProjects, selectedProjectsGraph } = await readProjects(project.dir(), [])

Expand All @@ -31,7 +56,6 @@ test('removes packages from pnpm-lock.yaml', async () => {

// Sanity check that this test is set up correctly by ensuring the lockfile is
// unmodified after a regular install.
expect(originalLockfile).toMatchSnapshot()
await install.handler(opts)
expect(await readProjectLockfile()).toEqual(originalLockfile)

Expand All @@ -40,7 +64,6 @@ test('removes packages from pnpm-lock.yaml', async () => {
await dedupe.handler(opts)

const dedupedLockfile = await readProjectLockfile()
expect(dedupedLockfile).toMatchSnapshot()

// It's possible to remove many packages from the fixture lockfile.
const originalLockfilePackageNames = Object.keys(originalLockfile.packages ?? {})
Expand All @@ -56,4 +79,6 @@ test('removes packages from pnpm-lock.yaml', async () => {
// make any further edits to the lockfile.
await install.handler(opts)
expect(await readProjectLockfile()).toEqual(dedupedLockfile)
})

return { originalLockfile, dedupedLockfile }
}
4 changes: 4 additions & 0 deletions pnpm-lock.yaml

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

0 comments on commit 832e6f8

Please sign in to comment.