This repository has been archived by the owner on Apr 22, 2020. It is now read-only.
forked from wearerequired/lint-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinters.test.js
94 lines (82 loc) · 2.93 KB
/
linters.test.js
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
const { join } = require("path");
const { copySync, removeSync } = require("fs-extra");
const { normalizeDates } = require("../utils");
const blackParams = require("./params/black");
const eslintParams = require("./params/eslint");
const eslintTypescriptParams = require("./params/eslint-typescript");
const flake8Params = require("./params/flake8");
const gofmtParams = require("./params/gofmt");
const golintParams = require("./params/golint");
const prettierParams = require("./params/prettier");
const ruboCopParams = require("./params/rubocop");
const stylelintParams = require("./params/stylelint");
const swiftformatParams = require("./params/swiftformat");
const swiftlintParams = require("./params/swiftlint");
const linterParams = [
blackParams,
eslintParams,
eslintTypescriptParams,
flake8Params,
gofmtParams,
golintParams,
prettierParams,
ruboCopParams,
stylelintParams,
];
// Only run Swift tests on macOS
if (process.platform === "darwin") {
linterParams.push(swiftformatParams, swiftlintParams);
}
// Test lint and auto-fix modes
describe.each([
["lint", false],
["auto-fix", true],
])("%s", (lintMode, autoFix) => {
// Test all linters
describe.each(linterParams)(
"%s",
(projectName, linter, extensions, getLintParams, getFixParams) => {
const projectDir = join(__dirname, "projects", projectName);
const tmpDir = join(__dirname, "..", "tmp", projectName);
const expected = autoFix ? getFixParams(tmpDir) : getLintParams(tmpDir);
beforeAll(async () => {
// Move test project into temporary directory (where files can be modified by the linters)
copySync(projectDir, tmpDir);
await linter.verifySetup(tmpDir);
});
afterAll(() => {
// Remove temporary directory after test completion
removeSync(tmpDir);
});
// Test `lint` function
test(`${linter.name} returns expected ${lintMode} output`, () => {
const cmdOutput = linter.lint(tmpDir, extensions, "", autoFix);
// Exit code
expect(cmdOutput.status).toEqual(expected.cmdOutput.status);
// stdout
const stdout = normalizeDates(cmdOutput.stdout);
if ("stdoutParts" in expected.lintResult) {
expected.lintResult.stdoutParts.forEach(stdoutPart =>
expect(stdout).toEqual(expect.stringContaining(stdoutPart)),
);
} else if ("stdout" in expected.lintResult) {
expect(stdout).toEqual(expected.stdout);
}
// stderr
const stderr = normalizeDates(cmdOutput.stderr);
if ("stderrParts" in expected.lintResult) {
expected.lintResult.stderrParts.forEach(stderrParts =>
expect(stderr).toEqual(expect.stringContaining(stderrParts)),
);
} else if ("stderr" in expected.lintResult) {
expect(stderr).toEqual(expected.stderr);
}
});
// Test `parseOutput` function
test(`${linter.name} parses ${lintMode} output correctly`, () => {
const lintResult = linter.parseOutput(tmpDir, expected.cmdOutput);
expect(lintResult).toEqual(expected.lintResult);
});
},
);
});