forked from firefox-devtools/debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtry-runner.js
More file actions
133 lines (112 loc) · 3.01 KB
/
try-runner.js
File metadata and controls
133 lines (112 loc) · 3.01 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
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
/*
* A small test runner/reporter for node-based tests,
* which are run via taskcluster node(debugger).
*/
const { execFileSync } = require("child_process");
const { chdir } = require("process");
const path = require("path");
const flow = require("flow-bin");
const dbgPath = path.join(__dirname, "..");
function execOut(...args) {
let out;
let err;
try {
out = execFileSync(...args);
} catch (e) {
out = e.stdout;
err = e.stderr;
}
return { out: out.toString(), err: err && err.toString() };
}
function logErrors(tool, text, regexp) {
const errors = text.match(regexp) || [];
for (const error of errors) {
console.log(`TEST-UNEXPECTED-FAIL ${tool} | ${error}`);
}
return errors;
}
function logStart(name) {
console.log(`TEST START | ${name}`);
}
function runFlowJson() {
const { out } = execOut(flow, ["check", "--json"]);
const results = JSON.parse(out);
if (!results.passed) {
for (const error of results.errors) {
for (const message of error.message) {
console.log(`TEST-UNEXPECTED-FAIL flow | ${message.descr}`);
}
}
}
return results.passed;
}
function runFlow() {
logStart("Flow");
const { out } = execOut(flow, ["check"]);
console.log(out);
return runFlowJson();
}
function eslint() {
logStart("Eslint");
const { out } = execOut("yarn", ["lint:js"]);
console.log(out);
const errors = logErrors("eslint", out, / {2}error {2}(.*)/g);
return errors.length == 0;
}
function jest() {
logStart("Jest");
const { out, err } = execOut("yarn", ["test"]);
console.log(err);
const errors = logErrors("jest", err || "", / {4}✕(.*)/g);
return errors.length == 0;
}
function stylelint() {
logStart("Stylelint");
const { out } = execOut("yarn", ["lint:css"]);
console.log(out);
const errors = logErrors("stylelint", out, / {2}✖(.*)/g);
return errors.length == 0;
}
function jsxAccessibility() {
logStart("Eslint (JSX Accessibility)");
const { out } = execOut("yarn", ["lint:jsx-a11y"]);
console.log(out);
const errors = logErrors(
"eslint (jsx accessibility)",
out,
/ {2}error {2}(.*)/g
);
return errors.length == 0;
}
function lintMd() {
logStart("Remark");
const { out, err } = execOut("yarn", ["lint:md"]);
const errors = logErrors("remark", err || "", /warning(.+)/g);
return errors.length == 0;
}
chdir(dbgPath);
const flowPassed = runFlow();
const eslintPassed = eslint();
const jestPassed = jest();
const styleLintPassed = stylelint();
const jsxAccessibilityPassed = jsxAccessibility();
const remarkPassed = lintMd();
const success =
flowPassed &&
eslintPassed &&
jestPassed &&
styleLintPassed &&
jsxAccessibilityPassed &&
remarkPassed;
console.log({
flowPassed,
eslintPassed,
jestPassed,
styleLintPassed,
jsxAccessibilityPassed,
remarkPassed
});
process.exitCode = success ? 0 : 1;