overleaf/services/web/test/frontend/ide/human-readable-logs/human-readable-logs.test.js
Mathias Jakobsen 1a6f3fc256 Merge pull request #16253 from overleaf/mj-human-readable-logs-fixes
[web] Fix incorrect error log parsing and imprecise package recommendations

GitOrigin-RevId: a0b9c6c51ebf680bb77be88167ab6d35eaa8fa70
2023-12-19 09:04:07 +00:00

81 lines
2.3 KiB
JavaScript

import { expect } from 'chai'
import HumanReadableLogs from '../../../../frontend/js/ide/human-readable-logs/HumanReadableLogs'
import { readFile } from 'fs/promises'
import { join } from 'path'
import { some } from 'lodash'
const fixturePath = '../../helpers/fixtures/logs/'
async function parse(fixtureName) {
const filePath = join(__dirname, fixturePath, fixtureName)
const data = await readFile(filePath, 'utf-8', 'r')
return HumanReadableLogs.parse(data)
}
describe('HumanReadableLogs', function () {
describe('Undefined commands', function () {
before(async function () {
this.errors = (await parse('undefined-control-sequence.log')).errors
})
describe('For unknown commands', function () {
it('Identifies command at beginning of line', function () {
expect(
some(this.errors, {
line: 3,
level: 'error',
message: 'Undefined control sequence.',
})
).to.be.true
})
it('Identifies command at end of line', function () {
expect(
some(this.errors, {
line: 4,
level: 'error',
message: 'Undefined control sequence.',
})
).to.be.true
})
it('Identifies command inside argument', function () {
expect(
some(this.errors, {
line: 5,
level: 'error',
message: 'Undefined control sequence.',
})
).to.be.true
})
})
describe('For known commands', function () {
it('Identifies command at beginning of line', function () {
expect(
some(this.errors, {
line: 6,
level: 'error',
message: 'Is \\usepackage{url} missing?',
})
).to.be.true
})
it('Identifies command at end of line', function () {
expect(
some(this.errors, {
line: 7,
level: 'error',
message: 'Is \\usepackage{amsmath} missing?',
})
).to.be.true
})
it('Identifies command inside argument', function () {
expect(
some(this.errors, {
line: 8,
level: 'error',
message: 'Is \\usepackage{array} missing?',
})
).to.be.true
})
})
})
})