replace separate task runner with an option for existing one
This commit is contained in:
parent
4310aa215d
commit
c91551249b
|
|
@ -22,7 +22,7 @@ import type { FullResult, TestError } from '../../types/testReporter';
|
|||
import { webServerPluginsForConfig } from '../plugins/webServerPlugin';
|
||||
import { collectFilesForProject, filterProjects } from './projectUtils';
|
||||
import { createReporters } from './reporters';
|
||||
import { TestRun, createTaskRunner, createTaskRunnerForFindRelatedTests, createTaskRunnerForList } from './tasks';
|
||||
import { TestRun, createTaskRunner, createTaskRunnerForList } from './tasks';
|
||||
import type { FullConfigInternal } from '../common/config';
|
||||
import { runWatchModeLoop } from './watchMode';
|
||||
import type { Suite } from '../common/test';
|
||||
|
|
@ -108,7 +108,7 @@ export class Runner {
|
|||
return status;
|
||||
}
|
||||
|
||||
async loadAllTests(mode: 'in-process' | 'out-of-process' = 'in-process'): Promise<{ status: FullResult['status'], suite?: Suite, errors: TestError[] }> {
|
||||
async loadAllTests(mode: 'in-process' | 'out-of-process' = 'in-process', options: { populatePluginDependencies?: boolean }): Promise<{ status: FullResult['status'], suite?: Suite, errors: TestError[] }> {
|
||||
const config = this._config;
|
||||
const errors: TestError[] = [];
|
||||
const reporters = [wrapReporterAsV2({
|
||||
|
|
@ -116,10 +116,8 @@ export class Runner {
|
|||
errors.push(error);
|
||||
}
|
||||
})];
|
||||
const taskRunner = createTaskRunnerForList(config, reporters, mode, { failOnLoadErrors: true });
|
||||
const taskRunner = createTaskRunnerForList(config, reporters, mode, { ...options, failOnLoadErrors: true });
|
||||
const testRun = new TestRun(config);
|
||||
taskRunner.reporter.onConfigure(config.config);
|
||||
|
||||
const status = await taskRunner.run(testRun, 0);
|
||||
return { status, suite: testRun.rootSuite, errors };
|
||||
}
|
||||
|
|
@ -131,8 +129,9 @@ export class Runner {
|
|||
}
|
||||
|
||||
async findRelatedTestFiles(mode: 'in-process' | 'out-of-process', files: string[]): Promise<FindRelatedTestFilesReport> {
|
||||
const taskRunner = createTaskRunnerForFindRelatedTests(this._config, mode);
|
||||
await taskRunner.run(new TestRun(this._config), 0);
|
||||
const result = await this.loadAllTests(mode, { populatePluginDependencies: true });
|
||||
if (result.status !== 'passed' || !result.suite)
|
||||
return { errors: result.errors, testFiles: [] };
|
||||
|
||||
const resolvedFiles = (files as string[]).map(file => path.resolve(process.cwd(), file));
|
||||
return { testFiles: affectedTestFiles(resolvedFiles) };
|
||||
|
|
|
|||
|
|
@ -106,18 +106,16 @@ function addRunTasks(taskRunner: TaskRunner<TestRun>, config: FullConfigInternal
|
|||
return taskRunner;
|
||||
}
|
||||
|
||||
export function createTaskRunnerForList(config: FullConfigInternal, reporters: ReporterV2[], mode: 'in-process' | 'out-of-process', options: { failOnLoadErrors: boolean }): TaskRunner<TestRun> {
|
||||
export function createTaskRunnerForList(config: FullConfigInternal, reporters: ReporterV2[], mode: 'in-process' | 'out-of-process', options: { failOnLoadErrors: boolean, populatePluginDependencies?: boolean }): TaskRunner<TestRun> {
|
||||
const taskRunner = TaskRunner.create<TestRun>(reporters, config.config.globalTimeout);
|
||||
taskRunner.addTask('load tests', createLoadTask(mode, { ...options, filterOnly: false }));
|
||||
taskRunner.addTask('report begin', createReportBeginTask());
|
||||
return taskRunner;
|
||||
}
|
||||
|
||||
export function createTaskRunnerForFindRelatedTests(config: FullConfigInternal, mode: 'in-process' | 'out-of-process'): TaskRunner<TestRun> {
|
||||
const taskRunner = TaskRunner.create<TestRun>([], config.config.globalTimeout);
|
||||
if (options.populatePluginDependencies) {
|
||||
for (const plugin of config.plugins)
|
||||
taskRunner.addTask('plugin setup', createPluginSetupTask(plugin));
|
||||
taskRunner.addTask('load tests', createLoadTask(mode, { filterOnly: false, populatePluginDependencies: true, failOnLoadErrors: false }));
|
||||
}
|
||||
|
||||
taskRunner.addTask('load tests', createLoadTask(mode, { ...options, filterOnly: false }));
|
||||
taskRunner.addTask('report begin', createReportBeginTask());
|
||||
return taskRunner;
|
||||
}
|
||||
|
||||
|
|
@ -155,6 +153,8 @@ function createPluginSetupTask(plugin: TestRunnerPluginRegistration): Task<TestR
|
|||
function createPluginBeginTask(plugin: TestRunnerPluginRegistration): Task<TestRun> {
|
||||
return {
|
||||
setup: async (reporter, { rootSuite }) => {
|
||||
if (!plugin.instance)
|
||||
throw new Error('Plugin not initialized');
|
||||
await plugin.instance?.begin?.(rootSuite!);
|
||||
},
|
||||
teardown: async () => {
|
||||
|
|
@ -237,8 +237,12 @@ function createLoadTask(mode: 'out-of-process' | 'in-process', options: { popula
|
|||
await loadFileSuites(testRun, mode, options.failOnLoadErrors ? errors : softErrors);
|
||||
|
||||
if (options.populatePluginDependencies || testRun.config.cliOnlyChanged) {
|
||||
for (const plugin of testRun.config.plugins)
|
||||
await plugin.instance?.populateDependencies?.();
|
||||
for (const plugin of testRun.config.plugins) {
|
||||
if (!plugin.instance)
|
||||
throw new Error('Plugin not initialized');
|
||||
|
||||
await plugin.instance.populateDependencies?.();
|
||||
}
|
||||
}
|
||||
|
||||
let cliOnlyChangedMatcher: Matcher | undefined = undefined;
|
||||
|
|
|
|||
Loading…
Reference in a new issue