mirror of https://github.com/requarks/wiki
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.0 KiB
40 lines
1.0 KiB
'use strict'
|
|
|
|
const colors = require('colors')
|
|
|
|
expect.extend({
|
|
/**
|
|
* Expect Snyk results to have no errors
|
|
* @param {*} received Snyk results
|
|
* @param {*} argument Arguments
|
|
* @returns {object} Matcher result
|
|
*/
|
|
toPassSnyk (received, argument) {
|
|
if (received && received.ok === false) {
|
|
let errorMsgBuf = []
|
|
for (let i = 0; i < received.vulnerabilities.length; i++) {
|
|
const result = received.vulnerabilities[i]
|
|
let vulnPath = result.from.slice(1).join(' > ')
|
|
errorMsgBuf.push(colors.red(`└──[${result.severity}] ${result.packageName}\t${result.title}`))
|
|
errorMsgBuf.push(colors.grey(`\t${vulnPath}`))
|
|
}
|
|
return {
|
|
message: () => (errorMsgBuf.join(`\n`)),
|
|
pass: false
|
|
}
|
|
}
|
|
return {
|
|
pass: true
|
|
}
|
|
}
|
|
})
|
|
|
|
describe('Security', () => {
|
|
it('should pass Snyk test', () => {
|
|
const snyk = require('snyk').test
|
|
return snyk('./').then(report => {
|
|
expect(report).toPassSnyk()
|
|
})
|
|
}, 30000)
|
|
})
|