Debian Codegraph @

workspaces/arborist/test/override-set.js

raw
1 const t = require('tap')
2 const OverrideSet = require('../lib/override-set.js')
3
4 t.test('constructor', async (t) => {
5 t.test('throws when adding a child rule with no name', async (t) => {
6 t.throws(() => {
7 new OverrideSet({
8 overrides: {
9 'github:npm/cli': '1.0.0',
10 },
11 })
12 }, 'Override without name: github:npm/cli', 'threw error')
13 })
14
15 t.test('loads overrides', async (t) => {
16 const overrides = new OverrideSet({
17 overrides: {
18 'a@1': { '.': '1.0.2' },
19 b: { '.': '1.0.0' },
20 '[email protected]': { '.': '1.0.2' },
21 },
22 })
23
24 t.ok(overrides.children.has('a@1'), 'created child for a@1')
25 t.ok(overrides.children.has('b'), 'created child for b')
26
27 const missingEdgeRule = overrides.getEdgeRule({ name: 'a', spec: '^2.0.0' })
28 t.equal(missingEdgeRule, overrides, 'unmatched edge returns root rules')
29
30 const edgeRuleA = overrides.getEdgeRule({ name: 'a', spec: '^1.0.1' })
31 t.ok(edgeRuleA, 'found a rule for a matching edge for a@1')
32 const edgeRuleB = overrides.getEdgeRule({ name: 'b', spec: '^1.1.0' })
33 t.ok(edgeRuleB, 'found a rule for a matching edge for b')
34 const edgeRuleC = overrides.getEdgeRule({ name: 'c', spec: '^1.0.0' })
35 t.ok(edgeRuleC, 'returned a rule for matching edge for c')
36
37 const missingNodeRule = overrides.getNodeRule({ name: 'c', version: '1.0.0' })
38 t.equal(missingNodeRule, overrides, 'getNodeRule returns root for misses')
39 const matchRule = overrides.getMatchingRule({ name: 'a', version: '1.0.2' })
40 t.equal(matchRule, overrides.children.get('a@1'), 'got a match for a@1')
41 const unmatchedRule = overrides.getMatchingRule({ name: 'a', version: '2.0.0' })
42 t.equal(unmatchedRule, null, 'got null for unmatched node')
43
44 const keySpecRuleA = overrides.getNodeRule({ name: 'a', version: '1.0.1' })
45 t.ok(keySpecRuleA, 'found a rule by keySpec for a@1')
46 const keySpecRuleB = overrides.getNodeRule({ name: 'b', version: '1.1.1' })
47 t.ok(keySpecRuleB, 'found a rule by keySpec for b')
48
49 const valueRuleA = overrides.getNodeRule({ name: 'a', version: '1.0.2' })
50 t.ok(valueRuleA, 'found a rule by value for a@1')
51 const valueRuleB = overrides.getNodeRule({ name: 'b', version: '1.0.0' })
52 t.ok(valueRuleB, 'found a rule by value for b')
53
54 t.equal(edgeRuleA, keySpecRuleA, 'edge and node rules are identical for a@1')
55 t.equal(keySpecRuleA, valueRuleA, 'both node rules are identical for a@1')
56 t.equal(edgeRuleB, keySpecRuleB, 'edge and node rules are identical for b')
57 t.equal(keySpecRuleB, valueRuleB, 'both node rules are identical for b')
58 })
59
60 t.test('loads child overrides as string', async (t) => {
61 const overrides = new OverrideSet({
62 overrides: {
63 'a@1': '1.0.2',
64 b: '1.0.0',
65 '[email protected]': '1.0.2',
66 },
67 })
68
69 t.ok(overrides.children.has('a@1'), 'created child for a@1')
70 t.ok(overrides.children.has('b'), 'created child for b')
71
72 const missingEdgeRule = overrides.getEdgeRule({ name: 'a', spec: '^2.0.0' })
73 t.equal(missingEdgeRule, overrides, 'unmatched edge returns root rules')
74
75 const edgeRuleA = overrides.getEdgeRule({ name: 'a', spec: '^1.0.1' })
76 t.ok(edgeRuleA, 'found a rule for a matching edge for a@1')
77 const edgeRuleB = overrides.getEdgeRule({ name: 'b', spec: '^1.1.0' })
78 t.ok(edgeRuleB, 'found a rule for a matching edge for b')
79 const edgeRuleC = overrides.getEdgeRule({ name: 'c', spec: '^1.0.0' })
80 t.ok(edgeRuleC, 'returned a rule for matching edge for c')
81
82 const missingNodeRule = overrides.getNodeRule({ name: 'c', version: '1.0.0' })
83 t.equal(missingNodeRule, overrides, 'getNodeRule returns root for misses')
84 const matchRule = overrides.getMatchingRule({ name: 'a', version: '1.0.2' })
85 t.equal(matchRule, overrides.children.get('a@1'), 'got a match for a@1')
86 const unmatchedRule = overrides.getMatchingRule({ name: 'a', version: '2.0.0' })
87 t.equal(unmatchedRule, null, 'got null for unmatched node')
88
89 const keySpecRuleA = overrides.getNodeRule({ name: 'a', version: '1.0.1' })
90 t.ok(keySpecRuleA, 'found a rule by keySpec for a@1')
91 const keySpecRuleB = overrides.getNodeRule({ name: 'b', version: '1.1.1' })
92 t.ok(keySpecRuleB, 'found a rule by keySpec for b')
93
94 const valueRuleA = overrides.getNodeRule({ name: 'a', version: '1.0.2' })
95 t.ok(valueRuleA, 'found a rule by value for a@1')
96 const valueRuleB = overrides.getNodeRule({ name: 'b', version: '1.0.0' })
97 t.ok(valueRuleB, 'found a rule by value for b')
98
99 t.equal(edgeRuleA, keySpecRuleA, 'edge and node rules are identical for a@1')
100 t.equal(keySpecRuleA, valueRuleA, 'both node rules are identical for a@1')
101 t.equal(edgeRuleB, keySpecRuleB, 'edge and node rules are identical for b')
102 t.equal(keySpecRuleB, valueRuleB, 'both node rules are identical for b')
103 })
104
105 t.test('child rules take priority', async (t) => {
106 const overrides = new OverrideSet({
107 overrides: {
108 foo: {
109 bar: {
110 '.': '2.0.0',
111 baz: '3.0.0',
112 },
113 baz: '2.0.0',
114 },
115 bar: '1.0.0',
116 baz: '1.0.0',
117 },
118 })
119
120 const edgeRule = overrides.getEdgeRule({ name: 'foo', spec: '^1' })
121 t.equal(edgeRule.name, 'foo', 'getEdgeRule returned child rule set')
122 const ruleset = edgeRule.ruleset
123 const fooRule = ruleset.get('foo')
124 // these are both empty because the foo rule does not actually override
125 // anything directly, it only carries child rules through
126 t.equal(fooRule.keySpec, '*', 'keySpec is *')
127 t.equal(fooRule.value, '*', 'value is *')
128 const barRule = ruleset.get('bar')
129 t.equal(barRule.keySpec, '*', 'keySpec is *')
130 t.equal(barRule.value, '2.0.0', 'got the correct override for bar')
131 const bazRule = ruleset.get('baz')
132 t.equal(bazRule.keySpec, '*', 'keySpec is *')
133 t.equal(bazRule.value, '2.0.0', 'got the correct override for baz')
134
135 const childRule = edgeRule.getEdgeRule({ name: 'bar', spec: '^1.0.0' })
136 const childRuleSet = childRule.ruleset
137 const childBazRule = childRuleSet.get('baz')
138 t.equal(childBazRule.keySpec, '*', 'keySpec is *')
139 t.equal(childBazRule.value, '3.0.0', 'got the correct override for nested baz')
140 const childBarRule = childRuleSet.get('bar')
141 t.equal(childBarRule.keySpec, '*', 'keySpec is *')
142 t.equal(childBarRule.value, '2.0.0', 'got the correct override for nested bar')
143 const childFooRule = childRuleSet.get('foo')
144 t.equal(childFooRule.keySpec, '*', 'keySpec is *')
145 t.equal(childFooRule.value, '*', 'value is *')
146 })
147
148 t.test('coerces empty string to *', async (t) => {
149 const overrides = new OverrideSet({
150 overrides: {
151 foo: {
152 '.': '',
153 },
154 bar: {
155 },
156 },
157 })
158
159 const edgeRule = overrides.getEdgeRule({ name: 'foo', spec: '^1' })
160 t.equal(edgeRule.value, '*', 'empty string was replaced with *')
161
162 const barEdgeRule = overrides.getEdgeRule({ name: 'bar', spec: '^1' })
163 t.equal(barEdgeRule.value, '*', 'when rule is omitted entirely value is *')
164 })
165
166 t.test('version specs work', async (t) => {
167 const overrides = new OverrideSet({
168 overrides: {
169 foo: {
170 bar: '$bar',
171 },
172 'baz@^1.0.0': {
173 'buzz@^1.0.0': '$buzz',
174 },
175 },
176 })
177
178 const fooEdgeRule = overrides.getEdgeRule({ name: 'foo', spec: '^1.0.0' })
179 const barEdgeRule = fooEdgeRule.getEdgeRule({ name: 'bar', spec: '1.0.0' })
180 t.equal(barEdgeRule.value, '$bar', 'got a rule back')
181
182 const bazEdgeRule = overrides.getEdgeRule({ name: 'baz', spec: '^1.0.0' })
183 const buzzEdgeRule = bazEdgeRule.getEdgeRule({ name: 'buzz', spec: '1.0.0' })
184 t.equal(buzzEdgeRule.value, '$buzz', 'got a rule back')
185 })
186
187 t.test('directory specs work', async (t) => {
188 const overrides = new OverrideSet({
189 overrides: {
190 foo: {
191 bar: '$bar',
192 },
193 'baz@^1.0.0': {
194 'buzz@^1.0.0': '$buzz',
195 },
196 },
197 })
198
199 const fooEdgeRule = overrides.getEdgeRule({ name: 'foo', spec: '^1.0.0' })
200 const barEdgeRule = fooEdgeRule.getEdgeRule({ name: 'bar', spec: 'file:../bar' })
201 t.equal(barEdgeRule.value, '$bar', 'got a rule back')
202
203 const bazEdgeRule = overrides.getEdgeRule({ name: 'baz', spec: '^1.0.0' })
204 const buzzEdgeRule = bazEdgeRule.getEdgeRule({ name: 'buzz', spec: 'file:../buzz' })
205 t.equal(buzzEdgeRule.value, '$buzz', 'got a rule back')
206 })
207
208 t.test('file specs work', async (t) => {
209 const overrides = new OverrideSet({
210 overrides: {
211 foo: {
212 bar: '$bar',
213 },
214 'baz@^1.0.0': {
215 'buzz@^1.0.0': '$buzz',
216 },
217 },
218 })
219
220 const fooEdgeRule = overrides.getEdgeRule({ name: 'foo', spec: '^1.0.0' })
221 const barEdgeRule = fooEdgeRule.getEdgeRule({ name: 'bar', spec: 'file:../bar.tgz' })
222 t.equal(barEdgeRule.value, '$bar', 'got a rule back')
223
224 const bazEdgeRule = overrides.getEdgeRule({ name: 'baz', spec: '^1.0.0' })
225 const buzzEdgeRule = bazEdgeRule.getEdgeRule({ name: 'buzz', spec: 'file:../buzz.tgz' })
226 t.equal(buzzEdgeRule.value, '$buzz', 'got a rule back')
227 })
228
229 t.test('alias specs work', async (t) => {
230 const overrides = new OverrideSet({
231 overrides: {
232 foo: {
233 bar: '$bar',
234 },
235 'baz@^1.0.0': {
236 'buzz@^1.0.0': '$buzz',
237 },
238 },
239 })
240
241 const fooEdgeRule = overrides.getEdgeRule({ name: 'foo', spec: '^1.0.0' })
242 const barEdgeRule = fooEdgeRule.getEdgeRule({ name: 'bar', spec: 'npm:bar2@^1.0.0' })
243 t.equal(barEdgeRule.value, '$bar', 'got a rule back')
244
245 const bazEdgeRule = overrides.getEdgeRule({ name: 'baz', spec: '^1.0.0' })
246 const buzzEdgeRule = bazEdgeRule.getEdgeRule({ name: 'buzz', spec: 'npm:buzz2@^1.0.0' })
247 t.equal(buzzEdgeRule.value, '$buzz', 'got a rule back')
248 })
249
250 t.test('git specs work', async (t) => {
251 const overrides = new OverrideSet({
252 overrides: {
253 foo: {
254 bar: '$bar',
255 },
256 'baz@^1.0.0': {
257 'buzz@^1.0.0': '$buzz',
258 },
259 },
260 })
261
262 const fooEdgeRule = overrides.getEdgeRule({ name: 'foo', spec: '^1.0.0' })
263 const barEdgeRule = fooEdgeRule.getEdgeRule({ name: 'bar', spec: 'github:foo/bar' })
264 t.equal(barEdgeRule.value, '$bar', 'got a rule back')
265
266 const bazEdgeRule = overrides.getEdgeRule({ name: 'baz', spec: '^1.0.0' })
267 const buzzEdgeRule = bazEdgeRule.getEdgeRule({ name: 'buzz', spec: 'github:baz/buzz#semver:^1.0.0' })
268 t.equal(buzzEdgeRule.value, '$buzz', 'got a rule back')
269
270 const outOfRangeRule = bazEdgeRule.getEdgeRule({ name: 'buzz', spec: 'github:baz/buzz#semver:^2.0.0' })
271 t.equal(outOfRangeRule.name, 'baz', 'no match - returned parent')
272 })
273
274 t.test('isequal and findspecificoverrideset tests', async (t) => {
275 const overrides1 = new OverrideSet({
276 overrides: {
277 foo: {
278 bar: {
279 '.': '2.0.0',
280 baz: '3.0.0',
281 },
282 baz: '2.0.0',
283 },
284 bar: '1.0.0',
285 baz: '1.0.0',
286 },
287 })
288 const overrides2 = new OverrideSet({
289 overrides: {
290 foo: {
291 bar: {
292 '.': '2.0.0',
293 baz: '3.0.0',
294 },
295 baz: '2.0.0',
296 },
297 bar: '1.0.0',
298 baz: '1.0.0',
299 },
300 })
301 const overrides3 = new OverrideSet({
302 overrides: {
303 foo: {
304 bar: {
305 '.': '2.0.0',
306 baz: '3.1.0',
307 },
308 baz: '2.0.0',
309 },
310 bar: '1.0.0',
311 baz: '1.0.0',
312 },
313 })
314 const overrides4 = new OverrideSet({
315 overrides: {
316 foo: {
317 bar: {
318 '.': '2.0.0',
319 },
320 baz: '2.0.0',
321 },
322 bar: '1.0.0',
323 baz: '1.0.0',
324 },
325 })
326 const overrides5 = new OverrideSet({
327 overrides: {
328 foo: {
329 bar: {
330 '.': '2.0.0',
331 },
332 bat: '2.0.0',
333 },
334 bar: '1.0.0',
335 baz: '1.0.0',
336 },
337 })
338 const overrides6 = new OverrideSet({
339 overrides: {
340 bar: {
341 '.': '2.0.0',
342 },
343 bat: '2.0.0',
344 },
345 })
346 overrides6.parent = overrides5
347 const overrides7 = new OverrideSet({
348 overrides: {
349 bat: '2.0.0',
350 },
351 })
352 const overrides8 = new OverrideSet({
353 overrides: {
354 bat: '1.2.0',
355 },
356 })
357 const overrides9 = new OverrideSet({
358 overrides: {
359 '[email protected]': '1.2.0',
360 },
361 })
362
363 t.ok(overrides1.isEqual(overrides1), 'override set is equal to itself')
364 t.ok(overrides1.isEqual(overrides2), 'two identical override sets are equal')
365 t.ok(!overrides1.isEqual(overrides3), 'two different override sets are not equal')
366 t.ok(!overrides2.isEqual(overrides3), 'two different override sets are not equal')
367 t.ok(!overrides3.isEqual(overrides1), 'two different override sets are not equal')
368 t.ok(!overrides3.isEqual(overrides2), 'two different override sets are not equal')
369 t.ok(!overrides4.isEqual(overrides1), 'two different override sets are not equal')
370 t.ok(!overrides4.isEqual(overrides2), 'two different override sets are not equal')
371 t.ok(!overrides4.isEqual(overrides3), 'two different override sets are not equal')
372 t.ok(!overrides4.isEqual(overrides5), 'two override sets that differ only by package name are not equal')
373 t.ok(!overrides5.isEqual(overrides4), 'two override sets that differ only by package name are not equal')
374 t.equal(OverrideSet.findSpecificOverrideSet(overrides5, overrides5), overrides5, 'find more specific override set when the sets are identical')
375 t.equal(OverrideSet.findSpecificOverrideSet(overrides5, overrides6), overrides6, "find more specific override set when it's the second")
376 t.equal(OverrideSet.findSpecificOverrideSet(overrides6, overrides5), overrides6, "find more specific override set when it's the first")
377 t.ok(!OverrideSet.doOverrideSetsConflict(overrides1, overrides2), 'override sets are equal')
378 t.ok(!OverrideSet.doOverrideSetsConflict(overrides5, overrides5), 'override sets are the same object')
379 t.ok(!OverrideSet.doOverrideSetsConflict(overrides5, overrides6), 'one override set is the specific version of the other')
380 t.ok(!OverrideSet.doOverrideSetsConflict(overrides6, overrides5), 'one override set is the specific version of the other')
381 // With semantic conflict detection, overrides5 and overrides7 don't conflict because
382 // they have the same value for 'bat' (2.0.0). Structurally they're incomparable,
383 // but semantically they're compatible.
384 t.ok(!OverrideSet.doOverrideSetsConflict(overrides5, overrides7), 'structurally incomparable but semantically compatible')
385 t.ok(!OverrideSet.doOverrideSetsConflict(overrides7, overrides5), 'structurally incomparable but semantically compatible')
386 t.ok(!overrides7.isEqual(overrides8), 'two override sets that differ in the version are not equal')
387 t.ok(!overrides8.isEqual(overrides9), 'two override sets that differ in the range are not equal')
388 t.ok(!overrides7.isEqual(overrides9), 'two override sets that differ in both version and range are not equal')
389 // overrides7 (bat: 2.0.0) and overrides8 (bat: 1.2.0) have conflicting versions for the same package
390 t.ok(OverrideSet.doOverrideSetsConflict(overrides7, overrides8), 'override sets have conflicting versions for bat')
391 // overrides7 (bat: 2.0.0) and overrides9 ([email protected]: 1.2.0) don't directly conflict because
392 // overrides9 only applies to [email protected], not [email protected]
393 t.ok(!OverrideSet.doOverrideSetsConflict(overrides7, overrides9), 'override sets apply to different version ranges')
394 // overrides8 (bat: 1.2.0) and overrides9 ([email protected]: 1.2.0) have same target version
395 t.ok(!OverrideSet.doOverrideSetsConflict(overrides8, overrides9), 'override sets have compatible target versions')
396 })
397
398 t.test('semantic conflict detection (haveConflictingRules)', async (t) => {
399 t.test('no conflict when packages are different', async (t) => {
400 const overrides1 = new OverrideSet({
401 overrides: {
402 foo: '1.0.0',
403 },
404 })
405 const overrides2 = new OverrideSet({
406 overrides: {
407 bar: '1.0.0',
408 },
409 })
410 t.ok(!OverrideSet.haveConflictingRules(overrides1, overrides2), 'different packages should not conflict')
411 })
412
413 t.test('no conflict when version ranges intersect', async (t) => {
414 const overrides1 = new OverrideSet({
415 overrides: {
416 lodash: '^4.0.0',
417 },
418 })
419 const overrides2 = new OverrideSet({
420 overrides: {
421 lodash: '4.17.0',
422 },
423 })
424 t.ok(!OverrideSet.haveConflictingRules(overrides1, overrides2), 'intersecting ranges should not conflict')
425 })
426
427 t.test('conflict when version ranges do not intersect', async (t) => {
428 const overrides1 = new OverrideSet({
429 overrides: {
430 lodash: '1.x',
431 },
432 })
433 const overrides2 = new OverrideSet({
434 overrides: {
435 lodash: '4.x',
436 },
437 })
438 t.ok(OverrideSet.haveConflictingRules(overrides1, overrides2), 'non-intersecting ranges should conflict')
439 })
440
441 t.test('no conflict when using reference overrides', async (t) => {
442 const overrides1 = new OverrideSet({
443 overrides: {
444 lodash: '$ref1',
445 },
446 })
447 const overrides2 = new OverrideSet({
448 overrides: {
449 lodash: '$ref2',
450 },
451 })
452 t.ok(!OverrideSet.haveConflictingRules(overrides1, overrides2), 'reference overrides should not conflict')
453 })
454
455 t.test('no conflict when one is a reference override', async (t) => {
456 const overrides1 = new OverrideSet({
457 overrides: {
458 lodash: '$ref1',
459 },
460 })
461 const overrides2 = new OverrideSet({
462 overrides: {
463 lodash: '4.17.21',
464 },
465 })
466 t.ok(!OverrideSet.haveConflictingRules(overrides1, overrides2), 'reference override with version should not conflict')
467 })
468
469 t.test('no conflict when rules are equal', async (t) => {
470 const overrides1 = new OverrideSet({
471 overrides: {
472 lodash: '4.17.21',
473 },
474 })
475 const overrides2 = new OverrideSet({
476 overrides: {
477 lodash: '4.17.21',
478 },
479 })
480 t.ok(!OverrideSet.haveConflictingRules(overrides1, overrides2), 'equal rules should not conflict')
481 })
482
483 t.test('handles non-semver spec types gracefully', async (t) => {
484 const overrides1 = new OverrideSet({
485 overrides: {
486 foo: 'github:user/repo',
487 },
488 })
489 const overrides2 = new OverrideSet({
490 overrides: {
491 foo: 'file:./local',
492 },
493 })
494 // Non-semver types should not be considered conflicting
495 t.ok(!OverrideSet.haveConflictingRules(overrides1, overrides2), 'non-semver specs should not conflict')
496 })
497
498 t.test('regression test for issue #8688 - Vaadin case', async (t) => {
499 const overridesComponents = new OverrideSet({
500 overrides: {
501 '@vaadin/react-components': '24.9.2',
502 },
503 })
504 const overridesComponentsPro = new OverrideSet({
505 overrides: {
506 '@vaadin/react-components-pro': '24.9.2',
507 },
508 })
509 t.ok(!OverrideSet.doOverrideSetsConflict(overridesComponents, overridesComponentsPro), 'Vaadin components should not conflict')
510 })
511 })
512 })
513
514 t.test('findSpecificOverrideSet returns common ancestor for compatible siblings', async (t) => {
515 // Regression test for https://github.com/npm/cli/issues/9109
516 // When two top-level overrides (e.g. react + react-dom) share a transitive dep (e.g. loose-envify), the dep's node gets override sets from both siblings. findSpecificOverrideSet must return their common ancestor instead of undefined.
517 const root = new OverrideSet({
518 overrides: {
519 react: '18.3.1',
520 'react-dom': '18.3.1',
521 },
522 })
523
524 const reactChild = root.children.get('react')
525 const reactDomChild = root.children.get('react-dom')
526
527 t.ok(reactChild, 'react child exists')
528 t.ok(reactDomChild, 'react-dom child exists')
529
530 // These are siblings - neither is an ancestor of the other
531 const result = OverrideSet.findSpecificOverrideSet(reactChild, reactDomChild)
532 t.ok(result, 'findSpecificOverrideSet should not return undefined for compatible siblings')
533 t.ok(result.isEqual(root), 'should return the common ancestor (root)')
534
535 const reverse = OverrideSet.findSpecificOverrideSet(reactDomChild, reactChild)
536 t.ok(reverse, 'reverse order should also return a result')
537 t.ok(reverse.isEqual(root), 'reverse order should also return the root')
538 })
539
540 t.test('findCommonAncestor', async (t) => {
541 const root = new OverrideSet({
542 overrides: {
543 foo: '1.0.0',
544 bar: '2.0.0',
545 },
546 })
547
548 const fooChild = root.children.get('foo')
549 const barChild = root.children.get('bar')
550
551 const ancestor = OverrideSet.findCommonAncestor(fooChild, barChild)
552 t.ok(ancestor, 'should find a common ancestor')
553 t.ok(ancestor.isEqual(root), 'common ancestor should be the root')
554
555 // Two unrelated roots have no common ancestor
556 const other = new OverrideSet({ overrides: { baz: '3.0.0' } })
557 const noAncestor = OverrideSet.findCommonAncestor(fooChild, other)
558 t.equal(noAncestor, null, 'unrelated sets have no common ancestor')
559 })
560
561 t.test('findSpecificOverrideSet returns undefined for truly conflicting siblings', async (t) => {
562 // Siblings with conflicting rules should still return undefined
563 const root = new OverrideSet({
564 overrides: {
565 foo: {
566 '.': '1.0.0',
567 shared: '1.0.0',
568 },
569 bar: {
570 '.': '2.0.0',
571 shared: '99.0.0',
572 },
573 },
574 })
575
576 const fooChild = root.children.get('foo')
577 const barChild = root.children.get('bar')
578
579 t.ok(fooChild, 'foo child exists')
580 t.ok(barChild, 'bar child exists')
581
582 const result = OverrideSet.findSpecificOverrideSet(fooChild, barChild)
583 t.equal(result, undefined, 'truly conflicting siblings should return undefined')
584 })
585
586 t.test('coverage for isEqual edge cases', async t => {
587 t.test('isEqual with null/undefined other', async t => {
588 const overrides = new OverrideSet({ overrides: { foo: '1.0.0' } })
589 t.ok(!overrides.isEqual(null), 'override set is not equal to null')
590 t.ok(!overrides.isEqual(undefined), 'override set is not equal to undefined')
591 })
592
593 t.test('isEqual when parent != null', async t => {
594 // Both parents have the SAME config -> parent.isEqual(...) will return TRUE
595 const parentA = new OverrideSet({ overrides: { foo: '1.0.0' } })
596 const parentB = new OverrideSet({ overrides: { foo: '1.0.0' } })
597
598 // Child override sets with the same parent config => should be equal
599 const childA = new OverrideSet({
600 overrides: { bar: '2.0.0' },
601 key: 'bar',
602 parent: parentA,
603 })
604 const childB = new OverrideSet({
605 overrides: { bar: '2.0.0' },
606 key: 'bar',
607 parent: parentB,
608 })
609
610 // This specifically covers the code path where parent != null
611 // AND parent.isEqual(...) returns true
612 t.ok(childA.isEqual(childB), 'two children with equivalent parents are equal')
613
614 // Different parent configs -> parent.isEqual(...) will return FALSE
615 const parentC = new OverrideSet({ overrides: { foo: '1.0.0' } })
616 const parentD = new OverrideSet({ overrides: { foo: '1.0.1' } })
617
618 const childC = new OverrideSet({
619 overrides: { bar: '2.0.0' },
620 key: 'bar',
621 parent: parentC,
622 })
623 const childD = new OverrideSet({
624 overrides: { bar: '2.0.0' },
625 key: 'bar',
626 parent: parentD,
627 })
628
629 // This specifically covers the code path where parent != null
630 // AND parent.isEqual(...) returns false
631 t.notOk(childC.isEqual(childD), 'two children with different parents are not equal')
632 })
633 })