Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: added count on reify-output #1858

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
})