Skip to content

Commit 4a0dbb7

Browse files
mfaferek93bburda
authored andcommitted
test(e2e): skip the rosbag specs when their stack is absent
A fetch in beforeAll threw before the skip guard could run, so CI went red on a missing fixture rather than reporting it as skipped.
1 parent 0071145 commit 4a0dbb7

1 file changed

Lines changed: 19 additions & 6 deletions

File tree

e2e/rosbag-recordings.spec.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,23 @@ interface Descriptor {
3939
'x-medkit'?: { fault_codes?: string[]; recording_id?: string };
4040
}
4141

42+
/** fetch that answers null instead of throwing when nothing is listening. */
43+
async function safeFetch(url: string): Promise<Response | null> {
44+
try {
45+
return await fetch(url);
46+
} catch {
47+
return null;
48+
}
49+
}
50+
4251
/** Recording ids the gateway attributes to the seeded fault, via its own API. */
4352
async function recordingsFromApi(appId: string): Promise<string[]> {
44-
const response = await fetch(`${GATEWAY_URL}/apps/${appId}/bulk-data/rosbags`);
45-
if (!response.ok) return [];
53+
// Network errors are swallowed here and in appHoldingTheFault so a stack that
54+
// is not up leaves expectedRecordings empty and the specs SKIP with a named
55+
// reason. Letting fetch throw out of beforeAll fails them instead, which says
56+
// nothing about this repo and turns CI red on a missing fixture.
57+
const response = await safeFetch(`${GATEWAY_URL}/apps/${appId}/bulk-data/rosbags`);
58+
if (!response?.ok) return [];
4659
const body = (await response.json()) as { items?: Descriptor[] };
4760
return (body.items ?? [])
4861
.filter((item) => item['x-medkit']?.fault_codes?.includes(FAULT_CODE))
@@ -51,12 +64,12 @@ async function recordingsFromApi(appId: string): Promise<string[]> {
5164

5265
/** The app the seeded fault is attributed to, whatever the gateway named it. */
5366
async function appHoldingTheFault(): Promise<string | null> {
54-
const response = await fetch(`${GATEWAY_URL}/apps`);
55-
if (!response.ok) return null;
67+
const response = await safeFetch(`${GATEWAY_URL}/apps`);
68+
if (!response?.ok) return null;
5669
const body = (await response.json()) as { items?: Array<{ id: string }> };
5770
for (const app of body.items ?? []) {
58-
const faults = await fetch(`${GATEWAY_URL}/apps/${app.id}/faults`);
59-
if (!faults.ok) continue;
71+
const faults = await safeFetch(`${GATEWAY_URL}/apps/${app.id}/faults`);
72+
if (!faults?.ok) continue;
6073
const listing = (await faults.json()) as { items?: Array<{ fault_code?: string }> };
6174
if ((listing.items ?? []).some((f) => f.fault_code === FAULT_CODE)) return app.id;
6275
}

0 commit comments

Comments
 (0)