move populateDependencies call, only match on filenames
This commit is contained in:
parent
dda6532e52
commit
338790f4af
|
|
@ -119,7 +119,7 @@ export async function loadFileSuites(testRun: TestRun, mode: 'out-of-process' |
|
|||
}
|
||||
}
|
||||
|
||||
export async function createRootSuite(testRun: TestRun, errors: TestError[], shouldFilterOnly: boolean, onlyChangedFiles?: string[]): Promise<Suite> {
|
||||
export async function createRootSuite(testRun: TestRun, errors: TestError[], shouldFilterOnly: boolean, additionalFileMatcher?: Matcher): Promise<Suite> {
|
||||
const config = testRun.config;
|
||||
// Create root suite, where each child will be a project suite with cloned file suites inside it.
|
||||
const rootSuite = new Suite('', 'root');
|
||||
|
|
@ -130,16 +130,16 @@ export async function createRootSuite(testRun: TestRun, errors: TestError[], sho
|
|||
{
|
||||
// Interpret cli parameters.
|
||||
const cliFileFilters = createFileFiltersFromArguments(config.cliArgs);
|
||||
const onlyChangedFilters = onlyChangedFiles ? createFileFiltersFromArguments(onlyChangedFiles) : undefined;
|
||||
const grepMatcher = config.cliGrep ? createTitleMatcher(forceRegExp(config.cliGrep)) : () => true;
|
||||
const grepInvertMatcher = config.cliGrepInvert ? createTitleMatcher(forceRegExp(config.cliGrepInvert)) : () => false;
|
||||
const cliTitleMatcher = (title: string) => !grepInvertMatcher(title) && grepMatcher(title);
|
||||
|
||||
// Filter file suites for all projects.
|
||||
for (const [project, fileSuites] of testRun.projectSuites) {
|
||||
const projectSuite = createProjectSuite(project, fileSuites);
|
||||
const filteredFileSuites = additionalFileMatcher ? fileSuites.filter(fileSuite => additionalFileMatcher(fileSuite.location!.file)) : fileSuites;
|
||||
const projectSuite = createProjectSuite(project, filteredFileSuites);
|
||||
projectSuites.set(project, projectSuite);
|
||||
const filteredProjectSuite = filterProjectSuite(projectSuite, { cliFileFilters, cliTitleMatcher, testIdMatcher: config.testIdMatcher, onlyChangedFilters });
|
||||
const filteredProjectSuite = filterProjectSuite(projectSuite, { cliFileFilters, cliTitleMatcher, testIdMatcher: config.testIdMatcher });
|
||||
filteredProjectSuites.set(project, filteredProjectSuite);
|
||||
}
|
||||
}
|
||||
|
|
@ -225,16 +225,14 @@ function createProjectSuite(project: FullProjectInternal, fileSuites: Suite[]):
|
|||
return projectSuite;
|
||||
}
|
||||
|
||||
function filterProjectSuite(projectSuite: Suite, options: { cliFileFilters: TestFileFilter[], cliTitleMatcher?: Matcher, testIdMatcher?: Matcher, onlyChangedFilters?: TestFileFilter[] }): Suite {
|
||||
function filterProjectSuite(projectSuite: Suite, options: { cliFileFilters: TestFileFilter[], cliTitleMatcher?: Matcher, testIdMatcher?: Matcher }): Suite {
|
||||
// Fast path.
|
||||
if (!options.cliFileFilters.length && !options.cliTitleMatcher && !options.testIdMatcher && !options.onlyChangedFilters?.length)
|
||||
if (!options.cliFileFilters.length && !options.cliTitleMatcher && !options.testIdMatcher)
|
||||
return projectSuite;
|
||||
|
||||
const result = projectSuite._deepClone();
|
||||
if (options.cliFileFilters.length)
|
||||
filterByFocusedLine(result, options.cliFileFilters);
|
||||
if (options.onlyChangedFilters?.length)
|
||||
filterByFocusedLine(result, options.onlyChangedFilters);
|
||||
if (options.testIdMatcher)
|
||||
filterByTestIds(result, options.testIdMatcher);
|
||||
filterTestsRemoveEmptySuites(result, (test: TestCase) => {
|
||||
|
|
|
|||
|
|
@ -229,8 +229,16 @@ function createLoadTask(mode: 'out-of-process' | 'in-process', options: { filter
|
|||
setup: async (testRun, errors, softErrors) => {
|
||||
await collectProjectsAndTestFiles(testRun, !!options.doNotRunDepsOutsideProjectFilter, options.additionalFileMatcher);
|
||||
await loadFileSuites(testRun, mode, options.failOnLoadErrors ? errors : softErrors);
|
||||
const changedFiles = testRun.config.cliOnlyChanged ? await detectChangedFiles(testRun) : undefined;
|
||||
testRun.rootSuite = await createRootSuite(testRun, options.failOnLoadErrors ? errors : softErrors, !!options.filterOnly, changedFiles);
|
||||
|
||||
let cliOnlyChangedMatcher: Matcher | undefined = undefined;
|
||||
if (testRun.config.cliOnlyChanged) {
|
||||
for (const plugin of testRun.config.plugins)
|
||||
await plugin.instance?.populateDependencies?.();
|
||||
const changedFiles = await detectChangedFiles(testRun.config.cliOnlyChanged);
|
||||
cliOnlyChangedMatcher = file => changedFiles.includes(file);
|
||||
}
|
||||
|
||||
testRun.rootSuite = await createRootSuite(testRun, options.failOnLoadErrors ? errors : softErrors, !!options.filterOnly, cliOnlyChangedMatcher);
|
||||
testRun.failureTracker.onRootSuite(testRun.rootSuite);
|
||||
// Fail when no tests.
|
||||
if (options.failOnLoadErrors && !testRun.rootSuite.allTests().length && !testRun.config.cliPassWithNoTests && !testRun.config.config.shard) {
|
||||
|
|
|
|||
|
|
@ -17,12 +17,9 @@
|
|||
import childProcess from 'child_process';
|
||||
import { toPosixPath } from 'playwright-core/lib/utils';
|
||||
import { affectedTestFiles } from '../transform/compilationCache';
|
||||
import type { TestRun } from './tasks';
|
||||
import path from 'path';
|
||||
|
||||
export async function detectChangedFiles(testRun: TestRun): Promise<string[]> {
|
||||
const baseCommit = testRun.config.cliOnlyChanged;
|
||||
|
||||
export async function detectChangedFiles(baseCommit: string): Promise<string[]> {
|
||||
function gitFileList(command: string) {
|
||||
try {
|
||||
return childProcess.execSync(
|
||||
|
|
@ -46,9 +43,6 @@ export async function detectChangedFiles(testRun: TestRun): Promise<string[]> {
|
|||
const trackedFilesWithChanges = gitFileList(`diff ${baseCommit} --name-only`).map(file => path.join(gitRoot, file));
|
||||
|
||||
const filesWithChanges = [...untrackedFiles, ...trackedFilesWithChanges];
|
||||
|
||||
for (const plugin of testRun.config.plugins)
|
||||
await plugin.instance?.populateDependencies?.();
|
||||
const affectedFiles = affectedTestFiles(filesWithChanges);
|
||||
|
||||
return [
|
||||
|
|
|
|||
Loading…
Reference in a new issue