Skip to content

Commit b64c135

Browse files
authored
Merge pull request #16283 from Microsoft/fixRunParallel
Master : Fix run-parallel
2 parents 31653de + ef3e7e6 commit b64c135

File tree

1 file changed

+43
-4
lines changed

1 file changed

+43
-4
lines changed

scripts/mocha-parallel.js

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ function runTests(taskConfigsFolder, run, options, cb) {
7272
current: undefined,
7373
start: undefined,
7474
end: undefined,
75+
catastrophicError: "",
7576
failures: []
7677
};
7778
partitions[index] = partition;
@@ -86,9 +87,20 @@ function runTests(taskConfigsFolder, run, options, cb) {
8687
input: p.stdout,
8788
terminal: false
8889
});
90+
91+
var rlError = readline.createInterface({
92+
input: p.stderr,
93+
terminal: false
94+
});
95+
8996
rl.on("line", onmessage);
97+
rlError.on("line", onErrorMessage);
9098
p.on("exit", onexit)
9199

100+
function onErrorMessage(line) {
101+
partition.catastrophicError += line + os.EOL;
102+
}
103+
92104
function onmessage(line) {
93105
if (partition.start === undefined) {
94106
partition.start = Date.now();
@@ -153,15 +165,17 @@ function runTests(taskConfigsFolder, run, options, cb) {
153165
}
154166
}
155167

156-
function onexit() {
168+
function onexit(code) {
157169
if (partition.end === undefined) {
158170
partition.end = Date.now();
159171
}
160172

161173
partition.duration = partition.end - partition.start;
162-
var summaryColor = partition.failed ? "fail" : "green";
163-
var summarySymbol = partition.failed ? Base.symbols.err : Base.symbols.ok;
164-
var summaryTests = (partition.passed === partition.tests ? partition.passed : partition.passed + "/" + partition.tests) + " passing";
174+
var isPartitionFail = partition.failed || code !== 0;
175+
var summaryColor = isPartitionFail ? "fail" : "green";
176+
var summarySymbol = isPartitionFail ? Base.symbols.err : Base.symbols.ok;
177+
178+
var summaryTests = (isPartitionFail ? partition.passed + "/" + partition.tests : partition.passed) + " passing";
165179
var summaryDuration = "(" + ms(partition.duration) + ")";
166180
var savedUseColors = Base.useColors;
167181
Base.useColors = !options.noColors;
@@ -198,12 +212,34 @@ function runTests(taskConfigsFolder, run, options, cb) {
198212
failures = reporter.failures;
199213

200214
var duration = 0;
215+
var catastrophicError = "";
201216
for (var i = 0; i < numPartitions; i++) {
202217
var partition = partitions[i];
203218
stats.passes += partition.passed;
204219
stats.failures += partition.failed;
205220
stats.tests += partition.tests;
206221
duration += partition.duration;
222+
if (partition.catastrophicError !== "") {
223+
// Partition is written out to a temporary file as a JSON object.
224+
// Below is an example of how the partition JSON object looks like
225+
// {
226+
// "light":false,
227+
// "tasks":[
228+
// {
229+
// "runner":"compiler",
230+
// "files":["tests/cases/compiler/es6ImportNamedImportParsingError.ts"]
231+
// }
232+
// ],
233+
// "runUnitTests":false
234+
// }
235+
var jsonText = fs.readFileSync(partition.file);
236+
var configObj = JSON.parse(jsonText);
237+
if (configObj.tasks && configObj.tasks[0]) {
238+
catastrophicError += "Error from one or more of these files: " + configObj.tasks[0].files + os.EOL;
239+
catastrophicError += partition.catastrophicError;
240+
catastrophicError += os.EOL;
241+
}
242+
}
207243
for (var j = 0; j < partition.failures.length; j++) {
208244
var failure = partition.failures[j];
209245
failures.push(makeMochaTest(failure));
@@ -223,6 +259,9 @@ function runTests(taskConfigsFolder, run, options, cb) {
223259
reporter.epilogue();
224260
}
225261

262+
if (catastrophicError !== "") {
263+
return cb(new Error(catastrophicError));
264+
}
226265
if (stats.failures) {
227266
return cb(new Error("Test failures reported: " + stats.failures));
228267
}

0 commit comments

Comments
 (0)