fix(html): fix the filter to respect status (#23208)

This commit is contained in:
Pavel Feldman 2023-05-22 15:35:19 -07:00 committed by GitHub
parent ee3864913a
commit b9e7a91368
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 4 deletions

View File

@ -84,7 +84,7 @@ export class Filter {
token.push(c);
continue;
}
if (c === ' ' || c === ':') {
if (c === ' ') {
if (token.length) {
result.push(token.join('').toLowerCase());
token = [];
@ -108,9 +108,11 @@ export class Filter {
if (test.outcome === 'skipped')
status = 'skipped';
const searchValues: SearchValues = {
text: (status + ' ' + test.projectName + ' ' + test.location.file + ' ' + test.location.line + ' ' + test.path.join(' ') + ' ' + test.title).toLowerCase(),
text: (status + ' ' + test.projectName + ' ' + test.location.file + ' ' + test.path.join(' ') + ' ' + test.title).toLowerCase(),
project: test.projectName.toLowerCase(),
status: status as any,
file: test.location.file,
line: String(test.location.line),
};
(test as any).searchValues = searchValues;
}
@ -127,9 +129,14 @@ export class Filter {
return false;
}
if (this.text.length) {
const matches = this.text.filter(t => searchValues.text.includes(t)).length === this.text.length;
if (!matches)
for (const text of this.text) {
if (searchValues.text.includes(text))
continue;
const location = text.split(':');
if (location.length === 2 && searchValues.file.includes(location[0]) && searchValues.line.includes(location[1]))
continue;
return false;
}
}
if (this.labels.length) {
const matches = this.labels.every(l => searchValues.text?.match(new RegExp(`(\\s|^)${escapeRegExp(l)}(\\s|$)`, 'g')));
@ -145,5 +152,7 @@ type SearchValues = {
text: string;
project: string;
status: 'passed' | 'failed' | 'flaky' | 'skipped';
file: string;
line: string;
};

View File

@ -1916,3 +1916,26 @@ test('tests should filter by file', async ({ runInlineTest, showReport, page })
await expect(page.getByText('a test 1')).toBeVisible();
await expect(page.getByText('a test 2')).not.toBeVisible();
});
test('tests should filter by status', async ({ runInlineTest, showReport, page }) => {
const result = await runInlineTest({
'a.test.js': `
const { test, expect } = require('@playwright/test');
test('failed title', async ({}) => { expect(1).toBe(1); });
test('passes title', async ({}) => { expect(1).toBe(2); });
`,
}, { reporter: 'dot,html' }, { PW_TEST_HTML_REPORT_OPEN: 'never' });
expect(result.exitCode).toBe(1);
expect(result.passed).toBe(1);
expect(result.failed).toBe(1);
await showReport();
const searchInput = page.locator('.subnav-search-input');
await searchInput.fill('s:failed');
await expect(page.getByText('a.test.js', { exact: true })).toBeVisible();
await expect(page.getByText('failed title')).not.toBeVisible();
await expect(page.getByText('passes title')).toBeVisible();
});