Skip to content

Commit

Permalink
test: test for license checking with json output
Browse files Browse the repository at this point in the history
  • Loading branch information
bnb authored Jun 22, 2021
1 parent 1432cca commit 3075d72
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions test/lib/audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,54 @@ t.test('report endpoint error', t => {
t.end()
})

t.test('licenses', t => {
const Audit = require('../../lib/audit.js')
t.test('run audit with license type and output json', t => {
const prefix = t.testdir({
node_modules: {
a: {
'package.json': JSON.stringify({
name: 'a',
version: '1.0.0',
license: 'MIT',
}),
},
b: {
'package.json': JSON.stringify({
name: 'b',
version: '1.0.0',
license: 'ISC',
}),
},
},
})

const OUTPUT = []
const npm = mockNpm({
prefix: prefix,
command: 'audit',
config: {
"audit-type": "license",
json: true
},
output: (...msg) => {
OUTPUT.push(msg)
},
})

const audit = new Audit(npm)

audit.exec([], () => {
t.strictSame(JSON.parse(OUTPUT), {
a: { name: 'a', version: '1.0.0', approved: true, license: 'MIT' },
b: { name: 'b', version: '1.0.0', approved: false, license: 'ISC' }
})
t.end()
})
})
t.end()
})

t.test('completion', t => {
const Audit = require('../../lib/audit.js')
const audit = new Audit({})
Expand Down

0 comments on commit 3075d72

Please sign in to comment.