Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/base-testplane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { ConfigInput } from "./config/types";
export abstract class BaseTestplane extends AsyncEmitter {
protected _interceptors: Interceptor[] = [];
protected _config: Config;
protected _initEventEmited: boolean = false;

static create<T extends BaseTestplane>(
this: new (config?: string | ConfigInput) => T,
Expand All @@ -38,8 +39,13 @@ export abstract class BaseTestplane extends AsyncEmitter {
this._loadPlugins();
}

protected async _init(): Promise<void> {
this._init = (): Promise<void> => Promise.resolve(); // init only once
/** @note Only the first call returns a promise to wait for INIT handlers to complete, subsequent calls return immediately to avoid deadlocks */
protected async _emitInitEventOnce(): Promise<void> {
if (this._initEventEmited) {
return;
}

this._initEventEmited = true;
await this.emitAndWait(MasterEvents.INIT);
}

Expand Down
9 changes: 4 additions & 5 deletions src/testplane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class Testplane extends BaseTestplane {
this._filesToRemove.push(path);
}

protected async _init(): Promise<void> {
protected async _startServersIfNeeded(): Promise<void> {
await initDevServer({
testplane: this,
devServerConfig: this._config.devServer,
Expand All @@ -124,8 +124,6 @@ export class Testplane extends BaseTestplane {
throw new Error(`Vite server failed to start: ${(err as Error).message}`);
}
}

return super._init();
}

async run(
Expand Down Expand Up @@ -185,7 +183,8 @@ export class Testplane extends BaseTestplane {
eventsUtils.passthroughEventAsync(this.runner, this, _.values(MasterAsyncEvents));
eventsUtils.passthroughEventAsync(signalHandler, this, MasterEvents.EXIT);

await this._init();
await this._startServersIfNeeded();
await this._emitInitEventOnce();

runner.init();

Expand Down Expand Up @@ -267,7 +266,7 @@ export class Testplane extends BaseTestplane {
const testReader = TestReader.create(this._config);

if (!silent) {
await this._init();
await this._emitInitEventOnce();

eventsUtils.passthroughEvent(testReader, this, [
MasterEvents.BEFORE_FILE_READ,
Expand Down
2 changes: 1 addition & 1 deletion src/worker/testplane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class Testplane extends BaseTestplane {
}

async init(): Promise<void> {
await this._init();
await this._emitInitEventOnce();

if (typeof expect === "undefined") {
// eslint-disable-next-line @typescript-eslint/no-var-requires
Expand Down
Loading