fix(html): do not update total time when filtering tests (#27808)

![image](https://github.com/microsoft/playwright/assets/9798949/491ef34d-6674-4242-a6f4-dcef048a18f5)


Fixes #27758
This commit is contained in:
Yury Semikhatsky 2023-10-26 08:20:14 -07:00 committed by GitHub
parent 37ab6832ab
commit 86c78c1e0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 26 deletions

View File

@ -45,12 +45,12 @@ export const TestFilesView: React.FC<{
return <>
<div className='mt-2 mx-1' style={{ display: 'flex' }}>
{projectNames.length === 1 && !!projectNames[0] && <div data-testid="project-name" style={{ color: 'var(--color-fg-subtle)' }}>Project: {projectNames[0]}</div>}
{!filter.empty() && <div data-testid="filtered-tests-count" style={{ color: 'var(--color-fg-subtle)', padding: '0 10px' }}>Filtered: {filteredStats.total}</div>}
{!filter.empty() && <div data-testid="filtered-tests-count" style={{ color: 'var(--color-fg-subtle)', padding: '0 10px' }}>Filtered: {filteredStats.total} {!!filteredStats.total && ('(' + msToString(filteredStats.duration) + ')')}</div>}
<div style={{ flex: 'auto' }}></div>
<div data-testid="overall-time" style={{ color: 'var(--color-fg-subtle)', marginRight: '10px' }}>{report ? new Date(report.startTime).toLocaleString() : ''}</div>
<div data-testid="overall-duration" style={{ color: 'var(--color-fg-subtle)' }}>Total time: {msToString(filteredStats.duration)}</div>
<div data-testid="overall-duration" style={{ color: 'var(--color-fg-subtle)' }}>Total time: {msToString(report?.duration ?? 0)}</div>
</div>
{report && report.errors.length && <AutoChip header='Errors' dataTestId='report-errors'>
{report && !!report.errors.length && <AutoChip header='Errors' dataTestId='report-errors'>
{report.errors.map((error, index) => <TestErrorView key={'test-report-error-message-' + index} error={error}></TestErrorView>)}
</AutoChip>}
{report && filteredFiles.map(({ file, defaultExpanded }) => {

View File

@ -388,7 +388,7 @@ test('total time is from test run not from merge', async ({ runInlineTest, merge
// "Total time: 2.1s"
const time = /Total time: (\d+)(\.\d+)?s/.exec(durationText);
expect(time).toBeTruthy();
expect(parseInt(time[1], 10)).toBeGreaterThan(2);
expect(parseInt(time[1], 10)).toBeGreaterThanOrEqual(2);
});
test('merge into list report by default', async ({ runInlineTest, mergeReports }) => {

View File

@ -1356,11 +1356,7 @@ for (const useIntermediateMergeReport of [false, true] as const) {
await expect(regressionLabelButton).not.toBeVisible();
{
const testDuration = await page.getByTestId('test-duration').textContent();
const totalDuration = await page.getByTestId('overall-duration').textContent();
expect(totalDuration).toBe('Total time: ' + testDuration);
}
await expect(page.getByTestId('overall-duration')).toHaveText(`Total time: ${msToString(result.report.stats.duration)}`);
await searchInput.clear();
@ -1376,11 +1372,7 @@ for (const useIntermediateMergeReport of [false, true] as const) {
await expect(page.locator('.chip', { hasText: 'b.test.js' })).toHaveCount(0);
await expect(page.locator('.test-file-test .test-file-title')).toHaveText('Error Pages @regression passes');
{
const testDuration = await page.getByTestId('test-duration').textContent();
const totalDuration = await page.getByTestId('overall-duration').textContent();
expect(totalDuration).toBe('Total time: ' + testDuration);
}
await expect(page.getByTestId('overall-duration')).toHaveText(`Total time: ${msToString(result.report.stats.duration)}`);
await searchInput.clear();
@ -1534,21 +1526,15 @@ for (const useIntermediateMergeReport of [false, true] as const) {
return total;
}
async function checkTotalDuration(testNames: string[]) {
for (const testDuration of await page.getByTestId('test-duration').allTextContents())
expect(testDuration).toMatch(/\d+m?s$/);
const expectedTotalTimeInMs = calculateTotalTestDuration(testNames);
await expect(page.getByTestId('overall-duration')).toHaveText(`Total time: ${msToString(expectedTotalTimeInMs)}`);
}
const searchInput = page.locator('.subnav-search-input');
await expect(page.getByTestId('filtered-tests-count')).not.toBeVisible();
await expect(page.getByTestId('overall-duration')).toHaveText(`Total time: ${msToString(result.report.stats.duration)}`);
await searchInput.fill('s:failed');
await expect(page.getByTestId('filtered-tests-count')).toHaveText('Filtered: 3');
await checkTotalDuration(['a-one foo', 'a-two foo', 'b-one foo']);
const threeTestsDuration = calculateTotalTestDuration(['a-one foo', 'a-two foo', 'b-one foo']);
await expect(page.getByTestId('filtered-tests-count')).toHaveText(`Filtered: 3 (${msToString(threeTestsDuration)})`);
await expect(page.getByTestId('overall-duration')).toHaveText(`Total time: ${msToString(result.report.stats.duration)}`);
await expect(page.locator('.subnav-item:has-text("All") .counter')).toHaveText('10');
await expect(page.locator('.subnav-item:has-text("Passed") .counter')).toHaveText('7');
await expect(page.locator('.subnav-item:has-text("Failed") .counter')).toHaveText('3');
@ -1559,8 +1545,9 @@ for (const useIntermediateMergeReport of [false, true] as const) {
await expect(page.getByTestId('filtered-tests-count')).not.toBeVisible();
await searchInput.fill('foo');
await expect(page.getByTestId('filtered-tests-count')).toHaveText('Filtered: 4');
await checkTotalDuration(['a-one foo', 'a-two foo', 'b-one foo', 'b-two foo']);
const fourTestsDuration = calculateTotalTestDuration(['a-one foo', 'a-two foo', 'b-one foo', 'b-two foo']);
await expect(page.getByTestId('filtered-tests-count')).toHaveText(`Filtered: 4 (${msToString(fourTestsDuration)})`);
await expect(page.getByTestId('overall-duration')).toHaveText(`Total time: ${msToString(result.report.stats.duration)}`);
await expect(page.locator('.subnav-item:has-text("All") .counter')).toHaveText('10');
await expect(page.locator('.subnav-item:has-text("Passed") .counter')).toHaveText('7');
await expect(page.locator('.subnav-item:has-text("Failed") .counter')).toHaveText('3');