Skip to content

Commit

Permalink
fix: added count on reify-output
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ruyadorno authored and nlf committed Sep 29, 2020
1 parent 76949c1 commit 3cc88d6
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/utils/reify-output.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const reifyOutput = arb => {
summary.removed++
break
case 'ADD':
summary.added++
actualTree.inventory.has(d.ideal) && summary.added++
break
case 'CHANGE':
summary.changed++
Expand Down
10 changes: 10 additions & 0 deletions tap-snapshots/test-lib-utils-reify-output.js-TAP.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@
* Make sure to inspect the output below. Do not ignore changes!
*/
'use strict'
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`] = `
added 1 package in {TIME}
`

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`] = `
up to date in {TIME}
`

exports[`test/lib/utils/reify-output.js TAP packages changed message > {"added":0,"removed":0,"changed":0,"audited":0,"json":false} 1`] = `
up to date in {TIME}
Expand Down
47 changes: 46 additions & 1 deletion test/lib/utils/reify-output.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ t.test('packages changed message', t => {
settings.json = json
npmock.command = command
const mock = {
actualTree: { inventory: { size: audited }, children: [] },
actualTree: { inventory: { size: audited, has: () => true }, children: [] },
auditReport: audited ? {
toJSON: () => mock.auditReport,
vulnerabilities: {},
Expand Down Expand Up @@ -300,3 +300,48 @@ t.test('packages changed message', t => {

t.end()
})

t.test('added packages should be looked up within returned tree', t => {
t.test('has added pkg in inventory', t => {
t.plan(1)
const reifyOutput = getReifyOutput(
out => t.matchSnapshot(out)
)

reifyOutput({
actualTree: {
name: 'foo',
inventory: {
has: () => true
}
},
diff: {
children: [
{ action: 'ADD', ideal: { name: 'baz' } }
]
}
})
})

t.test('missing added pkg in inventory', t => {
t.plan(1)
const reifyOutput = getReifyOutput(
out => t.matchSnapshot(out)
)

reifyOutput({
actualTree: {
name: 'foo',
inventory: {
has: () => false
}
},
diff: {
children: [
{ action: 'ADD', ideal: { name: 'baz' } }
]
}
})
})
t.end()
})

0 comments on commit 3cc88d6

Please sign in to comment.