This repository has been archived by the owner on Mar 31, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
cli.js
105 lines (85 loc) · 2.22 KB
/
cli.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
95
96
97
98
99
100
101
102
103
104
105
/*jslint node */
/*eslint-disable func-names, no-magic-numbers */
"use strict";
const {test} = require("tap");
const cli = require("../src/cli");
function makeExitCodeChecker(t) {
return function (exitCode) {
t.strictSame(exitCode, 1);
t.strictSame(process.exitCode, 1);
process.exitCode = 0;
};
}
test("cli()", function (t) {
t.plan(3);
function log(result) {
return t.strictSame(
result,
`test/stubs/bad.js (JSLint)
line 0 column 11
Expected ';' and instead saw '(end)'. (expected_a_b)
Used linters: JSLint
Total files checked: 1
Files with warnings: 1
Total warnings: 1
`,
"should log warnings and summary"
);
}
return cli({
rcFile: "test/stubs/.lints.json",
log,
lintersDirectory: "./linters/"
}).then(makeExitCodeChecker(t));
});
test("cli()", function (t) {
t.plan(1);
return cli({
rcFile: "test/stubs/.lints.json",
log() {
// eslint-disable-next-line fp/no-throw
throw new Error("Mock error");
},
lintersDirectory: "./linters/"
}).catch(function () {
t.strictSame(process.exitCode, 1);
process.exitCode = 0;
});
});
test("cli()", function (t) {
t.plan(3);
function log(result) {
return t.strictSame(
result,
"Nothing to check\n",
"should log summary"
);
}
return cli({
rcFile: "test/stubs/.lints-nothing-to-check.json",
log,
lintersDirectory: "./linters/"
// eslint-disable-next-line promise/always-return
}).then(function (exitCode) {
t.strictSame(exitCode, 0);
t.strictSame(process.exitCode, 0);
});
});
test("cli()", function (t) {
t.plan(3);
function log(result) {
return t.match(
result,
(
"Used linters: JSLint, JSHint, ESLint, dockerfilelint, "
+ "markdownlint,\nremark-lint"
),
"should use default.lints.json if .lints.json is not found"
);
}
return cli({
rcFile: "nonexistent",
log,
lintersDirectory: "./linters/"
}).then(makeExitCodeChecker(t));
});