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.

77 lines
2.0 KiB

  1. 'use strict'
  2. const fs = require('fs-extra')
  3. const colors = require('colors')
  4. expect.extend({
  5. /**
  6. * Expect ESLint results to have no errors
  7. * @param {*} received ESLint results
  8. * @param {*} argument Arguments
  9. * @returns {object} Matcher result
  10. */
  11. toESLint (received, argument) {
  12. if (received && received.errorCount > 0) {
  13. let errorMsgBuf = []
  14. for (let i = 0; i < received.results.length; i++) {
  15. const result = received.results[i]
  16. if (result.errorCount <= 0) {
  17. continue
  18. }
  19. for (let x = 0; x < result.messages.length; x++) {
  20. const m = result.messages[x]
  21. errorMsgBuf.push(colors.grey(`└── ${result.filePath}\t${m.line}:${m.column}\t${m.message}`))
  22. }
  23. }
  24. if (errorMsgBuf.length > 0) {
  25. return {
  26. message: () => (errorMsgBuf.join(`\n`)),
  27. pass: false
  28. }
  29. }
  30. }
  31. return {
  32. pass: true
  33. }
  34. },
  35. /**
  36. * Expect PugLint results to have no errors
  37. * @param {*} received PugLint results
  38. * @param {*} argument Arguments
  39. * @returns {object} Matcher result
  40. */
  41. toPugLint (received, argument) {
  42. if (received && received.length > 0) {
  43. let errorMsgBuf = []
  44. for (let i = 0; i < received.length; i++) {
  45. errorMsgBuf.push(colors.grey(`└── ${received[i].message}`))
  46. }
  47. return {
  48. message: () => (errorMsgBuf.join(`\n`)),
  49. pass: false
  50. }
  51. }
  52. return {
  53. pass: true
  54. }
  55. }
  56. })
  57. describe('Code Linting', () => {
  58. it('should pass ESLint validation', () => {
  59. const CLIEngine = require('eslint').CLIEngine
  60. const cli = new CLIEngine()
  61. let report = cli.executeOnFiles(['**/*.js'])
  62. expect(report).toESLint()
  63. })
  64. it('should pass PugLint validation', () => {
  65. const PugLint = require('pug-lint')
  66. const lint = new PugLint()
  67. const pugConfig = fs.readJsonSync('.pug-lintrc.json')
  68. lint.configure(pugConfig)
  69. let report = lint.checkPath('./views')
  70. expect(report).toPugLint()
  71. })
  72. })