human-readable-logs.test.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import { expect } from 'chai'
  2. import HumanReadableLogs from '../../../../frontend/js/ide/human-readable-logs/HumanReadableLogs'
  3. import { readFile } from 'fs/promises'
  4. import { join } from 'path'
  5. import { some } from 'lodash'
  6. const fixturePath = '../../helpers/fixtures/logs/'
  7. async function parse(fixtureName) {
  8. const filePath = join(__dirname, fixturePath, fixtureName)
  9. const data = await readFile(filePath, 'utf-8', 'r')
  10. return HumanReadableLogs.parse(data)
  11. }
  12. describe('HumanReadableLogs', function () {
  13. describe('Undefined commands', function () {
  14. before(async function () {
  15. this.errors = (await parse('undefined-control-sequence.log')).errors
  16. })
  17. describe('For unknown commands', function () {
  18. it('Identifies command at beginning of line', function () {
  19. expect(
  20. some(this.errors, {
  21. line: 3,
  22. level: 'error',
  23. message: 'Undefined control sequence.',
  24. })
  25. ).to.be.true
  26. })
  27. it('Identifies command at end of line', function () {
  28. expect(
  29. some(this.errors, {
  30. line: 4,
  31. level: 'error',
  32. message: 'Undefined control sequence.',
  33. })
  34. ).to.be.true
  35. })
  36. it('Identifies command inside argument', function () {
  37. expect(
  38. some(this.errors, {
  39. line: 5,
  40. level: 'error',
  41. message: 'Undefined control sequence.',
  42. })
  43. ).to.be.true
  44. })
  45. })
  46. describe('For known commands', function () {
  47. it('Identifies command at beginning of line', function () {
  48. expect(
  49. some(this.errors, {
  50. line: 6,
  51. level: 'error',
  52. message: 'Is \\usepackage{url} missing?',
  53. })
  54. ).to.be.true
  55. })
  56. it('Identifies command at end of line', function () {
  57. expect(
  58. some(this.errors, {
  59. line: 7,
  60. level: 'error',
  61. message: 'Is \\usepackage{amsmath} missing?',
  62. })
  63. ).to.be.true
  64. })
  65. it('Identifies command inside argument', function () {
  66. expect(
  67. some(this.errors, {
  68. line: 8,
  69. level: 'error',
  70. message: 'Is \\usepackage{array} missing?',
  71. })
  72. ).to.be.true
  73. })
  74. })
  75. })
  76. })