chore: calcular pool digests on the loader process side (#20728)
This commit is contained in:
parent
b67cef2c4d
commit
96f0674e41
|
|
@ -21,10 +21,12 @@ import type { FullConfigInternal } from '../common/types';
|
||||||
import { loadTestFile } from '../common/testLoader';
|
import { loadTestFile } from '../common/testLoader';
|
||||||
import type { TestError } from '../../reporter';
|
import type { TestError } from '../../reporter';
|
||||||
import { addToCompilationCache, serializeCompilationCache } from '../common/compilationCache';
|
import { addToCompilationCache, serializeCompilationCache } from '../common/compilationCache';
|
||||||
|
import { PoolBuilder } from '../common/poolBuilder';
|
||||||
|
|
||||||
export class LoaderMain extends ProcessRunner {
|
export class LoaderMain extends ProcessRunner {
|
||||||
private _serializedConfig: SerializedConfig;
|
private _serializedConfig: SerializedConfig;
|
||||||
private _configPromise: Promise<FullConfigInternal> | undefined;
|
private _configPromise: Promise<FullConfigInternal> | undefined;
|
||||||
|
private _poolBuilder = PoolBuilder.createForLoader();
|
||||||
|
|
||||||
constructor(serializedConfig: SerializedConfig) {
|
constructor(serializedConfig: SerializedConfig) {
|
||||||
super();
|
super();
|
||||||
|
|
@ -42,6 +44,7 @@ export class LoaderMain extends ProcessRunner {
|
||||||
const testErrors: TestError[] = [];
|
const testErrors: TestError[] = [];
|
||||||
const config = await this._config();
|
const config = await this._config();
|
||||||
const fileSuite = await loadTestFile(params.file, config.rootDir, testErrors);
|
const fileSuite = await loadTestFile(params.file, config.rootDir, testErrors);
|
||||||
|
this._poolBuilder.buildPools(fileSuite);
|
||||||
return { fileSuite: fileSuite._deepSerialize(), testErrors };
|
return { fileSuite: fileSuite._deepSerialize(), testErrors };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import type { Reporter, TestError } from '../../types/testReporter';
|
import type { Reporter, TestError } from '../../types/testReporter';
|
||||||
import { InProcessLoaderHost, OutOfProcessLoaderHost } from './loaderHost';
|
import { InProcessLoaderHost, OutOfProcessLoaderHost } from './loaderHost';
|
||||||
import type { LoaderHost } from './loaderHost';
|
|
||||||
import { Suite } from '../common/test';
|
import { Suite } from '../common/test';
|
||||||
import type { TestCase } from '../common/test';
|
import type { TestCase } from '../common/test';
|
||||||
import type { FullConfigInternal, FullProjectInternal } from '../common/types';
|
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.
|
// Load all test files and create a preprocessed root. Child suites are files there.
|
||||||
const fileSuits: Suite[] = [];
|
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<string>();
|
const allTestFiles = new Set<string>();
|
||||||
for (const files of filesToRunByProject.values())
|
for (const files of filesToRunByProject.values())
|
||||||
files.forEach(file => allTestFiles.add(file));
|
files.forEach(file => allTestFiles.add(file));
|
||||||
|
|
|
||||||
|
|
@ -19,13 +19,12 @@ import { serializeConfig } from '../common/ipc';
|
||||||
import { ProcessHost } from './processHost';
|
import { ProcessHost } from './processHost';
|
||||||
import { Suite } from '../common/test';
|
import { Suite } from '../common/test';
|
||||||
import { loadTestFile } from '../common/testLoader';
|
import { loadTestFile } from '../common/testLoader';
|
||||||
import type { LoadError } from '../common/fixtures';
|
|
||||||
import type { FullConfigInternal } from '../common/types';
|
import type { FullConfigInternal } from '../common/types';
|
||||||
import { PoolBuilder } from '../common/poolBuilder';
|
import { PoolBuilder } from '../common/poolBuilder';
|
||||||
import { addToCompilationCache } from '../common/compilationCache';
|
import { addToCompilationCache } from '../common/compilationCache';
|
||||||
|
|
||||||
export abstract class LoaderHost {
|
export class InProcessLoaderHost {
|
||||||
protected _config: FullConfigInternal;
|
private _config: FullConfigInternal;
|
||||||
private _poolBuilder: PoolBuilder;
|
private _poolBuilder: PoolBuilder;
|
||||||
|
|
||||||
constructor(config: FullConfigInternal) {
|
constructor(config: FullConfigInternal) {
|
||||||
|
|
@ -34,41 +33,31 @@ export abstract class LoaderHost {
|
||||||
}
|
}
|
||||||
|
|
||||||
async loadTestFile(file: string, testErrors: TestError[]): Promise<Suite> {
|
async loadTestFile(file: string, testErrors: TestError[]): Promise<Suite> {
|
||||||
const result = await this.doLoadTestFile(file, testErrors);
|
const result = await loadTestFile(file, this._config.rootDir, testErrors);
|
||||||
this._poolBuilder.buildPools(result, testErrors);
|
this._poolBuilder.buildPools(result, testErrors);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract doLoadTestFile(file: string, testErrors: TestError[]): Promise<Suite>;
|
|
||||||
|
|
||||||
async stop() {}
|
async stop() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class InProcessLoaderHost extends LoaderHost {
|
export class OutOfProcessLoaderHost {
|
||||||
|
|
||||||
doLoadTestFile(file: string, testErrors: TestError[]): Promise<Suite> {
|
|
||||||
return loadTestFile(file, this._config.rootDir, testErrors);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class OutOfProcessLoaderHost extends LoaderHost {
|
|
||||||
private _startPromise: Promise<void>;
|
private _startPromise: Promise<void>;
|
||||||
private _processHost: ProcessHost;
|
private _processHost: ProcessHost;
|
||||||
|
|
||||||
constructor(config: FullConfigInternal) {
|
constructor(config: FullConfigInternal) {
|
||||||
super(config);
|
|
||||||
this._processHost = new ProcessHost(require.resolve('../loader/loaderMain.js'), 'loader');
|
this._processHost = new ProcessHost(require.resolve('../loader/loaderMain.js'), 'loader');
|
||||||
this._startPromise = this._processHost.startRunner(serializeConfig(config), true, {});
|
this._startPromise = this._processHost.startRunner(serializeConfig(config), true, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
async doLoadTestFile(file: string, loadErrors: LoadError[]): Promise<Suite> {
|
async loadTestFile(file: string, testErrors: TestError[]): Promise<Suite> {
|
||||||
await this._startPromise;
|
await this._startPromise;
|
||||||
const result = await this._processHost.sendMessage({ method: 'loadTestFile', params: { file } }) as any;
|
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);
|
return Suite._deepParse(result.fileSuite);
|
||||||
}
|
}
|
||||||
|
|
||||||
override async stop() {
|
async stop() {
|
||||||
await this._startPromise;
|
await this._startPromise;
|
||||||
const result = await this._processHost.sendMessage({ method: 'serializeCompilationCache' }) as any;
|
const result = await this._processHost.sendMessage({ method: 'serializeCompilationCache' }) as any;
|
||||||
addToCompilationCache(result);
|
addToCompilationCache(result);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue