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(exit-code): account for null default #46

Merged
merged 1 commit into from
May 26, 2021
Merged
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
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