chore: expose find related files over test server (#29604)
This commit is contained in:
parent
92b1b16041
commit
ac0787d0c8
|
|
@ -34,7 +34,7 @@ import { program } from 'playwright-core/lib/cli/program';
|
||||||
export { program } from 'playwright-core/lib/cli/program';
|
export { program } from 'playwright-core/lib/cli/program';
|
||||||
import type { ReporterDescription } from '../types/test';
|
import type { ReporterDescription } from '../types/test';
|
||||||
import { prepareErrorStack } from './reporters/base';
|
import { prepareErrorStack } from './reporters/base';
|
||||||
import { affectedTestFiles, cacheDir } from './transform/compilationCache';
|
import { cacheDir } from './transform/compilationCache';
|
||||||
import { runTestServer } from './runner/testServer';
|
import { runTestServer } from './runner/testServer';
|
||||||
|
|
||||||
function addTestCommand(program: Command) {
|
function addTestCommand(program: Command) {
|
||||||
|
|
@ -102,17 +102,7 @@ function addFindRelatedTestFilesCommand(program: Command) {
|
||||||
command.description('Returns the list of related tests to the given files');
|
command.description('Returns the list of related tests to the given files');
|
||||||
command.option('-c, --config <file>', `Configuration file, or a test directory with optional "playwright.config.{m,c}?{js,ts}"`);
|
command.option('-c, --config <file>', `Configuration file, or a test directory with optional "playwright.config.{m,c}?{js,ts}"`);
|
||||||
command.action(async (files, options) => {
|
command.action(async (files, options) => {
|
||||||
await withRunnerAndMutedWrite(options.config, async (runner, config, configDir) => {
|
await withRunnerAndMutedWrite(options.config, runner => runner.findRelatedTestFiles('in-process', files));
|
||||||
const result = await runner.loadAllTests();
|
|
||||||
if (result.status !== 'passed' || !result.suite)
|
|
||||||
return { errors: result.errors };
|
|
||||||
|
|
||||||
const resolvedFiles = (files as string[]).map(file => path.resolve(process.cwd(), file));
|
|
||||||
const override = (config as any)['@playwright/test']?.['cli']?.['find-related-test-files'];
|
|
||||||
if (override)
|
|
||||||
return await override(resolvedFiles, config, configDir, result.suite);
|
|
||||||
return { testFiles: affectedTestFiles(resolvedFiles) };
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ import { InternalReporter } from '../reporters/internalReporter';
|
||||||
import { Multiplexer } from '../reporters/multiplexer';
|
import { Multiplexer } from '../reporters/multiplexer';
|
||||||
import type { Suite } from '../common/test';
|
import type { Suite } from '../common/test';
|
||||||
import { wrapReporterAsV2 } from '../reporters/reporterV2';
|
import { wrapReporterAsV2 } from '../reporters/reporterV2';
|
||||||
|
import { affectedTestFiles } from '../transform/compilationCache';
|
||||||
|
|
||||||
type ProjectConfigWithFiles = {
|
type ProjectConfigWithFiles = {
|
||||||
name: string;
|
name: string;
|
||||||
|
|
@ -44,6 +45,11 @@ type ConfigListFilesReport = {
|
||||||
error?: TestError;
|
error?: TestError;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type FindRelatedTestFilesReport = {
|
||||||
|
testFiles: string[];
|
||||||
|
errors?: TestError[];
|
||||||
|
};
|
||||||
|
|
||||||
export class Runner {
|
export class Runner {
|
||||||
private _config: FullConfigInternal;
|
private _config: FullConfigInternal;
|
||||||
|
|
||||||
|
|
@ -144,4 +150,16 @@ export class Runner {
|
||||||
webServerPluginsForConfig(config).forEach(p => config.plugins.push({ factory: p }));
|
webServerPluginsForConfig(config).forEach(p => config.plugins.push({ factory: p }));
|
||||||
return await runUIMode(config, options);
|
return await runUIMode(config, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async findRelatedTestFiles(mode: 'in-process' | 'out-of-process', files: string[]): Promise<FindRelatedTestFilesReport> {
|
||||||
|
const result = await this.loadAllTests(mode);
|
||||||
|
if (result.status !== 'passed' || !result.suite)
|
||||||
|
return { errors: result.errors, testFiles: [] };
|
||||||
|
|
||||||
|
const resolvedFiles = (files as string[]).map(file => path.resolve(process.cwd(), file));
|
||||||
|
const override = (this._config.config as any)['@playwright/test']?.['cli']?.['find-related-test-files'];
|
||||||
|
if (override)
|
||||||
|
return await override(resolvedFiles, this._config.config, this._config.configDir, result.suite);
|
||||||
|
return { testFiles: affectedTestFiles(resolvedFiles) };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,8 @@ import { Multiplexer } from '../reporters/multiplexer';
|
||||||
import { createReporters } from './reporters';
|
import { createReporters } from './reporters';
|
||||||
import { TestRun, createTaskRunnerForList, createTaskRunnerForTestServer } from './tasks';
|
import { TestRun, createTaskRunnerForList, createTaskRunnerForTestServer } from './tasks';
|
||||||
import type { ConfigCLIOverrides } from '../common/ipc';
|
import type { ConfigCLIOverrides } from '../common/ipc';
|
||||||
|
import { Runner } from './runner';
|
||||||
|
import type { FindRelatedTestFilesReport } from './runner';
|
||||||
|
|
||||||
type PlaywrightTestOptions = {
|
type PlaywrightTestOptions = {
|
||||||
headed?: boolean,
|
headed?: boolean,
|
||||||
|
|
@ -117,6 +119,12 @@ class Dispatcher {
|
||||||
await this._runTests(params.reporter, params.locations, params.options);
|
await this._runTests(params.reporter, params.locations, params.options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async findRelatedTestFiles(params: { files: string[] }): Promise<FindRelatedTestFilesReport> {
|
||||||
|
const config = await this._loadConfig({});
|
||||||
|
const runner = new Runner(config);
|
||||||
|
return runner.findRelatedTestFiles('out-of-process', params.files);
|
||||||
|
}
|
||||||
|
|
||||||
async stop() {
|
async stop() {
|
||||||
await this._stopTests();
|
await this._stopTests();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue