Skip to content

Commit 1b962ef

Browse files
committed
grep should not be an array
1 parent 86bee2a commit 1b962ef

File tree

7 files changed

+29
-21
lines changed

7 files changed

+29
-21
lines changed

.dockerignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ yarn.lock
4242
yarn-error.log
4343
.parallelperf.*
4444
.failed-tests
45-
.failed-tests.json
4645
TEST-results.xml
4746
package-lock.json
4847
tests

.gitignore

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

.npmignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ Jakefile.js
1414
.eslintignore
1515
.editorconfig
1616
.failed-tests
17-
.failed-tests.json
1817
.git
1918
.git/
2019
.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.json'.",
457+
" --failed": "Runs tests listed in '.failed-tests'.",
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.json even if they pass",
461+
" --keepFailed": "Keep tests in '.failed-tests 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.json' even if they pass.",
479+
" --keepFailed": "Keep tests in .failed-tests 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.json'. 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.",
638638
"-r --reporter=<reporter>": "The mocha reporter to use.",
639-
" --keepFailed": "Keep tests in '.failed-tests.json' even if they pass",
639+
" --keepFailed": "Keep tests in .failed-tests 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: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,15 @@ async function runConsoleTests(runJs, defaultReporter, runInParallel, watchMode,
8484
args.push("-g", `"${tests}"`);
8585
}
8686
if (failed) {
87-
args.push("--config", ".failed-tests.json");
87+
const grep = fs.readFileSync(".failed-tests", "utf8")
88+
.split(/\r?\n/g)
89+
.map(test => test.trim())
90+
.filter(test => test.length > 0)
91+
.map(regExpEscape)
92+
.join("|");
93+
const file = path.join(os.tmpdir(), ".failed-tests.json");
94+
fs.writeFileSync(file, JSON.stringify({ grep }), "utf8");
95+
args.push("--config", file);
8896
}
8997
if (colors) {
9098
args.push("--colors");
@@ -206,3 +214,7 @@ function restoreSavedNodeEnv() {
206214
function deleteTemporaryProjectOutput() {
207215
return del(path.join(exports.localBaseline, "projectOutput/"));
208216
}
217+
218+
function regExpEscape(text) {
219+
return text.replace(/[.*+?^${}()|\[\]\\]/g, '\\$&');
220+
}

scripts/failed-tests.js

Lines changed: 10 additions & 11 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.json reporter
10+
* .failed-tests 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.json";
28+
if (reporterOptions.file === undefined) reporterOptions.file = ".failed-tests";
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(readTests());
73+
const failingTests = new Set(fs.existsSync(file) ? readTests() : undefined);
7474
const possiblyPassingSuites = /**@type {Set<string>}*/(new Set());
7575

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

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

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.json"),
551+
file: path.resolve(".failed-tests"),
552552
keepFailed: Harness.keepFailed // eslint-disable-line @typescript-eslint/no-unnecessary-qualifier
553553
}
554554
});

0 commit comments

Comments
 (0)