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 type { TestCase } from './test';
|
||||||
import { Suite } from './test';
|
import { Suite } from './test';
|
||||||
import type { Config, FullConfigInternal, FullProjectInternal, ReporterInternal } from './types';
|
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';
|
import type { Matcher, TestFileFilter } from './util';
|
||||||
|
|
||||||
const removeFolderAsync = promisify(rimraf);
|
const removeFolderAsync = promisify(rimraf);
|
||||||
|
|
@ -619,15 +619,11 @@ function filterByFocusedLine(suite: Suite, focusedTestFileLines: TestFileFilter[
|
||||||
if (!filterWithLine)
|
if (!filterWithLine)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const testFileLineMatches = (testFileName: string, testLine: number, testColumn: number) => focusedTestFileLines.some(({ re, exact, line, column }) => {
|
const testFileLineMatches = (testFileName: string, testLine: number, testColumn: number) => focusedTestFileLines.some(filter => {
|
||||||
const lineColumnOk = (line === testLine || line === null) && (column === testColumn || column === null);
|
const lineColumnOk = (filter.line === testLine || filter.line === null) && (filter.column === testColumn || filter.column === null);
|
||||||
if (!lineColumnOk)
|
if (!lineColumnOk)
|
||||||
return false;
|
return false;
|
||||||
if (re) {
|
return createFileMatcherFromFilters([filter])(testFileName);
|
||||||
re.lastIndex = 0;
|
|
||||||
return re.test(testFileName);
|
|
||||||
}
|
|
||||||
return testFileName === exact;
|
|
||||||
});
|
});
|
||||||
const suiteFilter = (suite: Suite) => {
|
const suiteFilter = (suite: Suite) => {
|
||||||
return !!suite.location && testFileLineMatches(suite.location.file, suite.location.line, suite.location.column);
|
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 {
|
function fileMatcherFrom(testFileFilters?: TestFileFilter[]): Matcher {
|
||||||
if (testFileFilters?.length)
|
if (testFileFilters?.length)
|
||||||
return createFileMatcher(testFileFilters.map(e => e.re || e.exact || ''));
|
return createFileMatcherFromFilters(testFileFilters);
|
||||||
return () => true;
|
return () => true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -108,6 +108,10 @@ export type TestFileFilter = {
|
||||||
column: number | null;
|
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 {
|
export function createFileMatcher(patterns: string | RegExp | (string | RegExp)[]): Matcher {
|
||||||
const reList: RegExp[] = [];
|
const reList: RegExp[] = [];
|
||||||
const filePatterns: string[] = [];
|
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('no-wrong-column', () => { expect(1).toBe(2); });
|
||||||
pwt.test('yes-no-column-specified', () => { expect(1).toBe(1); });
|
pwt.test('yes-no-column-specified', () => { expect(1).toBe(1); });
|
||||||
pwt.test('no-match', () => { 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.exitCode).toBe(0);
|
||||||
expect(result.skipped).toBe(0);
|
expect(result.skipped).toBe(0);
|
||||||
expect(result.passed).toBe(2);
|
expect(result.passed).toBe(3);
|
||||||
expect(result.report.suites[0].specs.map(spec => spec.title)).toEqual(['yes-full-match', 'yes-no-column-specified']);
|
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 }) => {
|
test('line should override focused test', async ({ runInlineTest }) => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue