MCPcopy
hub / github.com/microsoft/playwright / TraceView

Function TraceView

packages/trace-viewer/src/ui/uiModeTraceView.tsx:34–103  ·  view source on GitHub ↗
({ item, rootDir, onOpenExternally, revealSource, pathSeparator })

Source from the content-addressed store, hash-verified

32 revealSource?: boolean,
33 pathSeparator: string,
34}> = ({ item, rootDir, onOpenExternally, revealSource, pathSeparator }) => {
35 const [model, setModel] = React.useState<{ model: TraceModel, isLive: boolean } | undefined>(undefined);
36 const [counter, setCounter] = React.useState(0);
37 const pollTimer = React.useRef<NodeJS.Timeout | null>(null);
38
39 const { outputDir } = React.useMemo(() => {
40 const outputDir = item.testCase ? outputDirForTestCase(item.testCase) : undefined;
41 return { outputDir };
42 }, [item]);
43
44 React.useEffect(() => {
45 if (pollTimer.current)
46 clearTimeout(pollTimer.current);
47
48 const result = item.testCase?.results[0];
49 if (!result || item.treeItem?.status === 'scheduled') {
50 setModel(undefined);
51 return;
52 }
53
54 // Test finished.
55 const attachment = result && result.duration >= 0 && result.attachments.find(a => a.name === 'trace');
56 if (attachment && attachment.path) {
57 loadSingleTraceFile(attachment.path, result.startTime.getTime()).then(model => setModel({ model, isLive: false }));
58 return;
59 }
60
61 if (!outputDir) {
62 setModel(undefined);
63 return;
64 }
65
66 const traceLocation = [
67 outputDir,
68 artifactsFolderName(result.workerIndex),
69 'traces',
70 `${item.testCase?.id}.json`
71 ].join(pathSeparator);
72 // Start polling running test.
73 pollTimer.current = setTimeout(async () => {
74 try {
75 const model = await loadSingleTraceFile(traceLocation, Date.now());
76 setModel({ model, isLive: true });
77 } catch {
78 const model = new TraceModel('', []);
79 model.errorDescriptors.push(...result.errors.flatMap(error => !!error.message ? [{ message: error.message }] : []));
80 setModel({ model, isLive: false });
81 } finally {
82 setCounter(counter + 1);
83 }
84 }, 500);
85 return () => {
86 if (pollTimer.current)
87 clearTimeout(pollTimer.current);
88 };
89 }, [outputDir, item, setModel, counter, setCounter, pathSeparator]);
90
91 return <Workbench

Callers

nothing calls this directly

Calls 7

artifactsFolderNameFunction · 0.90
outputDirForTestCaseFunction · 0.85
findMethod · 0.80
thenMethod · 0.80
nowMethod · 0.80
loadSingleTraceFileFunction · 0.70
pushMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…