fix(pwtest): fix focused line with dirname specified (#18189)
This commit is contained in:
parent
852a5c234b
commit
af38449f42
|
|
@ -44,7 +44,7 @@ import { SigIntWatcher } from './sigIntWatcher';
|
|||
import type { TestCase } from './test';
|
||||
import { Suite } from './test';
|
||||
import type { Config, FullConfigInternal, FullProjectInternal, ReporterInternal } from './types';
|
||||
import { createFileMatcher, createTitleMatcher, serializeError } from './util';
|
||||
import { createFileMatcher, createFileMatcherFromFilters, createTitleMatcher, serializeError } from './util';
|
||||
import type { Matcher, TestFileFilter } from './util';
|
||||
|
||||
const removeFolderAsync = promisify(rimraf);
|
||||
|
|
@ -619,15 +619,11 @@ function filterByFocusedLine(suite: Suite, focusedTestFileLines: TestFileFilter[
|
|||
if (!filterWithLine)
|
||||
return;
|
||||
|
||||
const testFileLineMatches = (testFileName: string, testLine: number, testColumn: number) => focusedTestFileLines.some(({ re, exact, line, column }) => {
|
||||
const lineColumnOk = (line === testLine || line === null) && (column === testColumn || column === null);
|
||||
const testFileLineMatches = (testFileName: string, testLine: number, testColumn: number) => focusedTestFileLines.some(filter => {
|
||||
const lineColumnOk = (filter.line === testLine || filter.line === null) && (filter.column === testColumn || filter.column === null);
|
||||
if (!lineColumnOk)
|
||||
return false;
|
||||
if (re) {
|
||||
re.lastIndex = 0;
|
||||
return re.test(testFileName);
|
||||
}
|
||||
return testFileName === exact;
|
||||
return createFileMatcherFromFilters([filter])(testFileName);
|
||||
});
|
||||
const suiteFilter = (suite: Suite) => {
|
||||
return !!suite.location && testFileLineMatches(suite.location.file, suite.location.line, suite.location.column);
|
||||
|
|
@ -898,7 +894,7 @@ class ListModeReporter implements Reporter {
|
|||
|
||||
function fileMatcherFrom(testFileFilters?: TestFileFilter[]): Matcher {
|
||||
if (testFileFilters?.length)
|
||||
return createFileMatcher(testFileFilters.map(e => e.re || e.exact || ''));
|
||||
return createFileMatcherFromFilters(testFileFilters);
|
||||
return () => true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -108,6 +108,10 @@ export type TestFileFilter = {
|
|||
column: number | null;
|
||||
};
|
||||
|
||||
export function createFileMatcherFromFilters(filters: TestFileFilter[]): Matcher {
|
||||
return createFileMatcher(filters.map(filter => filter.re || filter.exact || ''));
|
||||
}
|
||||
|
||||
export function createFileMatcher(patterns: string | RegExp | (string | RegExp)[]): Matcher {
|
||||
const reList: RegExp[] = [];
|
||||
const filePatterns: string[] = [];
|
||||
|
|
|
|||
|
|
@ -60,12 +60,13 @@ test('should filter by line and column', async ({ runInlineTest }) => {
|
|||
pwt.test('no-wrong-column', () => { expect(1).toBe(2); });
|
||||
pwt.test('yes-no-column-specified', () => { expect(1).toBe(1); });
|
||||
pwt.test('no-match', () => { expect(1).toBe(1); });
|
||||
pwt.test('yes-full-match-with-dirname', () => { expect(1).toBe(1); });
|
||||
`,
|
||||
}, undefined, undefined, { additionalArgs: ['x.spec.js:5:11', 'x.spec.js:6:99999', 'x.spec.js:7'] });
|
||||
}, undefined, undefined, { additionalArgs: ['x.spec.js:5:11', 'x.spec.js:6:99999', 'x.spec.js:7', 'foo/x.spec.js:9:11'] });
|
||||
expect(result.exitCode).toBe(0);
|
||||
expect(result.skipped).toBe(0);
|
||||
expect(result.passed).toBe(2);
|
||||
expect(result.report.suites[0].specs.map(spec => spec.title)).toEqual(['yes-full-match', 'yes-no-column-specified']);
|
||||
expect(result.passed).toBe(3);
|
||||
expect(result.report.suites[0].specs.map(spec => spec.title)).toEqual(['yes-full-match', 'yes-no-column-specified', 'yes-full-match-with-dirname']);
|
||||
});
|
||||
|
||||
test('line should override focused test', async ({ runInlineTest }) => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue