Skip to content

Commit e8bd8bc

Browse files
committed
test(arborist): add load-virtual and reify tests to demonstrate #4205
The tests show that the virtual tree ignores overrides on workspace dependencies, causing the corresponding nodes to have only their spec versions after reification.
1 parent b821eb0 commit e8bd8bc

File tree

8 files changed

+231
-0
lines changed

8 files changed

+231
-0
lines changed

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

+86
Original file line numberDiff line numberDiff line change
@@ -16375,6 +16375,92 @@ ArboristNode {
1637516375
}
1637616376
`
1637716377

16378+
exports[`test/arborist/load-virtual.js TAP workspaces load installed workspace with dependency overrides > virtual tree with overrides 1`] = `
16379+
ArboristNode {
16380+
"children": Map {
16381+
"arg" => ArboristNode {
16382+
"edgesIn": Set {
16383+
EdgeIn {
16384+
"error": "INVALID",
16385+
"from": "ws",
16386+
"name": "arg",
16387+
"spec": "4.1.2",
16388+
"type": "prod",
16389+
},
16390+
},
16391+
"location": "node_modules/arg",
16392+
"name": "arg",
16393+
"overrides": Map {
16394+
"arg" => "4.1.3",
16395+
},
16396+
"path": "{CWD}/test/fixtures/workspaces-with-overrides/node_modules/arg",
16397+
"resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz",
16398+
"version": "4.1.3",
16399+
},
16400+
"ws" => ArboristLink {
16401+
"edgesIn": Set {
16402+
EdgeIn {
16403+
"from": "",
16404+
"name": "ws",
16405+
"spec": "file:{CWD}/test/fixtures/workspaces-with-overrides/ws",
16406+
"type": "workspace",
16407+
},
16408+
},
16409+
"isWorkspace": true,
16410+
"location": "node_modules/ws",
16411+
"name": "ws",
16412+
"overrides": Map {
16413+
"arg" => "4.1.3",
16414+
},
16415+
"path": "{CWD}/test/fixtures/workspaces-with-overrides/node_modules/ws",
16416+
"realpath": "{CWD}/test/fixtures/workspaces-with-overrides/ws",
16417+
"resolved": "file:../ws",
16418+
"target": ArboristNode {
16419+
"location": "ws",
16420+
},
16421+
"version": "1.0.0",
16422+
},
16423+
},
16424+
"edgesOut": Map {
16425+
"ws" => EdgeOut {
16426+
"name": "ws",
16427+
"spec": "file:{CWD}/test/fixtures/workspaces-with-overrides/ws",
16428+
"to": "node_modules/ws",
16429+
"type": "workspace",
16430+
},
16431+
},
16432+
"fsChildren": Set {
16433+
ArboristNode {
16434+
"edgesOut": Map {
16435+
"arg" => EdgeOut {
16436+
"error": "INVALID",
16437+
"name": "arg",
16438+
"spec": "4.1.2",
16439+
"to": "node_modules/arg",
16440+
"type": "prod",
16441+
},
16442+
},
16443+
"isWorkspace": true,
16444+
"location": "ws",
16445+
"name": "ws",
16446+
"path": "{CWD}/test/fixtures/workspaces-with-overrides/ws",
16447+
"version": "1.0.0",
16448+
},
16449+
},
16450+
"isProjectRoot": true,
16451+
"location": "",
16452+
"name": "workspaces-with-overrides",
16453+
"overrides": Map {
16454+
"arg" => "4.1.3",
16455+
},
16456+
"packageName": "workspace-with-overrides",
16457+
"path": "{CWD}/test/fixtures/workspaces-with-overrides",
16458+
"workspaces": Map {
16459+
"ws" => "ws",
16460+
},
16461+
}
16462+
`
16463+
1637816464
exports[`test/arborist/load-virtual.js TAP workspaces load installed workspace with transitive dependencies > virtual tree with transitive deps 1`] = `
1637916465
ArboristNode {
1638016466
"children": Map {

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

+33
Original file line numberDiff line numberDiff line change
@@ -53497,6 +53497,39 @@ Object {
5349753497
}
5349853498
`
5349953499

53500+
exports[`test/arborist/reify.js TAP workspaces reify workspaces with overrides > should retain override version (4.1.3) 1`] = `
53501+
Object {
53502+
"lockfileVersion": 3,
53503+
"name": "workspace-with-overrides",
53504+
"packages": Object {
53505+
"": Object {
53506+
"name": "workspace-with-overrides",
53507+
"workspaces": Array [
53508+
"ws",
53509+
],
53510+
},
53511+
"node_modules/a": Object {
53512+
"link": true,
53513+
"resolved": "ws",
53514+
},
53515+
"ws": Object {
53516+
"dependencies": Object {
53517+
"arg": "4.1.2",
53518+
},
53519+
"name": "a",
53520+
"version": "1.0.0",
53521+
},
53522+
"ws/node_modules/arg": Object {
53523+
"integrity": "sha512-+ytCkGcBtHZ3V2r2Z06AncYO8jz46UEamcspGoU8lHcEbpn6J77QK0vdWvChsclg/tM5XIJC5tnjmPp7Eq6Obg==",
53524+
"license": "MIT",
53525+
"resolved": "https://registry.npmjs.org/arg/-/arg-4.1.2.tgz",
53526+
"version": "4.1.2",
53527+
},
53528+
},
53529+
"requires": true,
53530+
}
53531+
`
53532+
5350053533
exports[`test/arborist/reify.js TAP workspaces root as-a-workspace > should produce expected package-lock file 1`] = `
5350153534
Object {
5350253535
"lockfileVersion": 3,

workspaces/arborist/test/arborist/load-virtual.js

+6
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,12 @@ t.test('workspaces', t => {
204204
).then(tree =>
205205
t.matchSnapshot(printTree(tree), 'virtual tree ignoring nested node_modules')))
206206

207+
t.test('load installed workspace with dependency overrides', t =>
208+
loadVirtual(
209+
resolve(__dirname, '../fixtures/workspaces-with-overrides')
210+
).then(tree =>
211+
t.matchSnapshot(printTree(tree), 'virtual tree with overrides')))
212+
207213
t.end()
208214
})
209215

workspaces/arborist/test/arborist/reify.js

+7
Original file line numberDiff line numberDiff line change
@@ -1348,6 +1348,13 @@ t.test('workspaces', async t => {
13481348
t.matchSnapshot(require(path + '/package-lock.json'), 'should lock workspaces config')
13491349
})
13501350

1351+
await t.test('reify workspaces with overrides', async t => {
1352+
const path = fixture(t, 'workspaces-with-overrides')
1353+
createRegistry(t, true)
1354+
await reify(path, { workspacesEnabled: true, workspaces: ['ws'] })
1355+
t.matchSnapshot(require(path + '/package-lock.json'), 'should retain override version (4.1.3)')
1356+
})
1357+
13511358
await t.test('reify workspaces bin files', t => {
13521359
const path = fixture(t, 'workspaces-link-bin')
13531360
createRegistry(t, false)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// generated from test/fixtures/workspaces-with-overrides
2+
module.exports = t => {
3+
const path = t.testdir({
4+
"package-lock.json": JSON.stringify({
5+
"name": "workspace-with-overrides",
6+
"lockfileVersion": 3,
7+
"requires": true,
8+
"packages": {
9+
"": {
10+
"name": "workspace-with-overrides",
11+
"workspaces": [
12+
"ws"
13+
]
14+
},
15+
"node_modules/a": {
16+
"resolved": "ws",
17+
"link": true
18+
},
19+
"node_modules/arg": {
20+
"version": "4.1.3",
21+
"resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz",
22+
"integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==",
23+
"license": "MIT"
24+
},
25+
"ws": {
26+
"name": "a",
27+
"version": "1.0.0",
28+
"dependencies": {
29+
"arg": "4.1.2"
30+
}
31+
}
32+
}
33+
}),
34+
"package.json": JSON.stringify({
35+
"name": "workspace-with-overrides",
36+
"workspaces": [
37+
"ws"
38+
],
39+
"overrides": {
40+
"arg": "4.1.3"
41+
}
42+
}),
43+
"ws": {
44+
"package.json": JSON.stringify({
45+
"name": "a",
46+
"version": "1.0.0",
47+
"dependencies": {
48+
"arg": "4.1.2"
49+
}
50+
})
51+
}
52+
})
53+
return path
54+
}

workspaces/arborist/test/fixtures/workspaces-with-overrides/package-lock.json

+29
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "workspace-with-overrides",
3+
"workspaces": [
4+
"ws"
5+
],
6+
"overrides": {
7+
"arg": "4.1.3"
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "ws",
3+
"version": "1.0.0",
4+
"dependencies": {
5+
"arg": "4.1.2"
6+
}
7+
}

0 commit comments

Comments
 (0)