use promises in dbweb e2e tests when waiting for enrichStations to work

This commit is contained in:
dabund24 2025-02-08 00:39:26 +01:00
parent c285339cd9
commit a985f7423e

View file

@ -395,17 +395,19 @@ tap.test('trip details', async (t) => {
});
tap.test('departures at Berlin Schwedter Str.', async (t) => {
let interval = setInterval(async () => {
const res = await new Promise((resolve) => {
let interval = setInterval(async () => { // repeat evaluating `departures()` until stations are enriched
const res = await client.departures(blnSchwedterStr, {
duration: 5, when,
});
if (res.departures[0].stop.name === undefined || interval === undefined) { // ctx.common.locations have not loaded yet
return;
}
if (res.departures[0].stop.name !== undefined) { // ctx.common.locations have loaded
clearInterval(interval);
interval = undefined;
return resolve(res);
}
}, 4000);
});
await testDepartures({
test: t,
res,
@ -413,11 +415,11 @@ tap.test('departures at Berlin Schwedter Str.', async (t) => {
id: blnSchwedterStr,
});
t.end();
}, 4000);
});
tap.test('departures with station object', async (t) => {
let interval = setInterval(async () => {
const res = await new Promise((resolve) => {
let interval = setInterval(async () => { // repeat evaluating `departures()` until stations are enriched
const res = await client.departures({
type: 'station',
id: jungfernheide,
@ -429,30 +431,31 @@ tap.test('departures with station object', async (t) => {
},
}, {when});
if (res.departures[0].stop.name === undefined || interval === undefined) { // ctx.common.locations have not loaded yet
return;
}
if (res.departures[0].stop.name !== undefined) { // ctx.common.locations have loaded
clearInterval(interval);
interval = undefined;
return resolve(res);
}
}, 4000);
});
validate(t, res, 'departuresResponse', 'res');
t.end();
}, 4000);
});
tap.test('arrivals at Berlin Schwedter Str.', async (t) => {
let interval = setInterval(async () => {
const res = await new Promise((resolve) => {
let interval = setInterval(async () => { // repeat evaluating `arrivals()` until stations are enriched
const res = await client.arrivals(blnSchwedterStr, {
duration: 5, when,
});
if (res.arrivals[0].stop.name === undefined || interval === undefined) { // ctx.common.locations have not loaded yet
return;
}
if (res.arrivals[0].stop.name !== undefined) { // ctx.common.locations have loaded
clearInterval(interval);
interval = undefined;
return resolve(res);
}
}, 4000);
});
await testArrivals({
test: t,
res,
@ -460,7 +463,6 @@ tap.test('arrivals at Berlin Schwedter Str.', async (t) => {
id: blnSchwedterStr,
});
t.end();
}, 4000);
});
tap.test('nearby Berlin Jungfernheide', async (t) => {