Skip to content

Commit

Permalink
fix(exit-code): account for null default (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
wraithgar authored May 26, 2021
1 parent d516876 commit dff5941
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ module.exports = Object.assign((data, options = {}) => {
color = true,
unicode = true,
indent = 2,
auditLevel = 'low'
} = options

// CLI defaults this to `null` so the defaulting method above doesn't work
const auditLevel = options.auditLevel || 'low'

if (!data)
throw Object.assign(
new TypeError('ENOAUDITDATA'),
Expand Down
21 changes: 21 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ t.equal(nar.reporters.json, require('../lib/reporters/json.js'))
t.equal(nar.reporters.quiet, require('../lib/reporters/quiet.js'))

const metadata = { vulnerabilities: {} }
const highMeta = {
vulnerabilities: {
high: 99,
low: 0,
critical: 0,
total: 99
}
}

const fake = { reporter: 'fake' }
t.strictSame(nar({ foo: 'bar', metadata }, fake), {
exitCode: 0,
Expand All @@ -34,6 +43,18 @@ t.strictSame(nar({ foo: 'bar', toJSON: () => ({ bar: 'baz', metadata }) }, fake)
}
}, 'should call toJSON')

t.strictSame(nar({ foo: 'bar', auditLevel: null, metadata: highMeta }, fake), {
exitCode: 1,
report: {
data: { foo: 'bar', auditLevel: null, metadata: highMeta },
options: {
color: true,
unicode: true,
indent: 2,
},
}
}, 'null auditLevel')

t.test('install is default reporter', async t => {
const fix = fixture('one-vuln')
t.strictSame(nar(fix).report, nar.reporters.install(fix, {
Expand Down

0 comments on commit dff5941

Please sign in to comment.