diff --git a/packages/playwright-test/src/loader/loaderMain.ts b/packages/playwright-test/src/loader/loaderMain.ts index a3bf5ac27a..21d07b3ecc 100644 --- a/packages/playwright-test/src/loader/loaderMain.ts +++ b/packages/playwright-test/src/loader/loaderMain.ts @@ -21,10 +21,12 @@ import type { FullConfigInternal } from '../common/types'; import { loadTestFile } from '../common/testLoader'; import type { TestError } from '../../reporter'; import { addToCompilationCache, serializeCompilationCache } from '../common/compilationCache'; +import { PoolBuilder } from '../common/poolBuilder'; export class LoaderMain extends ProcessRunner { private _serializedConfig: SerializedConfig; private _configPromise: Promise | undefined; + private _poolBuilder = PoolBuilder.createForLoader(); constructor(serializedConfig: SerializedConfig) { super(); @@ -42,6 +44,7 @@ export class LoaderMain extends ProcessRunner { const testErrors: TestError[] = []; const config = await this._config(); const fileSuite = await loadTestFile(params.file, config.rootDir, testErrors); + this._poolBuilder.buildPools(fileSuite); return { fileSuite: fileSuite._deepSerialize(), testErrors }; } diff --git a/packages/playwright-test/src/runner/loadUtils.ts b/packages/playwright-test/src/runner/loadUtils.ts index 2fe2002418..fb14806f9c 100644 --- a/packages/playwright-test/src/runner/loadUtils.ts +++ b/packages/playwright-test/src/runner/loadUtils.ts @@ -17,7 +17,6 @@ import path from 'path'; import type { Reporter, TestError } from '../../types/testReporter'; import { InProcessLoaderHost, OutOfProcessLoaderHost } from './loaderHost'; -import type { LoaderHost } from './loaderHost'; import { Suite } from '../common/test'; import type { TestCase } from '../common/test'; import type { FullConfigInternal, FullProjectInternal } from '../common/types'; @@ -81,7 +80,7 @@ export async function loadAllTests(mode: 'out-of-process' | 'in-process', config // Load all test files and create a preprocessed root. Child suites are files there. const fileSuits: Suite[] = []; { - const loaderHost: LoaderHost = mode === 'out-of-process' ? new OutOfProcessLoaderHost(config) : new InProcessLoaderHost(config); + const loaderHost = mode === 'out-of-process' ? new OutOfProcessLoaderHost(config) : new InProcessLoaderHost(config); const allTestFiles = new Set(); for (const files of filesToRunByProject.values()) files.forEach(file => allTestFiles.add(file)); diff --git a/packages/playwright-test/src/runner/loaderHost.ts b/packages/playwright-test/src/runner/loaderHost.ts index 30390aa7c0..d54197b88c 100644 --- a/packages/playwright-test/src/runner/loaderHost.ts +++ b/packages/playwright-test/src/runner/loaderHost.ts @@ -19,13 +19,12 @@ import { serializeConfig } from '../common/ipc'; import { ProcessHost } from './processHost'; import { Suite } from '../common/test'; import { loadTestFile } from '../common/testLoader'; -import type { LoadError } from '../common/fixtures'; import type { FullConfigInternal } from '../common/types'; import { PoolBuilder } from '../common/poolBuilder'; import { addToCompilationCache } from '../common/compilationCache'; -export abstract class LoaderHost { - protected _config: FullConfigInternal; +export class InProcessLoaderHost { + private _config: FullConfigInternal; private _poolBuilder: PoolBuilder; constructor(config: FullConfigInternal) { @@ -34,41 +33,31 @@ export abstract class LoaderHost { } async loadTestFile(file: string, testErrors: TestError[]): Promise { - const result = await this.doLoadTestFile(file, testErrors); + const result = await loadTestFile(file, this._config.rootDir, testErrors); this._poolBuilder.buildPools(result, testErrors); return result; } - protected abstract doLoadTestFile(file: string, testErrors: TestError[]): Promise; - async stop() {} } -export class InProcessLoaderHost extends LoaderHost { - - doLoadTestFile(file: string, testErrors: TestError[]): Promise { - return loadTestFile(file, this._config.rootDir, testErrors); - } -} - -export class OutOfProcessLoaderHost extends LoaderHost { +export class OutOfProcessLoaderHost { private _startPromise: Promise; private _processHost: ProcessHost; constructor(config: FullConfigInternal) { - super(config); this._processHost = new ProcessHost(require.resolve('../loader/loaderMain.js'), 'loader'); this._startPromise = this._processHost.startRunner(serializeConfig(config), true, {}); } - async doLoadTestFile(file: string, loadErrors: LoadError[]): Promise { + async loadTestFile(file: string, testErrors: TestError[]): Promise { await this._startPromise; const result = await this._processHost.sendMessage({ method: 'loadTestFile', params: { file } }) as any; - loadErrors.push(...result.testErrors); + testErrors.push(...result.testErrors); return Suite._deepParse(result.fileSuite); } - override async stop() { + async stop() { await this._startPromise; const result = await this._processHost.sendMessage({ method: 'serializeCompilationCache' }) as any; addToCompilationCache(result);