mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-04-20 23:23:56 +03:00
use promises in dbweb e2e tests when waiting for enrichStations to work
This commit is contained in:
parent
c285339cd9
commit
a985f7423e
1 changed files with 56 additions and 54 deletions
|
@ -395,17 +395,19 @@ tap.test('trip details', async (t) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('departures at Berlin Schwedter Str.', 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, {
|
const res = await client.departures(blnSchwedterStr, {
|
||||||
duration: 5, when,
|
duration: 5, when,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (res.departures[0].stop.name === undefined || interval === undefined) { // ctx.common.locations have not loaded yet
|
if (res.departures[0].stop.name !== undefined) { // ctx.common.locations have loaded
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
clearInterval(interval);
|
clearInterval(interval);
|
||||||
interval = undefined;
|
return resolve(res);
|
||||||
|
}
|
||||||
|
}, 4000);
|
||||||
|
});
|
||||||
|
|
||||||
await testDepartures({
|
await testDepartures({
|
||||||
test: t,
|
test: t,
|
||||||
res,
|
res,
|
||||||
|
@ -413,11 +415,11 @@ tap.test('departures at Berlin Schwedter Str.', async (t) => {
|
||||||
id: blnSchwedterStr,
|
id: blnSchwedterStr,
|
||||||
});
|
});
|
||||||
t.end();
|
t.end();
|
||||||
}, 4000);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('departures with station object', async (t) => {
|
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({
|
const res = await client.departures({
|
||||||
type: 'station',
|
type: 'station',
|
||||||
id: jungfernheide,
|
id: jungfernheide,
|
||||||
|
@ -429,30 +431,31 @@ tap.test('departures with station object', async (t) => {
|
||||||
},
|
},
|
||||||
}, {when});
|
}, {when});
|
||||||
|
|
||||||
if (res.departures[0].stop.name === undefined || interval === undefined) { // ctx.common.locations have not loaded yet
|
if (res.departures[0].stop.name !== undefined) { // ctx.common.locations have loaded
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
clearInterval(interval);
|
clearInterval(interval);
|
||||||
interval = undefined;
|
return resolve(res);
|
||||||
validate(t, res, 'departuresResponse', 'res');
|
}
|
||||||
t.end();
|
|
||||||
|
|
||||||
}, 4000);
|
}, 4000);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
validate(t, res, 'departuresResponse', 'res');
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
||||||
tap.test('arrivals at Berlin Schwedter Str.', async (t) => {
|
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, {
|
const res = await client.arrivals(blnSchwedterStr, {
|
||||||
duration: 5, when,
|
duration: 5, when,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (res.arrivals[0].stop.name === undefined || interval === undefined) { // ctx.common.locations have not loaded yet
|
if (res.arrivals[0].stop.name !== undefined) { // ctx.common.locations have loaded
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
clearInterval(interval);
|
clearInterval(interval);
|
||||||
interval = undefined;
|
return resolve(res);
|
||||||
|
}
|
||||||
|
}, 4000);
|
||||||
|
});
|
||||||
|
|
||||||
await testArrivals({
|
await testArrivals({
|
||||||
test: t,
|
test: t,
|
||||||
res,
|
res,
|
||||||
|
@ -460,7 +463,6 @@ tap.test('arrivals at Berlin Schwedter Str.', async (t) => {
|
||||||
id: blnSchwedterStr,
|
id: blnSchwedterStr,
|
||||||
});
|
});
|
||||||
t.end();
|
t.end();
|
||||||
}, 4000);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('nearby Berlin Jungfernheide', async (t) => {
|
tap.test('nearby Berlin Jungfernheide', async (t) => {
|
||||||
|
|
Loading…
Add table
Reference in a new issue