Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 | 7x 91x 91x 91x 91x 91x 7x 7x 86x 7x 7x 7x 7x 7x 7x 7x 7x 28x 7x | /**
* The details panel, rendered below the cards. It is a plain toggle: changing the selected step
* updates its content but does not close it, and there is no backdrop to click.
*/
import {useMemo, useState} from 'react';
import type {
ITestLogRowModel,
ITestProgressTreeNode,
ITestRunModel,
ITestSourceLinkConfig,
ITestSourcePointer,
} from '../../types/testRun.js';
import {Text} from '../Text/Text.js';
import {
assertionLabel,
defaultSourceLinkConfig,
formatDuration,
logRows,
progressTree,
sourceHref,
sourceLabel,
} from './testRunModel.js';
export interface ITestRunDetailsProps {
run: ITestRunModel;
stepName?: string;
open: boolean;
/** Base and scheme for source links; the pointer is always shown, linked or not. */
sourceLink?: ITestSourceLinkConfig;
onClose(): void;
}
type DetailsTab = 'progress' | 'result' | 'error' | 'log';
const TABS: Array<{id: DetailsTab; label: string}> = [
{id: 'progress', label: 'Progress'},
{id: 'result', label: 'Result'},
{id: 'error', label: 'Error'},
{id: 'log', label: 'Log'},
];
function safeStringify(value: unknown): string {
if (value === undefined) return '';
try {
return JSON.stringify(value, null, 2) ?? String(value);
} catch {
return String(value);
}
}
/** A captured source pointer, linked when a base is configured and plain otherwise. */
function SourceLink({
source,
config,
}: {
source?: ITestSourcePointer;
config?: ITestSourceLinkConfig;
}) {
Iif (!source?.file) return null;
const href = sourceHref(source, config);
const label = sourceLabel(source);
const title = `${source.file}${source.line === undefined ? '' : `:${source.line}`}${
source.symbol ? ` · ${source.symbol}` : ''
}`;
return href ? (
<a
className="blong-test-run__source"
href={href}
title={title}
target="_blank"
rel="noreferrer"
>
{label}
</a>
) : (
<span
className="blong-test-run__source"
title={title}
>
{label}
</span>
);
}
/** The Log tab: executor lines and assertion messages in one stream. */
function LogList({
rows,
startedAt,
sourceLink,
}: {
rows: ITestLogRowModel[];
startedAt: number;
sourceLink?: ITestSourceLinkConfig;
}) {
Iif (!rows.length) {
return (
<p className="blong-test-run__muted">
<Text>No log entries or assertions</Text>
</p>
);
}
return (
<ul className="blong-test-run__logs">
{rows.map((row, index) => (
<li
// eslint-disable-next-line @eslint-react/no-array-index-key
key={`${row.kind}-${row.timestamp}-${index}-${row.stepName ?? ''}`}
className={`blong-test-run__log blong-test-run__log--${row.level}`}
>
<span className="blong-test-run__log-time">
{formatDuration(Math.max(0, row.timestamp - startedAt))}
</span>
<span className="blong-test-run__log-level">
{row.kind === 'assertion'
? row.passed
? '✓ assert'
: '✗ assert'
: row.level}
</span>
<span className="blong-test-run__log-message">
{row.stepName && (
<span className="blong-test-run__log-step">{row.stepName}</span>
)}
{row.message}
<SourceLink
source={row.source}
config={sourceLink}
/>
</span>
</li>
))}
</ul>
);
}
function ProgressNodes({nodes, depth = 0}: {nodes: ITestProgressTreeNode[]; depth?: number}) {
return (
<ul className={`blong-test-run__progress-tree depth-${depth}`}>
{nodes.map((node, index) => (
<li
// eslint-disable-next-line @eslint-react/no-array-index-key
key={`${depth}-${index}-${node.name}`}
className={`blong-test-run__progress-node blong-test-run__progress-node--${node.kind}`}
>
<span className="blong-test-run__progress-label">{node.name}</span>
{node.data && (
<span className="blong-test-run__progress-data">
{Object.entries(node.data)
.slice(0, 4)
.map(
([key, value]) =>
`${key}=${safeStringify(value).replace(/\n/g, ' ')}`,
)
.join(' · ')}
</span>
)}
{node.children.length > 0 && (
<ProgressNodes
nodes={node.children}
depth={depth + 1}
/>
)}
</li>
))}
</ul>
);
}
function TestRunDetailsContent({run, stepName, open, sourceLink, onClose}: ITestRunDetailsProps) {
const step = stepName ? run.steps[stepName] : undefined;
const link = useMemo(() => sourceLink ?? defaultSourceLinkConfig(), [sourceLink]);
// The exported wrapper keys this component by the selected step, so a different step starts on
// the Log tab while a live refresh of the same step keeps the tab the user chose.
const [tab, setTab] = useState<DetailsTab>('log');
const tree = useMemo(() => progressTree(step?.progress), [step?.progress]);
const rows = useMemo(() => logRows(run, stepName), [run, stepName]);
Iif (!open) return null;
const selectStep = (
<p className="blong-test-run__muted">
<Text>Select a step to see its details</Text>
</p>
);
return (
<section
className="blong-test-run__details p-card p-component"
aria-label="Step details"
>
<header className="blong-test-run__details-header">
<div className="blong-test-run__details-title">
{step ? (
<>
<i
className={`blong-test-run__status pi ${
step.status === 'failed'
? 'pi-times'
: step.status === 'running'
? 'pi-spin pi-spinner'
: step.status === 'completed'
? 'pi-check'
: 'pi-circle-fill'
}`}
/>
<span>{step.displayName}</span>
<span className="blong-test-run__details-meta">
{formatDuration(step.duration)} · assertions{' '}
{assertionLabel(step.assertions)}
</span>
<SourceLink
source={step.sourceLocation}
config={link}
/>
</>
) : (
<Text>Run log</Text>
)}
</div>
<button
type="button"
className="blong-test-run__graph-button"
aria-label="Close details"
onClick={onClose}
>
<i className="pi pi-times" />
</button>
</header>
<nav
className="blong-test-run__tabs"
role="tablist"
>
{TABS.map(item => (
<button
key={item.id}
type="button"
role="tab"
aria-selected={tab === item.id}
className={`blong-test-run__tab${tab === item.id ? ' is-active' : ''}`}
onClick={() => setTab(item.id)}
>
<Text>{item.label}</Text>
{item.id === 'error' && step?.error && (
<span className="blong-test-run__tab-badge">1</span>
)}
{item.id === 'log' && rows.length > 0 && (
<span className="blong-test-run__tab-badge">{rows.length}</span>
)}
</button>
))}
</nav>
<div className="blong-test-run__details-body">
{tab === 'log' && (
<LogList
rows={rows}
startedAt={run.startedAt}
sourceLink={link}
/>
)}
{tab === 'progress' &&
(!step ? (
selectStep
) : tree.length ? (
<ProgressNodes nodes={tree} />
) : (
<p className="blong-test-run__muted">
<Text>This step announced no checkpoints</Text>
</p>
))}
{tab === 'result' &&
(!step ? (
selectStep
) : step.result === undefined ? (
<p className="blong-test-run__muted">
<Text>The step returned nothing</Text>
</p>
) : (
<pre className="blong-test-run__code">{safeStringify(step.result)}</pre>
))}
{tab === 'error' &&
(!step ? (
selectStep
) : step.error ? (
<div className="blong-test-run__error">
<div className="blong-test-run__error-message">
{step.error.message}
</div>
{step.error.type && (
<div className="blong-test-run__error-type">{step.error.type}</div>
)}
{step.error.stack && (
<pre className="blong-test-run__code">{step.error.stack}</pre>
)}
{step.error.context && (
<pre className="blong-test-run__code">
{safeStringify(step.error.context)}
</pre>
)}
</div>
) : (
<p className="blong-test-run__muted">
<Text>The step did not fail</Text>
</p>
))}
</div>
</section>
);
}
/**
* The panel is keyed by the selected step: a different step starts on the Log tab, while a live
* refresh of the same step keeps the tab the user chose.
*/
export function TestRunDetails(props: ITestRunDetailsProps) {
return (
<TestRunDetailsContent
key={props.stepName ?? 'none'}
{...props}
/>
);
}
|