Skip to content

Commit 219a570

Browse files
authored
Fix discovery and execution of root-level tests in the parallel runner (microsoft#32980)
1 parent 5d04250 commit 219a570

File tree

3 files changed

+35
-14
lines changed

3 files changed

+35
-14
lines changed

src/testRunner/parallel/host.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,7 @@ namespace Harness.Parallel.Host {
626626

627627
const perfData = readSavedPerfData(configOption);
628628
context.describe = addSuite as Mocha.SuiteFunction;
629+
context.it = addSuite as Mocha.TestFunction;
629630

630631
function addSuite(title: string) {
631632
// Note, sub-suites are not indexed (we assume such granularity is not required)

src/testRunner/parallel/worker.ts

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,24 +151,42 @@ namespace Harness.Parallel.Worker {
151151
unitTestSuiteMap.set(suite.title, suite);
152152
}
153153
}
154+
if (!unitTestTestMap && unitTestSuite.tests.length) {
155+
unitTestTestMap = ts.createMap<Mocha.Test>();
156+
for (const test of unitTestSuite.tests) {
157+
unitTestTestMap.set(test.title, test);
158+
}
159+
}
154160

155-
if (!unitTestSuiteMap) {
161+
if (!unitTestSuiteMap && !unitTestTestMap) {
156162
throw new Error(`Asked to run unit test ${task.file}, but no unit tests were discovered!`);
157163
}
158164

159-
const suite = unitTestSuiteMap.get(task.file);
160-
if (!suite) {
165+
let suite = unitTestSuiteMap.get(task.file);
166+
const test = unitTestTestMap.get(task.file);
167+
if (!suite && !test) {
161168
throw new Error(`Unit test with name "${task.file}" was asked to be run, but such a test does not exist!`);
162169
}
163170

164171
const root = new Suite("", new Mocha.Context());
165172
root.timeout(globalTimeout || 40_000);
166-
root.addSuite(suite);
167-
Object.setPrototypeOf(suite.ctx, root.ctx);
173+
if (suite) {
174+
root.addSuite(suite);
175+
Object.setPrototypeOf(suite.ctx, root.ctx);
176+
}
177+
else if (test) {
178+
const newSuite = new Suite("", new Mocha.Context());
179+
newSuite.addTest(test);
180+
root.addSuite(newSuite);
181+
Object.setPrototypeOf(newSuite.ctx, root.ctx);
182+
Object.setPrototypeOf(test.ctx, root.ctx);
183+
test.parent = newSuite;
184+
suite = newSuite;
185+
}
168186

169-
runSuite(task, suite, payload => {
170-
suite.parent = unitTestSuite;
171-
Object.setPrototypeOf(suite.ctx, unitTestSuite.ctx);
187+
runSuite(task, suite!, payload => {
188+
suite!.parent = unitTestSuite;
189+
Object.setPrototypeOf(suite!.ctx, unitTestSuite.ctx);
172190
fn(payload);
173191
});
174192
}
@@ -284,6 +302,8 @@ namespace Harness.Parallel.Worker {
284302
// The root suite for all unit tests.
285303
let unitTestSuite: Suite;
286304
let unitTestSuiteMap: ts.Map<Mocha.Suite>;
305+
// (Unit) Tests directly within the root suite
306+
let unitTestTestMap: ts.Map<Mocha.Test>;
287307

288308
if (runUnitTests) {
289309
unitTestSuite = new Suite("", new Mocha.Context());

tests/baselines/reference/tsbuild/moduleSpecifiers/initial-build/resolves-correctly.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ exports.__esModule = true;
1414
"program": {
1515
"fileInfos": {
1616
"../../../.ts/lib.es5.d.ts": {
17-
"version": "146944634190",
18-
"signature": "146944634190"
17+
"version": "406734842058",
18+
"signature": "406734842058"
1919
},
2020
"../../../.ts/lib.es2015.d.ts": {
2121
"version": "57263133672",
@@ -114,8 +114,8 @@ exports.__esModule = true;
114114
"program": {
115115
"fileInfos": {
116116
"../../../.ts/lib.es5.d.ts": {
117-
"version": "146944634190",
118-
"signature": "146944634190"
117+
"version": "406734842058",
118+
"signature": "406734842058"
119119
},
120120
"../../../.ts/lib.es2015.d.ts": {
121121
"version": "57263133672",
@@ -237,8 +237,8 @@ exports.getVar = getVar;
237237
"program": {
238238
"fileInfos": {
239239
"../../../.ts/lib.es5.d.ts": {
240-
"version": "146944634190",
241-
"signature": "146944634190"
240+
"version": "406734842058",
241+
"signature": "406734842058"
242242
},
243243
"../../../.ts/lib.es2015.d.ts": {
244244
"version": "57263133672",

0 commit comments

Comments
 (0)