Skip to content

Commit d2fb924

Browse files
committed
chore: account for the test id missing in the store
1 parent fcfb61a commit d2fb924

File tree

2 files changed

+26
-27
lines changed

2 files changed

+26
-27
lines changed

packages/html-reporter/src/reportView.tsx

+11-7
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,22 @@ const TestCaseViewLoader: React.FC<{
113113
if (!testId || testId === test?.testId)
114114
return;
115115
const fileId = testIdToFileIdMap.get(testId);
116-
if (!fileId)
116+
if (!fileId) {
117+
setTest(undefined);
117118
return;
118-
const file = await report.entry(`${fileId}.json`) as TestFile;
119-
for (const t of file.tests) {
120-
if (t.testId === testId) {
121-
setTest(t);
122-
break;
123-
}
124119
}
120+
const file = await report.entry(`${fileId}.json`) as TestFile;
121+
setTest(file?.tests.find(t => t.testId === testId));
125122
})();
126123
}, [test, report, testId, testIdToFileIdMap]);
127124

125+
if (!test) {
126+
return <div className='test-case-column vbox'>
127+
<div className='test-case-title'>Test not found</div>
128+
<div className='test-case-location'>Test ID: {testId}</div>
129+
</div>;
130+
}
131+
128132
return <TestCaseView
129133
projectNames={report.json().projectNames}
130134
next={next}

packages/html-reporter/src/testCaseView.tsx

+15-20
Original file line numberDiff line numberDiff line change
@@ -30,49 +30,44 @@ import { CopyToClipboardContainer } from './copyToClipboard';
3030

3131
export const TestCaseView: React.FC<{
3232
projectNames: string[],
33-
test: TestCase | undefined,
33+
test: TestCase,
3434
next: TestCaseSummary | undefined,
3535
prev: TestCaseSummary | undefined,
3636
run: number,
3737
}> = ({ projectNames, test, run, next, prev }) => {
3838
const [selectedResultIndex, setSelectedResultIndex] = React.useState(run);
3939
const searchParams = React.useContext(SearchParamsContext);
40-
const filterParam = searchParams.has('q') ? '&q=' + searchParams.get('q') : '';
41-
42-
const labels = React.useMemo(() => {
43-
if (!test)
44-
return undefined;
45-
return test.tags;
46-
}, [test]);
4740

48-
const visibleTestAnnotations = test?.annotations.filter(a => !a.type.startsWith('_')) ?? [];
41+
const filterParam = searchParams.has('q') ? '&q=' + searchParams.get('q') : '';
42+
const labels = React.useMemo(() => test.tags, [test]);
43+
const visibleTestAnnotations = test.annotations.filter(a => !a.type.startsWith('_')) ?? [];
4944

5045
return <div className='test-case-column vbox'>
51-
{test && <div className='hbox'>
46+
<div className='hbox'>
5247
<div className='test-case-path'>{test.path.join(' › ')}</div>
5348
<div style={{ flex: 'auto' }}></div>
5449
<div className={clsx(!prev && 'hidden')}><Link href={testResultHref({ test: prev }) + filterParam}>« previous</Link></div>
5550
<div style={{ width: 10 }}></div>
5651
<div className={clsx(!next && 'hidden')}><Link href={testResultHref({ test: next }) + filterParam}>next »</Link></div>
57-
</div>}
58-
{test && <div className='test-case-title'>{test?.title}</div>}
59-
{test && <div className='hbox'>
52+
</div>
53+
<div className='test-case-title'>{test.title}</div>
54+
<div className='hbox'>
6055
<div className='test-case-location'>
61-
<CopyToClipboardContainer value={`${test?.location.file}:${test?.location.line}`}>
56+
<CopyToClipboardContainer value={`${test.location.file}:${test.location.line}`}>
6257
{test.location.file}:{test.location.line}
6358
</CopyToClipboardContainer>
6459
</div>
6560
<div style={{ flex: 'auto' }}></div>
6661
<div className='test-case-duration'>{msToString(test.duration)}</div>
67-
</div>}
68-
{test && (!!test.projectName || labels) && <div className='test-case-project-labels-row'>
69-
{test && !!test.projectName && <ProjectLink projectNames={projectNames} projectName={test.projectName}></ProjectLink>}
62+
</div>
63+
{(!!test.projectName || labels) && <div className='test-case-project-labels-row'>
64+
{!!test.projectName && <ProjectLink projectNames={projectNames} projectName={test.projectName}></ProjectLink>}
7065
{labels && <LabelsLinkView labels={labels} />}
7166
</div>}
72-
{test?.results.length === 0 && visibleTestAnnotations.length !== 0 && <AutoChip header='Annotations' dataTestId='test-case-annotations'>
67+
{test.results.length === 0 && visibleTestAnnotations.length !== 0 && <AutoChip header='Annotations' dataTestId='test-case-annotations'>
7368
{visibleTestAnnotations.map((annotation, index) => <TestCaseAnnotationView key={index} annotation={annotation} />)}
7469
</AutoChip>}
75-
{test && <TabbedPane tabs={
70+
<TabbedPane tabs={
7671
test.results.map((result, index) => ({
7772
id: String(index),
7873
title: <div style={{ display: 'flex', alignItems: 'center' }}>
@@ -88,7 +83,7 @@ export const TestCaseView: React.FC<{
8883
<TestResultView test={test!} result={result} />
8984
</>;
9085
},
91-
})) || []} selectedTab={String(selectedResultIndex)} setSelectedTab={id => setSelectedResultIndex(+id)} />}
86+
})) || []} selectedTab={String(selectedResultIndex)} setSelectedTab={id => setSelectedResultIndex(+id)} />
9287
</div>;
9388
};
9489

0 commit comments

Comments
 (0)