Files
firefox/devtools/client/debugger/bin/try-runner.js
T
Nicolas Chevobbe 1ec37d3742 Bug 1586297 - Fix debugger's jest failures. r=jlast.
Some tests were failing because we `require` an absolute
path from the debugger source. We add a new entry in jest
config's moduleNameMapper to reroute all the absolute require
of devtools modules to the right path.
To fix the failures we also need to add a fixture for `Services`
as it's loaded in one of the fail we use in the debugger.

We take this opportunity to fix debugger's try runner.
Currently, we were only checking the `numFailedTests` property
of the resulting JSON when running tests.
But in some case, this property would still be 0, but other
properties would indicate the some tests fail.
In order to not have to go through all those properties, we
simply check that the array of error messages we build is
empty to assert if the tests were successfully ran.

Differential Revision: https://phabricator.services.mozilla.com/D48295
2019-10-07 15:34:14 +00:00

152 lines
3.6 KiB
JavaScript

/* 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, { silent: true });
} catch (e) {
out = e.stdout;
err = e.stderr;
}
return { out: out.toString(), err: err && err.toString() };
}
function logErrors(tool, errors) {
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.match(/ {2}error {2}(.*)/g) || []);
return errors.length == 0;
}
function jest() {
logStart("Jest");
const { out } = execOut("yarn", ["test-ci"]);
// Remove the non-JSON logs mixed with the JSON output by yarn.
const jsonOut = out.substring(out.indexOf("{"), out.lastIndexOf("}") + 1);
const results = JSON.parse(jsonOut);
// The individual failing tests are in jammed into the same message string :/
const errors = [].concat(
...results.testResults.map(r =>
r.message.split("\n").filter(l => l.includes("●"))
)
);
logErrors("jest", errors);
return errors.length == 0;
}
function stylelint() {
logStart("Stylelint");
const { out } = execOut("yarn", ["lint:css"]);
console.log(out);
const errors = logErrors("stylelint", out.match(/ {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.match(/ {2}error {2}(.*)/g) || []
);
return errors.length == 0;
}
function lintMd() {
logStart("Remark");
const { err } = execOut("yarn", ["lint:md"]);
const errors = logErrors("remark", (err || "").match(/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,
});
if (!success) {
console.log(
"[debugger-node-test-runner] You can find documentation about the " +
"debugger node tests at https://docs.firefox-dev.tools/tests/node-tests.html"
);
}
process.exitCode = success ? 0 : 1;
console.log("CODE", process.exitCode);