-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPrettierParser.test.js
More file actions
54 lines (44 loc) · 1.9 KB
/
Copy pathPrettierParser.test.js
File metadata and controls
54 lines (44 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { describe, it } from "node:test";
import assert from "node:assert/strict";
import { PrettierParser } from "./PrettierParser.js";
const SAMPLE_FAILURE_LOG = `Checking formatting...
[warn] src/app.js
[warn] src/components/Button.tsx
[warn] Code style issues found in the above file(s). Forgot to run Prettier?`;
const SAMPLE_ERROR_LOG = `Checking formatting...
[error] src/app.js: SyntaxError: Unexpected token (1:7)
[warn] Code style issues found in the above file(s). Forgot to run Prettier?`;
describe("PrettierParser", () => {
it("keeps auto-pattern path detection synchronized", () => {
const parser = new PrettierParser();
const filePath = "application/humanize-prettier-report.log";
assert.ok(parser.matchesAutoPatterns(filePath));
assert.ok(parser.canParse(filePath, SAMPLE_FAILURE_LOG));
});
it("identifies prettier check logs", () => {
const parser = new PrettierParser();
assert.ok(parser.canParse("prettier-check.log", SAMPLE_FAILURE_LOG));
assert.ok(parser.canParse("logs/output.txt", SAMPLE_FAILURE_LOG));
});
it("parses files reported by prettier", () => {
const parser = new PrettierParser();
const reportData = parser.parse(SAMPLE_FAILURE_LOG, "prettier-check.log");
assert.strictEqual(reportData.lintIssues.length, 2);
assert.strictEqual(reportData.lintIssues[0].file, "src/app.js");
assert.strictEqual(reportData.lintIssues[0].severity, "error");
assert.strictEqual(
reportData.lintIssues[0].message,
"File is not formatted according to Prettier",
);
});
it("captures error details when prettier reports syntax issues", () => {
const parser = new PrettierParser();
const reportData = parser.parse(SAMPLE_ERROR_LOG, "prettier.log");
assert.strictEqual(reportData.lintIssues.length, 1);
assert.strictEqual(reportData.lintIssues[0].file, "src/app.js");
assert.strictEqual(
reportData.lintIssues[0].message,
"SyntaxError: Unexpected token (1:7)",
);
});
});