DEV: linting of run-qunit.js (#10728)

This commit is contained in:
Joffrey JAFFEUX 2020-09-23 12:52:11 +02:00 committed by GitHub
parent eb891778ff
commit f2a6791ce2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,8 +5,6 @@
// Requires chrome-launcher and chrome-remote-interface from npm // Requires chrome-launcher and chrome-remote-interface from npm
// An up-to-date version of chrome is also required // An up-to-date version of chrome is also required
/* globals Promise */
var args = process.argv.slice(2); var args = process.argv.slice(2);
if (args.length < 1 || args.length > 3) { if (args.length < 1 || args.length > 3) {
@ -23,12 +21,13 @@ const fs = require("fs");
if (QUNIT_RESULT) { if (QUNIT_RESULT) {
(async () => { (async () => {
await fs.stat(QUNIT_RESULT, (err, stats) => { await fs.stat(QUNIT_RESULT, (err, stats) => {
if (stats && stats.isFile()) if (stats && stats.isFile()) {
fs.unlink(QUNIT_RESULT, unlinkErr => { fs.unlink(QUNIT_RESULT, (unlinkErr) => {
if (unlinkErr) { if (unlinkErr) {
console.log("Error deleting " + QUNIT_RESULT + " " + unlinkErr); console.log("Error deleting " + QUNIT_RESULT + " " + unlinkErr);
} }
}); });
}
}); });
})(); })();
} }
@ -42,8 +41,8 @@ async function runAllTests() {
"--no-sandbox", "--no-sandbox",
"--disable-dev-shm-usage", "--disable-dev-shm-usage",
"--mute-audio", "--mute-audio",
"--window-size=1440,900" "--window-size=1440,900",
] ],
}; };
if (process.env.REMOTE_DEBUG) { if (process.env.REMOTE_DEBUG) {
@ -68,7 +67,8 @@ async function runAllTests() {
console.log( console.log(
"Unable to establish connection to chrome target - trying again..." "Unable to establish connection to chrome target - trying again..."
); );
await new Promise(resolve => setTimeout(resolve, 100)); // eslint-disable-next-line
await new Promise((resolve) => setTimeout(resolve, 100));
} else { } else {
throw e; throw e;
} }
@ -77,18 +77,19 @@ async function runAllTests() {
const { Inspector, Page, Runtime } = protocol; const { Inspector, Page, Runtime } = protocol;
// eslint-disable-next-line
await Promise.all([Inspector.enable(), Page.enable(), Runtime.enable()]); await Promise.all([Inspector.enable(), Page.enable(), Runtime.enable()]);
Inspector.targetCrashed(entry => { Inspector.targetCrashed((entry) => {
console.log("Chrome target crashed:"); console.log("Chrome target crashed:");
console.log(entry); console.log(entry);
}); });
Runtime.exceptionThrown(exceptionInfo => { Runtime.exceptionThrown((exceptionInfo) => {
console.log(exceptionInfo.exceptionDetails.exception.description); console.log(exceptionInfo.exceptionDetails.exception.description);
}); });
Runtime.consoleAPICalled(response => { Runtime.consoleAPICalled((response) => {
const message = response["args"][0].value; const message = response["args"][0].value;
// Not finished yet, don't add a newline // Not finished yet, don't add a newline
@ -114,15 +115,15 @@ async function runAllTests() {
expression: expression:
`const QUNIT_FAIL_FAST = ` + `const QUNIT_FAIL_FAST = ` +
(qff === "1" || qff === "true").toString() + (qff === "1" || qff === "true").toString() +
";" ";",
}); });
await Runtime.evaluate({ await Runtime.evaluate({
expression: `(${qunit_script})();` expression: `(${qunit_script})();`,
}); });
if (args[0].indexOf("report_requests=1") > -1) { if (args[0].indexOf("report_requests=1") > -1) {
await Runtime.evaluate({ await Runtime.evaluate({
expression: "QUnit.config.logAllRequests = true" expression: "QUnit.config.logAllRequests = true",
}); });
} }
@ -131,7 +132,7 @@ async function runAllTests() {
var interval; var interval;
let runTests = async function() { let runTests = async function () {
if (Date.now() > start + timeout) { if (Date.now() > start + timeout) {
console.error("\n\nTests timed out\n"); console.error("\n\nTests timed out\n");
protocol.close(); protocol.close();
@ -140,7 +141,7 @@ async function runAllTests() {
} }
let numFails = await Runtime.evaluate({ let numFails = await Runtime.evaluate({
expression: `(${check_script})()` expression: `(${check_script})()`,
}); });
if (numFails && numFails.result && numFails.result.type !== "undefined") { if (numFails && numFails.result && numFails.result.type !== "undefined") {
@ -160,7 +161,7 @@ async function runAllTests() {
}); });
} }
runAllTests().catch(e => { runAllTests().catch((e) => {
console.log("Failed to run tests: " + e); console.log("Failed to run tests: " + e);
process.exit(1); process.exit(1);
}); });
@ -178,12 +179,12 @@ function logQUnit() {
let durations = {}; let durations = {};
let inTest = false; let inTest = false;
QUnit.testStart(function(context) { QUnit.testStart(function (context) {
console.log("↪ " + context.module + "::" + context.name); console.log("↪ " + context.module + "::" + context.name);
inTest = true; inTest = true;
}); });
QUnit.testDone(function(context) { QUnit.testDone(function (context) {
durations[context.module + "::" + context.name] = context.runtime; durations[context.module + "::" + context.name] = context.runtime;
if (context.failed) { if (context.failed) {
@ -197,6 +198,7 @@ function logQUnit() {
assertionErrors = []; assertionErrors = [];
// Pass QUNIT_FAIL_FAST on the command line to quit after the first failure // Pass QUNIT_FAIL_FAST on the command line to quit after the first failure
// eslint-disable-next-line
if (QUNIT_FAIL_FAST) { if (QUNIT_FAIL_FAST) {
QUnit.config.queue.length = 0; QUnit.config.queue.length = 0;
} }
@ -211,7 +213,7 @@ function logQUnit() {
inTest = false; inTest = false;
}); });
QUnit.log(function(context) { QUnit.log(function (context) {
if (context.result) { if (context.result) {
return; return;
} }
@ -229,13 +231,13 @@ function logQUnit() {
assertionErrors.push(msg); assertionErrors.push(msg);
}); });
QUnit.done(function(context) { QUnit.done(function (context) {
console.log("\n"); console.log("\n");
if (testErrors.length) { if (testErrors.length) {
console.log("Test Errors"); console.log("Test Errors");
console.log("----------------------------------------------"); console.log("----------------------------------------------");
testErrors.forEach(e => { testErrors.forEach((e) => {
console.error(e); console.error(e);
}); });
console.log("\n"); console.log("\n");
@ -243,12 +245,12 @@ function logQUnit() {
console.log("Slowest tests"); console.log("Slowest tests");
console.log("----------------------------------------------"); console.log("----------------------------------------------");
let ary = Object.keys(durations).map(key => ({ let ary = Object.keys(durations).map((key) => ({
key: key, key: key,
value: durations[key] value: durations[key],
})); }));
ary.sort((p1, p2) => p2.value - p1.value); ary.sort((p1, p2) => p2.value - p1.value);
ary.slice(0, 30).forEach(pair => { ary.slice(0, 30).forEach((pair) => {
console.log(pair.key + ": " + pair.value + "ms"); console.log(pair.key + ": " + pair.value + "ms");
}); });
@ -256,7 +258,7 @@ function logQUnit() {
"Time: " + context.runtime + "ms", "Time: " + context.runtime + "ms",
"Total: " + context.total, "Total: " + context.total,
"Passed: " + context.passed, "Passed: " + context.passed,
"Failed: " + context.failed "Failed: " + context.failed,
]; ];
console.log(stats.join(", ")); console.log(stats.join(", "));