diff --git a/packages/playwright-test/src/reporters/html.ts b/packages/playwright-test/src/reporters/html.ts index 7e3d6578e9..0e8c4c6655 100644 --- a/packages/playwright-test/src/reporters/html.ts +++ b/packages/playwright-test/src/reporters/html.ts @@ -258,9 +258,7 @@ class HtmlBuilder { const testCaseSummaryComparator = (t1: TestCaseSummary, t2: TestCaseSummary) => { const w1 = (t1.outcome === 'unexpected' ? 1000 : 0) + (t1.outcome === 'flaky' ? 1 : 0); const w2 = (t2.outcome === 'unexpected' ? 1000 : 0) + (t2.outcome === 'flaky' ? 1 : 0); - if (w2 - w1) - return w2 - w1; - return t1.location.line - t2.location.line; + return w2 - w1; }; testFileSummary.tests.sort(testCaseSummaryComparator); diff --git a/tests/playwright-test/reporter-html.spec.ts b/tests/playwright-test/reporter-html.spec.ts index 17560a5874..7a0a328f15 100644 --- a/tests/playwright-test/reporter-html.spec.ts +++ b/tests/playwright-test/reporter-html.spec.ts @@ -1669,4 +1669,52 @@ test.describe('labels', () => { await expect(page.locator('.chip', { hasText: 'b.test.js' })).toHaveCount(1); await expect(page.locator('.chip', { hasText: 'c.test.js' })).toHaveCount(1); }); -}); \ No newline at end of file +}); + +test('should list tests in the right order', async ({ runInlineTest, showReport, page }) => { + await runInlineTest({ + 'main.spec.ts': ` + import firstTest from './first'; + import secondTest from './second'; + import { test, expect } from '@playwright/test'; + + test.describe('main', () => { + test.describe('first', firstTest); + test.describe('second', secondTest); + test('fails', () => { + expect(1).toBe(2); + }); + }); + `, + 'first.ts': ` + import { test, expect } from '@playwright/test'; + + // comments to change the line number + // comment + // comment + // comment + // comment + // comment + // comment + export default function() { + test('passes', () => {}); + } + `, + 'second.ts': ` + import { test, expect } from '@playwright/test'; + + export default function() { + test('passes', () => {}); + } + `, + }, { reporter: 'html' }, { PW_TEST_HTML_REPORT_OPEN: 'never' }); + + await showReport(); + + // Failing test first, then sorted by the run order. + await expect(page.locator('.test-file-test')).toHaveText([ + /main › fails\d+m?smain.spec.ts:9/, + /main › first › passes\d+m?sfirst.ts:12/, + /main › second › passes\d+m?ssecond.ts:5/, + ]); +});