Skip to content

Commit

Permalink
fix(html): do not update total time when filtering tests (microsoft#2…
Browse files Browse the repository at this point in the history
  • Loading branch information
yury-s authored Oct 26, 2023
1 parent 37ab683 commit 86c78c1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 26 deletions.
6 changes: 3 additions & 3 deletions packages/html-reporter/src/testFilesView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand Down
2 changes: 1 addition & 1 deletion tests/playwright-test/reporter-blob.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand Down
31 changes: 9 additions & 22 deletions tests/playwright-test/reporter-html.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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();

Expand Down Expand Up @@ -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');
Expand All @@ -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');
Expand Down

0 comments on commit 86c78c1

Please sign in to comment.