-
Notifications
You must be signed in to change notification settings - Fork 333
/
package-lock.json.unit.test.mjs
89 lines (78 loc) · 2.81 KB
/
package-lock.json.unit.test.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import semver from 'semver'
describe('package-lock.json', () => {
let packages = /** @type {import('./package-lock.json')["packages"]} */ ({})
beforeAll(async () => {
packages = (await import('./package-lock.json')).packages
})
describe('Dependabot updates', () => {
/**
* When this check fails, the incorrect `package-lock.json` can be repaired
* by checking out the Dependabot branch and running `npm install` to remove
* the hoisted dependency
*
* {@link https://team-playbook.design-system.service.gov.uk/how-we-work/version-control/pull-requests#reviewing-a-pr-from-dependabot}
*/
it("should not hoist 'optionalDependencies' to 'dependencies'", () => {
const { dependencies, optionalDependencies } = packages['']
// List package names for comparison
const packageNames = Object.keys(dependencies ?? {})
const packageNamesOptional = Object.keys(optionalDependencies ?? {})
// Check no optional dependencies are hoisted
for (const name of packageNamesOptional) {
expect(packageNames).not.toContain(name)
}
})
})
describe("Shared helper 'peerDependencies'", () => {
it('should maintain `puppeteer` bundled `@puppeteer/browsers` compatibility', () => {
const helpers = packages['shared/helpers']
const puppeteer = packages['node_modules/puppeteer']
// Bundled package `@puppeteer/browsers` versus peer dependencies
const installed = puppeteer.dependencies['@puppeteer/browsers']
const expected = helpers.peerDependencies['@puppeteer/browsers']
expect({
'@puppeteer/browsers': {
parent: 'shared/helpers',
installed,
expected,
compatible: semver.intersects(expected, installed)
}
}).toEqual({
'@puppeteer/browsers': {
parent: 'shared/helpers',
installed,
expected,
compatible: true
}
})
})
it("should maintain `puppeteer` workspace 'devDependencies' compatibility", () => {
const helpers = packages['shared/helpers']
for (const name of /** @type {const} */ ([
'packages/govuk-frontend-review',
'packages/govuk-frontend',
'shared/helpers',
'shared/tasks'
])) {
// Development package `puppeteer` versus peer dependencies
const installed = packages[name].devDependencies.puppeteer
const expected = helpers.peerDependencies['puppeteer-core']
expect({
puppeteer: {
parent: name,
installed,
expected,
compatible: semver.intersects(expected, installed)
}
}).toEqual({
puppeteer: {
parent: name,
installed,
expected,
compatible: true
}
})
}
})
})
})