Skip to content

Commit 86bee2a

Browse files
committed
Update failed test tracking to support Mocha 6+
1 parent 9f70d49 commit 86bee2a

File tree

8 files changed

+24
-114
lines changed

8 files changed

+24
-114
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ yarn.lock
4242
yarn-error.log
4343
.parallelperf.*
4444
.failed-tests
45+
.failed-tests.json
4546
TEST-results.xml
4647
package-lock.json
4748
tests

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ tests/cases/user/*/**/*.d.ts
8383
!tests/cases/user/discord.js/
8484
tests/baselines/reference/dt
8585
.failed-tests
86+
.failed-tests.json
8687
TEST-results.xml
8788
package-lock.json
8889
tests/cases/user/TypeScript-React-Starter/TypeScript-React-Starter

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Jakefile.js
1414
.eslintignore
1515
.editorconfig
1616
.failed-tests
17+
.failed-tests.json
1718
.git
1819
.git/
1920
.gitattributes

Gulpfile.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -454,11 +454,11 @@ task("runtests", series(preBuild, preTest, runTests, postTest));
454454
task("runtests").description = "Runs the tests using the built run.js file.";
455455
task("runtests").flags = {
456456
"-t --tests=<regex>": "Pattern for tests to run.",
457-
" --failed": "Runs tests listed in '.failed-tests'.",
457+
" --failed": "Runs tests listed in '.failed-tests.json'.",
458458
"-r --reporter=<reporter>": "The mocha reporter to use.",
459459
"-d --debug": "Runs tests in debug mode (NodeJS 6 and earlier)",
460460
"-i --inspect": "Runs tests in inspector mode (NodeJS 8 and later)",
461-
" --keepFailed": "Keep tests in .failed-tests even if they pass",
461+
" --keepFailed": "Keep tests in '.failed-tests.json even if they pass",
462462
" --light": "Run tests in light mode (fewer verifications, but tests run faster)",
463463
" --dirty": "Run tests without first cleaning test output directories",
464464
" --stackTraceLimit=<limit>": "Sets the maximum number of stack frames to display. Use 'full' to show all frames.",
@@ -476,7 +476,7 @@ task("runtests-parallel").description = "Runs all the tests in parallel using th
476476
task("runtests-parallel").flags = {
477477
" --no-lint": "disables lint.",
478478
" --light": "Run tests in light mode (fewer verifications, but tests run faster).",
479-
" --keepFailed": "Keep tests in .failed-tests even if they pass.",
479+
" --keepFailed": "Keep tests in '.failed-tests.json' even if they pass.",
480480
" --dirty": "Run tests without first cleaning test output directories.",
481481
" --stackTraceLimit=<limit>": "Sets the maximum number of stack frames to display. Use 'full' to show all frames.",
482482
" --workers=<number>": "The number of parallel workers to use.",
@@ -634,9 +634,9 @@ task("watch", series(preBuild, preTest, parallel(watchLib, watchDiagnostics, wat
634634
task("watch").description = "Watches for changes and rebuilds and runs tests in parallel.";
635635
task("watch").flags = {
636636
"-t --tests=<regex>": "Pattern for tests to run. Forces tests to be run in a single worker.",
637-
" --failed": "Runs tests listed in '.failed-tests'. Forces tests to be run in a single worker.",
637+
" --failed": "Runs tests listed in '.failed-tests.json'. Forces tests to be run in a single worker.",
638638
"-r --reporter=<reporter>": "The mocha reporter to use.",
639-
" --keepFailed": "Keep tests in .failed-tests even if they pass",
639+
" --keepFailed": "Keep tests in '.failed-tests.json' even if they pass",
640640
" --light": "Run tests in light mode (fewer verifications, but tests run faster)",
641641
" --dirty": "Run tests without first cleaning test output directories",
642642
" --stackTraceLimit=<limit>": "Sets the maximum number of stack frames to display. Use 'full' to show all frames.",

scripts/build/tests.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,15 @@ async function runConsoleTests(runJs, defaultReporter, runInParallel, watchMode,
7777
// timeout normally isn"t necessary but Travis-CI has been timing out on compiler baselines occasionally
7878
// default timeout is 2sec which really should be enough, but maybe we just need a small amount longer
7979
if (!runInParallel) {
80-
args.push(failed ? "scripts/run-failed-tests.js" : mochaJs);
80+
args.push(mochaJs);
8181
args.push("-R", "scripts/failed-tests");
8282
args.push("-O", '"reporter=' + reporter + (keepFailed ? ",keepFailed=true" : "") + '"');
8383
if (tests) {
8484
args.push("-g", `"${tests}"`);
8585
}
86+
if (failed) {
87+
args.push("--config", ".failed-tests.json");
88+
}
8689
if (colors) {
8790
args.push("--colors");
8891
}

scripts/failed-tests.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const os = require("os");
77
const failingHookRegExp = /^(.*) "(before|after) (all|each)" hook$/;
88

99
/**
10-
* .failed-tests reporter
10+
* .failed-tests.json reporter
1111
*
1212
* @typedef {Object} ReporterOptions
1313
* @property {string} [file]
@@ -25,7 +25,7 @@ class FailedTestsReporter extends Mocha.reporters.Base {
2525
if (!runner) return;
2626

2727
const reporterOptions = this.reporterOptions = options.reporterOptions || {};
28-
if (reporterOptions.file === undefined) reporterOptions.file = ".failed-tests";
28+
if (reporterOptions.file === undefined) reporterOptions.file = ".failed-tests.json";
2929
if (reporterOptions.keepFailed === undefined) reporterOptions.keepFailed = false;
3030
if (reporterOptions.reporter) {
3131
/** @type {Mocha.ReporterConstructor} */
@@ -70,7 +70,7 @@ class FailedTestsReporter extends Mocha.reporters.Base {
7070
* @param {(err?: NodeJS.ErrnoException) => void} done
7171
*/
7272
static writeFailures(file, passes, failures, keepFailed, done) {
73-
const failingTests = new Set(fs.existsSync(file) ? readTests() : undefined);
73+
const failingTests = new Set(readTests());
7474
const possiblyPassingSuites = /**@type {Set<string>}*/(new Set());
7575

7676
// Remove tests that are now passing and track suites that are now
@@ -104,9 +104,8 @@ class FailedTestsReporter extends Mocha.reporters.Base {
104104
if (failingTests.size > 0) {
105105
const failed = Array
106106
.from(failingTests)
107-
.sort()
108-
.join(os.EOL);
109-
fs.writeFile(file, failed, "utf8", done);
107+
.sort();
108+
fs.writeFile(file, JSON.stringify({ grep: failed }, undefined, " "), "utf8", done);
110109
}
111110
else if (!keepFailed && fs.existsSync(file)) {
112111
fs.unlink(file, done);
@@ -116,10 +115,12 @@ class FailedTestsReporter extends Mocha.reporters.Base {
116115
}
117116

118117
function readTests() {
119-
return fs.readFileSync(file, "utf8")
120-
.split(/\r?\n/g)
121-
.map(line => line.trim())
122-
.filter(line => line.length > 0);
118+
try {
119+
return JSON.parse(fs.readFileSync(file, "utf8")).grep;
120+
}
121+
catch {
122+
return undefined;
123+
}
123124
}
124125
}
125126

scripts/run-failed-tests.js

Lines changed: 0 additions & 97 deletions
This file was deleted.

src/testRunner/parallel/host.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ namespace Harness.Parallel.Host {
548548
else {
549549
failedTestReporter = new FailedTestReporter(replayRunner, {
550550
reporterOptions: {
551-
file: path.resolve(".failed-tests"),
551+
file: path.resolve(".failed-tests.json"),
552552
keepFailed: Harness.keepFailed // eslint-disable-line @typescript-eslint/no-unnecessary-qualifier
553553
}
554554
});

0 commit comments

Comments
 (0)