Load unit tests more consistently (pulled from ESM branch) (#58481)

This commit is contained in:
Jake Bailey 2024-05-09 10:32:05 -07:00 committed by GitHub
parent be8fb98cf1
commit 81e9929154
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 16 additions and 20 deletions

View File

@ -9,9 +9,3 @@ export * from "../fourslashRunner.js";
export * from "../compilerRunner.js";
export * from "../transpileRunner.js";
export * from "../runner.js";
// If running as emitted CJS, don't start executing the tests here; instead start in runner.ts.
// If running bundled, we want this to be here so that esbuild places the tests after runner.ts.
if (!__filename.endsWith("Harness.js")) {
require("../tests.js");
}

View File

@ -25,7 +25,7 @@ import {
import * as ts from "../_namespaces/ts.js";
import * as Utils from "../_namespaces/Utils.js";
export function start() {
export function start(importTests: () => Promise<unknown>) {
const Mocha = require("mocha") as typeof import("mocha");
const Base = Mocha.reporters.Base;
const color = Base.color;
@ -656,5 +656,5 @@ export function start() {
shimNoopTestInterface(global);
}
setTimeout(() => startDelayed(perfData, totalCost), 0); // Do real startup on next tick, so all unit tests have been collected
importTests().then(() => startDelayed(perfData, totalCost));
}

View File

@ -16,7 +16,10 @@ import {
UnitTestTask,
} from "../_namespaces/Harness.Parallel.js";
export function start() {
export function start(importTests: () => Promise<unknown>) {
// This brings in the tests after we finish setting things up and yield to the event loop.
const importTestsPromise = importTests();
function hookUncaughtExceptions() {
if (!exceptionsHooked) {
process.on("uncaughtException", handleUncaughtException);
@ -277,7 +280,9 @@ export function start() {
return !!tasks && Array.isArray(tasks) && tasks.length > 0 && tasks.every(validateTest);
}
function processHostMessage(message: ParallelHostMessage) {
async function processHostMessage(message: ParallelHostMessage) {
await importTestsPromise;
if (!validateHostMessage(message)) {
console.log("Invalid message:", message);
return;

View File

@ -249,6 +249,10 @@ function beginTests() {
}
}
function importTests() {
return import("./tests.js");
}
export let isWorker: boolean;
function startTestEnvironment() {
// For debugging convenience.
@ -256,20 +260,13 @@ function startTestEnvironment() {
isWorker = handleTestConfig();
if (isWorker) {
return Parallel.Worker.start();
return Parallel.Worker.start(importTests);
}
else if (taskConfigsFolder && workerCount && workerCount > 1) {
return Parallel.Host.start();
return Parallel.Host.start(importTests);
}
beginTests();
importTests();
}
startTestEnvironment();
// This brings in all of the unittests.
// If running as emitted CJS, we want to start the tests here after startTestEnvironment.
// If running bundled, we will do this in Harness.ts.
if (__filename.endsWith("runner.js")) {
require("./tests.js");
}