Skip to content

Commit 619d43e

Browse files
chore: fix pruner and reify tests for optional peer deps (#8540)
While investigating CI failure in #8537, I found unrelated test failures when running locally on windows. `prune with lockfile with implicit optional peer dependencies` fixed by adding files to fixture `node_modules`, avoiding network, also reduced package lock to minimum and removed unhelpful snapshots `move aside symlink clutter` fixed by creating problematic symlink in `t.testdir()` instead of in `reifyPackages` hook --------- Co-authored-by: Liam Mitchell <[email protected]>
1 parent bdcc10d commit 619d43e

File tree

8 files changed

+43
-736
lines changed

8 files changed

+43
-736
lines changed

workspaces/arborist/tap-snapshots/test/arborist/load-actual.js.test.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7784,4 +7784,4 @@ ArboristNode {
77847784
"name": "yarn-lock-mkdirp-file-dep",
77857785
"path": "yarn-lock-mkdirp-file-dep",
77867786
}
7787-
`
7787+
`

workspaces/arborist/tap-snapshots/test/arborist/pruner.js.test.cjs

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -124,82 +124,6 @@ ArboristNode {
124124
}
125125
`
126126

127-
exports[`test/arborist/pruner.js TAP prune with lockfile with implicit optional peer dependencies > should remove all deps from reified tree 1`] = `
128-
ArboristNode {
129-
"children": Map {
130-
"dedent" => ArboristNode {
131-
"edgesIn": Set {
132-
EdgeIn {
133-
"from": "",
134-
"name": "dedent",
135-
"spec": "^1.6.0",
136-
"type": "prod",
137-
},
138-
},
139-
"edgesOut": Map {
140-
"babel-plugin-macros" => EdgeOut {
141-
"name": "babel-plugin-macros",
142-
"spec": "^3.1.0",
143-
"to": null,
144-
"type": "peerOptional",
145-
},
146-
},
147-
"location": "node_modules/dedent",
148-
"name": "dedent",
149-
"path": "{CWD}/test/arborist/tap-testdir-pruner-prune-with-lockfile-with-implicit-optional-peer-dependencies/node_modules/dedent",
150-
"resolved": "https://registry.npmjs.org/dedent/-/dedent-1.6.0.tgz",
151-
"version": "1.6.0",
152-
},
153-
},
154-
"edgesOut": Map {
155-
"dedent" => EdgeOut {
156-
"name": "dedent",
157-
"spec": "^1.6.0",
158-
"to": "node_modules/dedent",
159-
"type": "prod",
160-
},
161-
},
162-
"isProjectRoot": true,
163-
"location": "",
164-
"name": "tap-testdir-pruner-prune-with-lockfile-with-implicit-optional-peer-dependencies",
165-
"packageName": "prune-lockfile-optional-peer",
166-
"path": "{CWD}/test/arborist/tap-testdir-pruner-prune-with-lockfile-with-implicit-optional-peer-dependencies",
167-
"version": "1.0.0",
168-
}
169-
`
170-
171-
exports[`test/arborist/pruner.js TAP prune with lockfile with implicit optional peer dependencies > should remove optional peer dependencies in package-lock.json 1`] = `
172-
Object {
173-
"lockfileVersion": 3,
174-
"name": "prune-lockfile-optional-peer",
175-
"packages": Object {
176-
"": Object {
177-
"dependencies": Object {
178-
"dedent": "^1.6.0",
179-
},
180-
"name": "prune-lockfile-optional-peer",
181-
"version": "1.0.0",
182-
},
183-
"node_modules/dedent": Object {
184-
"integrity": "sha512-F1Z+5UCFpmQUzJa11agbyPVMbpgT/qA3/SKyJ1jyBgm7dUcUEa8v9JwDkerSQXfakBwFljIxhOJqGkjUwZ9FSA==",
185-
"license": "MIT",
186-
"peerDependencies": Object {
187-
"babel-plugin-macros": "^3.1.0",
188-
},
189-
"peerDependenciesMeta": Object {
190-
"babel-plugin-macros": Object {
191-
"optional": true,
192-
},
193-
},
194-
"resolved": "https://registry.npmjs.org/dedent/-/dedent-1.6.0.tgz",
195-
"version": "1.6.0",
196-
},
197-
},
198-
"requires": true,
199-
"version": "1.0.0",
200-
}
201-
`
202-
203127
exports[`test/arborist/pruner.js TAP prune workspaces > must match snapshot 1`] = `
204128
ArboristNode {
205129
"children": Map {

workspaces/arborist/test/arborist/pruner.js

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,32 +39,19 @@ t.test('prune with lockfile', async t => {
3939
})
4040

4141
t.test('prune with lockfile with implicit optional peer dependencies', async t => {
42-
registry.audit({})
43-
const opts = {}
44-
45-
// todo: for some reason on Windows when doing this test NPM looks for
46-
// the cache in the home directory, resulting in an unexpected real
47-
// call being made to the registry
48-
if (process.platform === 'win32') {
49-
opts.cache = 'C:\\npm\\cache\\_cacache'
50-
}
51-
5242
const path = fixture(t, 'prune-lockfile-optional-peer')
53-
const tree = await pruneTree(path, opts)
43+
const tree = await pruneTree(path, { audit: false })
5444

5545
const dep = tree.children.get('dedent')
56-
t.ok(dep, 'required prod dep was pruned from tree')
46+
t.ok(dep, 'required prod dep was not pruned from tree')
5747

5848
const optionalPeerDep = tree.children.get('babel-plugin-macros')
59-
t.notOk(optionalPeerDep, 'all listed optional peer deps pruned from tree')
49+
t.notOk(optionalPeerDep, 'optional peer dep was pruned from tree')
6050

61-
t.matchSnapshot(
62-
require(path + '/package-lock.json'),
63-
'should remove optional peer dependencies in package-lock.json'
64-
)
65-
t.matchSnapshot(
66-
printTree(tree),
67-
'should remove all deps from reified tree'
51+
t.notMatch(
52+
fs.readFileSync(path + '/package-lock.json'),
53+
'node_modules/babel-plugin-macros',
54+
'should remove optional peer dep from package-lock.json'
6855
)
6956
})
7057

workspaces/arborist/test/arborist/reify.js

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2444,28 +2444,20 @@ t.test('move aside symlink clutter', async t => {
24442444
file: 'do not delete me please',
24452445
'package.json': JSON.stringify({ name: 'ABBREV', version: '1.0.0' }),
24462446
},
2447-
'sensitivity-test': t.fixture('symlink', './target'),
2447+
node_modules: {
2448+
ABBREV: t.fixture('symlink', '../target'),
2449+
},
24482450
})
24492451

24502452
// check to see if we're on a case-insensitive fs
24512453
try {
2452-
const st = fs.lstatSync(path + '/SENSITIVITY-TEST')
2454+
const st = fs.lstatSync(path + '/node_modules/abbrev')
24532455
t.equal(st.isSymbolicLink(), true, 'fs is case insensitive')
24542456
} catch (er) {
24552457
t.plan(0, 'case sensitive file system, test not relevant')
24562458
return
24572459
}
24582460

2459-
const kReifyPackages = Symbol.for('reifyPackages')
2460-
const reifyPackages = Arborist.prototype[kReifyPackages]
2461-
t.teardown(() => Arborist.prototype[kReifyPackages] = reifyPackages)
2462-
Arborist.prototype[kReifyPackages] = async function () {
2463-
fs.mkdirSync(path + '/node_modules')
2464-
fs.symlinkSync('../target', path + '/node_modules/ABBREV')
2465-
Arborist.prototype[kReifyPackages] = reifyPackages
2466-
return this[kReifyPackages]()
2467-
}
2468-
24692461
createRegistry(t, true)
24702462
const tree = await printReified(path)
24712463
const st = fs.lstatSync(path + '/node_modules/abbrev')

workspaces/arborist/test/fixtures/create-reify-case.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ if (hiddenLocks.length) {
129129
}
130130
}
131131

132-
writeFileSync(outFile, `// generated from ${rel}
132+
writeFileSync(outFile, `// generated from ${rel.replaceAll('\\', '/')}
133133
module.exports = t => {
134134
const path = ${output}
135135
return path

workspaces/arborist/test/fixtures/prune-lockfile-optional-peer/node_modules/dedent/package.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)