Skip to content

Commit 2715220

Browse files
ruyadornonlf
authored andcommitted
fix: added count on reify-output
The added count on lib/utils/reify-output.js only looks up resulting keys from arb.diff and does not take into account the fact that some of these pkgs signaled as diff=ADD might in fact not have been installed, most common scenario are optional deps that could have failed their install in a given system or opt-out from configs. This fixes the counting number by looking up at arb.inventory and confirming it has the node that has been marked as added on diff result. Fix: #1813 PR-URL: #1858 Credit: @ruyadorno Close: #1858 Reviewed-by: @nlf
1 parent 90550b2 commit 2715220

3 files changed

Lines changed: 57 additions & 2 deletions

File tree

lib/utils/reify-output.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const reifyOutput = arb => {
4343
summary.removed++
4444
break
4545
case 'ADD':
46-
summary.added++
46+
actualTree.inventory.has(d.ideal) && summary.added++
4747
break
4848
case 'CHANGE':
4949
summary.changed++

tap-snapshots/test-lib-utils-reify-output.js-TAP.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@
55
* Make sure to inspect the output below. Do not ignore changes!
66
*/
77
'use strict'
8+
exports[`test/lib/utils/reify-output.js TAP added packages should be looked up within returned tree has added pkg in inventory > must match snapshot 1`] = `
9+
10+
added 1 package in {TIME}
11+
`
12+
13+
exports[`test/lib/utils/reify-output.js TAP added packages should be looked up within returned tree missing added pkg in inventory > must match snapshot 1`] = `
14+
15+
up to date in {TIME}
16+
`
17+
818
exports[`test/lib/utils/reify-output.js TAP packages changed message > {"added":0,"removed":0,"changed":0,"audited":0,"json":false} 1`] = `
919
1020
up to date in {TIME}

test/lib/utils/reify-output.js

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ t.test('packages changed message', t => {
238238
settings.json = json
239239
npmock.command = command
240240
const mock = {
241-
actualTree: { inventory: { size: audited }, children: [] },
241+
actualTree: { inventory: { size: audited, has: () => true }, children: [] },
242242
auditReport: audited ? {
243243
toJSON: () => mock.auditReport,
244244
vulnerabilities: {},
@@ -300,3 +300,48 @@ t.test('packages changed message', t => {
300300

301301
t.end()
302302
})
303+
304+
t.test('added packages should be looked up within returned tree', t => {
305+
t.test('has added pkg in inventory', t => {
306+
t.plan(1)
307+
const reifyOutput = getReifyOutput(
308+
out => t.matchSnapshot(out)
309+
)
310+
311+
reifyOutput({
312+
actualTree: {
313+
name: 'foo',
314+
inventory: {
315+
has: () => true
316+
}
317+
},
318+
diff: {
319+
children: [
320+
{ action: 'ADD', ideal: { name: 'baz' } }
321+
]
322+
}
323+
})
324+
})
325+
326+
t.test('missing added pkg in inventory', t => {
327+
t.plan(1)
328+
const reifyOutput = getReifyOutput(
329+
out => t.matchSnapshot(out)
330+
)
331+
332+
reifyOutput({
333+
actualTree: {
334+
name: 'foo',
335+
inventory: {
336+
has: () => false
337+
}
338+
},
339+
diff: {
340+
children: [
341+
{ action: 'ADD', ideal: { name: 'baz' } }
342+
]
343+
}
344+
})
345+
})
346+
t.end()
347+
})

0 commit comments

Comments
 (0)