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.

39 lines
1.0 KiB

  1. 'use strict'
  2. const colors = require('colors')
  3. expect.extend({
  4. /**
  5. * Expect Snyk results to have no errors
  6. * @param {*} received Snyk results
  7. * @param {*} argument Arguments
  8. * @returns {object} Matcher result
  9. */
  10. toPassSnyk (received, argument) {
  11. if (received && received.ok === false) {
  12. let errorMsgBuf = []
  13. for (let i = 0; i < received.vulnerabilities.length; i++) {
  14. const result = received.vulnerabilities[i]
  15. let vulnPath = result.from.slice(1).join(' > ')
  16. errorMsgBuf.push(colors.red(`└──[${result.severity}] ${result.packageName}\t${result.title}`))
  17. errorMsgBuf.push(colors.grey(`\t${vulnPath}`))
  18. }
  19. return {
  20. message: () => (errorMsgBuf.join(`\n`)),
  21. pass: false
  22. }
  23. }
  24. return {
  25. pass: true
  26. }
  27. }
  28. })
  29. describe('Security', () => {
  30. it('should pass Snyk test', () => {
  31. const snyk = require('snyk').test
  32. return snyk('./').then(report => {
  33. expect(report).toPassSnyk()
  34. })
  35. }, 30000)
  36. })