Skip to content

Commit 1d9647b

Browse files
Skn0ttdgozman
andauthored
chore(ui/html): hide _ attachments (#35044)
Signed-off-by: Simon Knott <[email protected]> Co-authored-by: Dmitry Gozman <[email protected]>
1 parent f3a75e2 commit 1d9647b

File tree

4 files changed

+11
-24
lines changed

4 files changed

+11
-24
lines changed

packages/html-reporter/src/testResultView.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export const TestResultView: React.FC<{
7272
result: TestResult,
7373
}> = ({ test, result }) => {
7474
const { screenshots, videos, traces, otherAttachments, diffs, errors, otherAttachmentAnchors, screenshotAnchors } = React.useMemo(() => {
75-
const attachments = result.attachments;
75+
const attachments = result.attachments.filter(a => !a.name.startsWith('_'));
7676
const screenshots = new Set(attachments.filter(a => a.contentType.startsWith('image/')));
7777
const screenshotAnchors = [...screenshots].map(a => `attachment-${attachments.indexOf(a)}`);
7878
const videos = attachments.filter(a => a.contentType.startsWith('video/'));

packages/trace-viewer/src/ui/attachmentsTab.tsx

+2-10
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import * as React from 'react';
1818
import './attachmentsTab.css';
1919
import { ImageDiffView } from '@web/shared/imageDiffView';
20-
import type { MultiTraceModel } from './modelUtil';
20+
import type { Attachment, MultiTraceModel } from './modelUtil';
2121
import { PlaceholderPanel } from './placeholderPanel';
2222
import type { AfterActionTraceEventAttachment } from '@trace/trace';
2323
import { CodeMirrorWrapper, lineHeight } from '@web/components/codeMirrorWrapper';
@@ -26,8 +26,6 @@ import { Expandable } from '@web/components/expandable';
2626
import { linkifyText } from '@web/renderUtils';
2727
import { clsx, useFlash } from '@web/uiUtils';
2828

29-
type Attachment = AfterActionTraceEventAttachment & { traceUrl: string };
30-
3129
type ExpandableAttachmentProps = {
3230
attachment: Attachment;
3331
reveal?: any;
@@ -97,14 +95,8 @@ export const AttachmentsTab: React.FunctionComponent<{
9795
revealedAttachment?: [AfterActionTraceEventAttachment, number],
9896
}> = ({ model, revealedAttachment }) => {
9997
const { diffMap, screenshots, attachments } = React.useMemo(() => {
100-
const attachments = new Set<Attachment>();
98+
const attachments = new Set(model?.visibleAttachments ?? []);
10199
const screenshots = new Set<Attachment>();
102-
103-
for (const action of model?.actions || []) {
104-
const traceUrl = action.context.traceUrl;
105-
for (const attachment of action.attachments || [])
106-
attachments.add({ ...attachment, traceUrl });
107-
}
108100
const diffMap = new Map<string, { expected: Attachment | undefined, actual: Attachment | undefined, diff: Attachment | undefined }>();
109101

110102
for (const attachment of attachments) {

packages/trace-viewer/src/ui/modelUtil.ts

+7-9
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ export type ErrorDescription = {
5757
prompt?: trace.AfterActionTraceEventAttachment & { traceUrl: string };
5858
};
5959

60+
export type Attachment = trace.AfterActionTraceEventAttachment & { traceUrl: string };
61+
6062
export class MultiTraceModel {
6163
readonly startTime: number;
6264
readonly endTime: number;
@@ -68,6 +70,8 @@ export class MultiTraceModel {
6870
readonly options: trace.BrowserContextEventOptions;
6971
readonly pages: PageEntry[];
7072
readonly actions: ActionTraceEventInContext[];
73+
readonly attachments: Attachment[];
74+
readonly visibleAttachments: Attachment[];
7175
readonly events: (trace.EventTraceEvent | trace.ConsoleMessageTraceEvent)[];
7276
readonly stdio: trace.StdioTraceEvent[];
7377
readonly errors: trace.ErrorTraceEvent[];
@@ -103,6 +107,8 @@ export class MultiTraceModel {
103107
this.hasSource = contexts.some(c => c.hasSource);
104108
this.hasStepData = contexts.some(context => context.origin === 'testRunner');
105109
this.resources = [...contexts.map(c => c.resources)].flat();
110+
this.attachments = this.actions.flatMap(action => action.attachments?.map(attachment => ({ ...attachment, traceUrl: action.context.traceUrl })) ?? []);
111+
this.visibleAttachments = this.attachments.filter(attachment => !attachment.name.startsWith('_'));
106112

107113
this.events.sort((a1, a2) => a1.time - a2.time);
108114
this.resources.sort((a1, a2) => a1._monotonicTime! - a2._monotonicTime!);
@@ -130,18 +136,10 @@ export class MultiTraceModel {
130136
}
131137

132138
private _errorDescriptorsFromTestRunner(): ErrorDescription[] {
133-
const errorPrompts: Record<string, trace.AfterActionTraceEventAttachment & { traceUrl: string }> = {};
134-
for (const action of this.actions) {
135-
for (const attachment of action.attachments ?? []) {
136-
if (attachment.name.startsWith('_prompt-'))
137-
errorPrompts[attachment.name] = { ...attachment, traceUrl: action.context.traceUrl };
138-
}
139-
}
140-
141139
return this.errors.filter(e => !!e.message).map((error, i) => ({
142140
stack: error.stack,
143141
message: error.message,
144-
prompt: errorPrompts[`_prompt-${i}`],
142+
prompt: this.attachments.find(a => a.name === `_prompt-${i}`),
145143
}));
146144
}
147145
}

packages/trace-viewer/src/ui/workbench.tsx

+1-4
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,6 @@ export const Workbench: React.FunctionComponent<{
163163
const consoleModel = useConsoleTabModel(model, selectedTime);
164164
const networkModel = useNetworkTabModel(model, selectedTime);
165165
const errorsModel = useErrorsTabModel(model);
166-
const attachments = React.useMemo(() => {
167-
return model?.actions.map(a => a.attachments || []).flat() || [];
168-
}, [model]);
169166

170167
const sdkLanguage = model?.sdkLanguage || 'javascript';
171168

@@ -241,7 +238,7 @@ export const Workbench: React.FunctionComponent<{
241238
const attachmentsTab: TabbedPaneTabModel = {
242239
id: 'attachments',
243240
title: 'Attachments',
244-
count: attachments.length,
241+
count: model?.visibleAttachments.length,
245242
render: () => <AttachmentsTab model={model} revealedAttachment={revealedAttachment} />
246243
};
247244

0 commit comments

Comments
 (0)