From a9db22be886882d8ac6ba097014fc93913523df0 Mon Sep 17 00:00:00 2001 From: Jonatas Soares Date: Sun, 15 Nov 2026 15:40:26 -0300 Subject: [PATCH 1/2] perf(report): avoid copying accumulated Markdown file results Append each result to one array per target/file group instead of copying every earlier entry on each append. The comparator, result order, display cap and rendered output are unchanged. Fixes #1802 --- .changeset/markdown-result-groups.md | 5 ++ packages/e2e/src/report/markdown.ts | 7 ++- .../e2e/tests/unit/report-markdown.test.ts | 48 +++++++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 .changeset/markdown-result-groups.md diff --git a/.changeset/markdown-result-groups.md b/.changeset/markdown-result-groups.md new file mode 100644 index 000000000..9a8170892 --- /dev/null +++ b/.changeset/markdown-result-groups.md @@ -0,0 +1,5 @@ +--- +"e2e": patch +--- + +Avoid copying earlier results each time the Markdown reporter adds a result to a file group. diff --git a/packages/e2e/src/report/markdown.ts b/packages/e2e/src/report/markdown.ts index 938693f46..7682e2a70 100644 --- a/packages/e2e/src/report/markdown.ts +++ b/packages/e2e/src/report/markdown.ts @@ -415,7 +415,12 @@ function fileGroups(entries: readonly Entry[]): FileGroup[] { const groups = new Map>(); for (const entry of entries) { const byFile = groups.get(entry.result.targetId) ?? new Map(); - byFile.set(entry.result.file, [...(byFile.get(entry.result.file) ?? []), entry]); + let grouped = byFile.get(entry.result.file); + if (grouped === undefined) { + grouped = []; + byFile.set(entry.result.file, grouped); + } + grouped.push(entry); groups.set(entry.result.targetId, byFile); } const rows = [...groups].flatMap(([target, byFile]) => [...byFile].map(([file, grouped]) => ({ file, target, entries: grouped }))); diff --git a/packages/e2e/tests/unit/report-markdown.test.ts b/packages/e2e/tests/unit/report-markdown.test.ts index 1928f6199..ed5d39d05 100644 --- a/packages/e2e/tests/unit/report-markdown.test.ts +++ b/packages/e2e/tests/unit/report-markdown.test.ts @@ -18,6 +18,15 @@ import { REPORT_AT, reportAttempt, reportDocument, reportError, reportResult, re const FINISHED_AT = '2026-01-01T00:00:08.400Z'; +/** Freezes a report's nested inputs so rendering cannot change caller-owned data. */ +function freeze(value: T): T { + if (value !== null && typeof value === 'object') { + for (const child of Object.values(value)) freeze(child); + Object.freeze(value); + } + return value; +} + /** A document the page has something to say about: a version, a duration, one target. */ function page(overrides: Partial = {}): Report1Document { const status = overrides.status ?? 'passed'; @@ -475,6 +484,45 @@ describe('renderMarkdownReport', () => { ]); }); + it('keeps frozen repeated results in their target and file groups, with ties ordered by file then target', () => { + const shared = named({ title: 'first', file: 'tests/a.e2e.ts', status: 'passed', attempts: [attempt({ durationMs: 100 })] }); + const results = [ + { ...shared, targetId: 'web' }, + named({ title: 'last file', file: 'tests/z.e2e.ts', status: 'passed', attempts: [attempt({ durationMs: 100 })] }), + { ...shared, targetId: 'mobile' }, + { ...shared, repeat: 1 }, + named({ title: 'last in group', file: shared.file, status: 'passed', attempts: [attempt({ durationMs: 100 })] }), + ]; + const document = freeze(page({ results, targets: [reportTarget(), reportTarget({ id: 'mobile', index: 1 })] })); + const before = JSON.stringify(document); + const body = renderMarkdownReport(document); + const rows = body.split('\n').filter((line) => line.startsWith('| 馃煝 |')); + expect(rows).toEqual([ + '| 馃煝 | **tests/a.e2e.ts (mobile)** 路 1 passed | 100ms |', + '| 馃煝 | first | 100ms |', + '| 馃煝 | **tests/a.e2e.ts (web)** 路 3 passed | 300ms |', + '| 馃煝 | first | 100ms |', + '| 馃煝 | first (repeat #1) | 100ms |', + '| 馃煝 | last in group | 100ms |', + '| 馃煝 | **tests/z.e2e.ts (web)** 路 1 passed | 100ms |', + '| 馃煝 | last file | 100ms |', + ]); + expect(JSON.stringify(document)).toBe(before); + expect(document.run.results[0]).toBe(results[0]); + expect(renderMarkdownReport(freeze(page()))).not.toContain('
'); + }); + + it('counts every result in a dense frozen group before capping its displayed rows', () => { + const results = Array.from({ length: 401 }, (_, index) => named({ title: `dense ${index}`, status: 'passed', attempts: [attempt({ durationMs: 1 })] })); + const document = freeze(page({ results })); + const body = renderMarkdownReport(document); + expect(body).toContain('**tests/example.e2e.ts** 路 401 passed | 401ms |'); + expect(body).toContain('| 馃煝 | dense 399 | 1ms |'); + expect(body).not.toContain('| 馃煝 | dense 400 |'); + expect(body).toContain('| | and 1 more | |\n
'); + expect(document.run.results).toHaveLength(401); + }); + it('caps the folded list, saying how many more there are', () => { const results = Array.from({ length: 450 }, (_, index) => named({ title: `t${index}`, file: `tests/f${String(index).padStart(3, '0')}.e2e.ts`, status: 'passed', attempts: [attempt()] })); const body = renderMarkdownReport(page({ results })); From 0d710d2f7fbab981fbb17968c39cbebdd14cd73d Mon Sep 17 00:00:00 2001 From: Jonatas Soares Date: Sun, 15 Nov 2026 20:47:29 -0300 Subject: [PATCH 2/2] test(report): drop Markdown grouping tests and use a user-facing changeset Remove the two added tests and the freeze helper, as the existing Markdown tests already cover the changed lines. Reword the changeset for users and shorten the grouping loop; output and order are unchanged. --- .changeset/markdown-result-groups.md | 2 +- packages/e2e/src/report/markdown.ts | 9 ++-- .../e2e/tests/unit/report-markdown.test.ts | 48 ------------------- 3 files changed, 4 insertions(+), 55 deletions(-) diff --git a/.changeset/markdown-result-groups.md b/.changeset/markdown-result-groups.md index 9a8170892..9ffa070be 100644 --- a/.changeset/markdown-result-groups.md +++ b/.changeset/markdown-result-groups.md @@ -2,4 +2,4 @@ "e2e": patch --- -Avoid copying earlier results each time the Markdown reporter adds a result to a file group. +The Markdown summary renders faster for files with many results. Output is unchanged. diff --git a/packages/e2e/src/report/markdown.ts b/packages/e2e/src/report/markdown.ts index 7682e2a70..4e385c118 100644 --- a/packages/e2e/src/report/markdown.ts +++ b/packages/e2e/src/report/markdown.ts @@ -415,12 +415,9 @@ function fileGroups(entries: readonly Entry[]): FileGroup[] { const groups = new Map>(); for (const entry of entries) { const byFile = groups.get(entry.result.targetId) ?? new Map(); - let grouped = byFile.get(entry.result.file); - if (grouped === undefined) { - grouped = []; - byFile.set(entry.result.file, grouped); - } - grouped.push(entry); + const grouped = byFile.get(entry.result.file); + if (grouped) grouped.push(entry); + else byFile.set(entry.result.file, [entry]); groups.set(entry.result.targetId, byFile); } const rows = [...groups].flatMap(([target, byFile]) => [...byFile].map(([file, grouped]) => ({ file, target, entries: grouped }))); diff --git a/packages/e2e/tests/unit/report-markdown.test.ts b/packages/e2e/tests/unit/report-markdown.test.ts index ed5d39d05..1928f6199 100644 --- a/packages/e2e/tests/unit/report-markdown.test.ts +++ b/packages/e2e/tests/unit/report-markdown.test.ts @@ -18,15 +18,6 @@ import { REPORT_AT, reportAttempt, reportDocument, reportError, reportResult, re const FINISHED_AT = '2026-01-01T00:00:08.400Z'; -/** Freezes a report's nested inputs so rendering cannot change caller-owned data. */ -function freeze(value: T): T { - if (value !== null && typeof value === 'object') { - for (const child of Object.values(value)) freeze(child); - Object.freeze(value); - } - return value; -} - /** A document the page has something to say about: a version, a duration, one target. */ function page(overrides: Partial = {}): Report1Document { const status = overrides.status ?? 'passed'; @@ -484,45 +475,6 @@ describe('renderMarkdownReport', () => { ]); }); - it('keeps frozen repeated results in their target and file groups, with ties ordered by file then target', () => { - const shared = named({ title: 'first', file: 'tests/a.e2e.ts', status: 'passed', attempts: [attempt({ durationMs: 100 })] }); - const results = [ - { ...shared, targetId: 'web' }, - named({ title: 'last file', file: 'tests/z.e2e.ts', status: 'passed', attempts: [attempt({ durationMs: 100 })] }), - { ...shared, targetId: 'mobile' }, - { ...shared, repeat: 1 }, - named({ title: 'last in group', file: shared.file, status: 'passed', attempts: [attempt({ durationMs: 100 })] }), - ]; - const document = freeze(page({ results, targets: [reportTarget(), reportTarget({ id: 'mobile', index: 1 })] })); - const before = JSON.stringify(document); - const body = renderMarkdownReport(document); - const rows = body.split('\n').filter((line) => line.startsWith('| 馃煝 |')); - expect(rows).toEqual([ - '| 馃煝 | **tests/a.e2e.ts (mobile)** 路 1 passed | 100ms |', - '| 馃煝 | first | 100ms |', - '| 馃煝 | **tests/a.e2e.ts (web)** 路 3 passed | 300ms |', - '| 馃煝 | first | 100ms |', - '| 馃煝 | first (repeat #1) | 100ms |', - '| 馃煝 | last in group | 100ms |', - '| 馃煝 | **tests/z.e2e.ts (web)** 路 1 passed | 100ms |', - '| 馃煝 | last file | 100ms |', - ]); - expect(JSON.stringify(document)).toBe(before); - expect(document.run.results[0]).toBe(results[0]); - expect(renderMarkdownReport(freeze(page()))).not.toContain('
'); - }); - - it('counts every result in a dense frozen group before capping its displayed rows', () => { - const results = Array.from({ length: 401 }, (_, index) => named({ title: `dense ${index}`, status: 'passed', attempts: [attempt({ durationMs: 1 })] })); - const document = freeze(page({ results })); - const body = renderMarkdownReport(document); - expect(body).toContain('**tests/example.e2e.ts** 路 401 passed | 401ms |'); - expect(body).toContain('| 馃煝 | dense 399 | 1ms |'); - expect(body).not.toContain('| 馃煝 | dense 400 |'); - expect(body).toContain('| | and 1 more | |\n
'); - expect(document.run.results).toHaveLength(401); - }); - it('caps the folded list, saying how many more there are', () => { const results = Array.from({ length: 450 }, (_, index) => named({ title: `t${index}`, file: `tests/f${String(index).padStart(3, '0')}.e2e.ts`, status: 'passed', attempts: [attempt()] })); const body = renderMarkdownReport(page({ results }));