Skip to content

Commit

Permalink
fix: throws TypeError on missing audit data
Browse files Browse the repository at this point in the history
PR-URL: #43
Credit: @ruyadorno
Close: #43
Reviewed-by: @isaacs
  • Loading branch information
ruyadorno authored and isaacs committed May 11, 2020
1 parent f3aad5b commit 4b97792
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ module.exports = Object.assign((data, options = {}) => {
auditLevel = 'low'
} = options

if (!data)
throw Object.assign(
new TypeError('ENOAUDITDATA'),
{
code: 'ENOAUDITDATA',
message: 'missing audit data'
}
)

if (typeof data.toJSON === 'function')
data = data.toJSON()

Expand Down
9 changes: 9 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,12 @@ t.test('install is default reporter', async t => {
indent: 2,
}))
})

t.test('falsy audit data', t => {
t.throws(
() => nar(),
{ code: 'ENOAUDITDATA' },
'should throw a missing audit data error'
)
t.end()
})

0 comments on commit 4b97792

Please sign in to comment.