mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Fix discovery and execution of root-level tests in the parallel runner (#32980)
This commit is contained in:
@@ -626,6 +626,7 @@ namespace Harness.Parallel.Host {
|
||||
|
||||
const perfData = readSavedPerfData(configOption);
|
||||
context.describe = addSuite as Mocha.SuiteFunction;
|
||||
context.it = addSuite as Mocha.TestFunction;
|
||||
|
||||
function addSuite(title: string) {
|
||||
// Note, sub-suites are not indexed (we assume such granularity is not required)
|
||||
|
||||
@@ -151,24 +151,42 @@ namespace Harness.Parallel.Worker {
|
||||
unitTestSuiteMap.set(suite.title, suite);
|
||||
}
|
||||
}
|
||||
if (!unitTestTestMap && unitTestSuite.tests.length) {
|
||||
unitTestTestMap = ts.createMap<Mocha.Test>();
|
||||
for (const test of unitTestSuite.tests) {
|
||||
unitTestTestMap.set(test.title, test);
|
||||
}
|
||||
}
|
||||
|
||||
if (!unitTestSuiteMap) {
|
||||
if (!unitTestSuiteMap && !unitTestTestMap) {
|
||||
throw new Error(`Asked to run unit test ${task.file}, but no unit tests were discovered!`);
|
||||
}
|
||||
|
||||
const suite = unitTestSuiteMap.get(task.file);
|
||||
if (!suite) {
|
||||
let suite = unitTestSuiteMap.get(task.file);
|
||||
const test = unitTestTestMap.get(task.file);
|
||||
if (!suite && !test) {
|
||||
throw new Error(`Unit test with name "${task.file}" was asked to be run, but such a test does not exist!`);
|
||||
}
|
||||
|
||||
const root = new Suite("", new Mocha.Context());
|
||||
root.timeout(globalTimeout || 40_000);
|
||||
root.addSuite(suite);
|
||||
Object.setPrototypeOf(suite.ctx, root.ctx);
|
||||
if (suite) {
|
||||
root.addSuite(suite);
|
||||
Object.setPrototypeOf(suite.ctx, root.ctx);
|
||||
}
|
||||
else if (test) {
|
||||
const newSuite = new Suite("", new Mocha.Context());
|
||||
newSuite.addTest(test);
|
||||
root.addSuite(newSuite);
|
||||
Object.setPrototypeOf(newSuite.ctx, root.ctx);
|
||||
Object.setPrototypeOf(test.ctx, root.ctx);
|
||||
test.parent = newSuite;
|
||||
suite = newSuite;
|
||||
}
|
||||
|
||||
runSuite(task, suite, payload => {
|
||||
suite.parent = unitTestSuite;
|
||||
Object.setPrototypeOf(suite.ctx, unitTestSuite.ctx);
|
||||
runSuite(task, suite!, payload => {
|
||||
suite!.parent = unitTestSuite;
|
||||
Object.setPrototypeOf(suite!.ctx, unitTestSuite.ctx);
|
||||
fn(payload);
|
||||
});
|
||||
}
|
||||
@@ -284,6 +302,8 @@ namespace Harness.Parallel.Worker {
|
||||
// The root suite for all unit tests.
|
||||
let unitTestSuite: Suite;
|
||||
let unitTestSuiteMap: ts.Map<Mocha.Suite>;
|
||||
// (Unit) Tests directly within the root suite
|
||||
let unitTestTestMap: ts.Map<Mocha.Test>;
|
||||
|
||||
if (runUnitTests) {
|
||||
unitTestSuite = new Suite("", new Mocha.Context());
|
||||
|
||||
+6
-6
@@ -14,8 +14,8 @@ exports.__esModule = true;
|
||||
"program": {
|
||||
"fileInfos": {
|
||||
"../../../.ts/lib.es5.d.ts": {
|
||||
"version": "146944634190",
|
||||
"signature": "146944634190"
|
||||
"version": "406734842058",
|
||||
"signature": "406734842058"
|
||||
},
|
||||
"../../../.ts/lib.es2015.d.ts": {
|
||||
"version": "57263133672",
|
||||
@@ -114,8 +114,8 @@ exports.__esModule = true;
|
||||
"program": {
|
||||
"fileInfos": {
|
||||
"../../../.ts/lib.es5.d.ts": {
|
||||
"version": "146944634190",
|
||||
"signature": "146944634190"
|
||||
"version": "406734842058",
|
||||
"signature": "406734842058"
|
||||
},
|
||||
"../../../.ts/lib.es2015.d.ts": {
|
||||
"version": "57263133672",
|
||||
@@ -237,8 +237,8 @@ exports.getVar = getVar;
|
||||
"program": {
|
||||
"fileInfos": {
|
||||
"../../../.ts/lib.es5.d.ts": {
|
||||
"version": "146944634190",
|
||||
"signature": "146944634190"
|
||||
"version": "406734842058",
|
||||
"signature": "406734842058"
|
||||
},
|
||||
"../../../.ts/lib.es2015.d.ts": {
|
||||
"version": "57263133672",
|
||||
|
||||
Reference in New Issue
Block a user