Skip to content

Commit b8761ef

Browse files
committed
cherry-pick(#23208): fix(html): fix the filter to respect status
1 parent 55eebad commit b8761ef

File tree

2 files changed

+71
-4
lines changed

2 files changed

+71
-4
lines changed

packages/html-reporter/src/filter.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export class Filter {
8484
token.push(c);
8585
continue;
8686
}
87-
if (c === ' ' || c === ':') {
87+
if (c === ' ') {
8888
if (token.length) {
8989
result.push(token.join('').toLowerCase());
9090
token = [];
@@ -108,9 +108,11 @@ export class Filter {
108108
if (test.outcome === 'skipped')
109109
status = 'skipped';
110110
const searchValues: SearchValues = {
111-
text: (status + ' ' + test.projectName + ' ' + test.location.file + ' ' + test.location.line + ' ' + test.path.join(' ') + ' ' + test.title).toLowerCase(),
111+
text: (status + ' ' + test.projectName + ' ' + test.location.file + ' ' + test.path.join(' ') + ' ' + test.title).toLowerCase(),
112112
project: test.projectName.toLowerCase(),
113113
status: status as any,
114+
file: test.location.file,
115+
line: String(test.location.line),
114116
};
115117
(test as any).searchValues = searchValues;
116118
}
@@ -127,9 +129,14 @@ export class Filter {
127129
return false;
128130
}
129131
if (this.text.length) {
130-
const matches = this.text.filter(t => searchValues.text.includes(t)).length === this.text.length;
131-
if (!matches)
132+
for (const text of this.text) {
133+
if (searchValues.text.includes(text))
134+
continue;
135+
const location = text.split(':');
136+
if (location.length === 2 && searchValues.file.includes(location[0]) && searchValues.line.includes(location[1]))
137+
continue;
132138
return false;
139+
}
133140
}
134141
if (this.labels.length) {
135142
const matches = this.labels.every(l => searchValues.text?.match(new RegExp(`(\\s|^)${escapeRegExp(l)}(\\s|$)`, 'g')));
@@ -145,5 +152,7 @@ type SearchValues = {
145152
text: string;
146153
project: string;
147154
status: 'passed' | 'failed' | 'flaky' | 'skipped';
155+
file: string;
156+
line: string;
148157
};
149158

tests/playwright-test/reporter-html.spec.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1881,3 +1881,61 @@ test('should list tests in the right order', async ({ runInlineTest, showReport,
18811881
/main second passes\d+m?ssecond.ts:5/,
18821882
]);
18831883
});
1884+
1885+
test('tests should filter by file', async ({ runInlineTest, showReport, page }) => {
1886+
const result = await runInlineTest({
1887+
'file-a.test.js': `
1888+
const { test } = require('@playwright/test');
1889+
test('a test 1', async ({}) => {});
1890+
test('a test 2', async ({}) => {});
1891+
`,
1892+
'file-b.test.js': `
1893+
const { test } = require('@playwright/test');
1894+
test('b test 1', async ({}) => {});
1895+
test('b test 2', async ({}) => {});
1896+
`,
1897+
}, { reporter: 'dot,html' }, { PW_TEST_HTML_REPORT_OPEN: 'never' });
1898+
1899+
expect(result.exitCode).toBe(0);
1900+
expect(result.passed).toBe(4);
1901+
expect(result.failed).toBe(0);
1902+
1903+
await showReport();
1904+
1905+
const searchInput = page.locator('.subnav-search-input');
1906+
1907+
await searchInput.fill('file-a');
1908+
await expect(page.getByText('file-a.test.js', { exact: true })).toBeVisible();
1909+
await expect(page.getByText('a test 1')).toBeVisible();
1910+
await expect(page.getByText('a test 2')).toBeVisible();
1911+
await expect(page.getByText('file-b.test.js', { exact: true })).not.toBeVisible();
1912+
await expect(page.getByText('b test 1')).not.toBeVisible();
1913+
await expect(page.getByText('b test 2')).not.toBeVisible();
1914+
1915+
await searchInput.fill('file-a:3');
1916+
await expect(page.getByText('a test 1')).toBeVisible();
1917+
await expect(page.getByText('a test 2')).not.toBeVisible();
1918+
});
1919+
1920+
test('tests should filter by status', async ({ runInlineTest, showReport, page }) => {
1921+
const result = await runInlineTest({
1922+
'a.test.js': `
1923+
const { test, expect } = require('@playwright/test');
1924+
test('failed title', async ({}) => { expect(1).toBe(1); });
1925+
test('passes title', async ({}) => { expect(1).toBe(2); });
1926+
`,
1927+
}, { reporter: 'dot,html' }, { PW_TEST_HTML_REPORT_OPEN: 'never' });
1928+
1929+
expect(result.exitCode).toBe(1);
1930+
expect(result.passed).toBe(1);
1931+
expect(result.failed).toBe(1);
1932+
1933+
await showReport();
1934+
1935+
const searchInput = page.locator('.subnav-search-input');
1936+
1937+
await searchInput.fill('s:failed');
1938+
await expect(page.getByText('a.test.js', { exact: true })).toBeVisible();
1939+
await expect(page.getByText('failed title')).not.toBeVisible();
1940+
await expect(page.getByText('passes title')).toBeVisible();
1941+
});

0 commit comments

Comments
 (0)