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