From 719b91c9bc2914b7ae253a9255973e5725148f24 Mon Sep 17 00:00:00 2001 From: Mathieu Colmon Date: Tue, 17 Dec 2024 15:25:11 +0100 Subject: [PATCH] Improve test stability (2) --- tests/replayMode.test.ts | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/tests/replayMode.test.ts b/tests/replayMode.test.ts index 60a525b..758dde0 100644 --- a/tests/replayMode.test.ts +++ b/tests/replayMode.test.ts @@ -76,30 +76,26 @@ describe('ReplayMode', () => { range: 1, }); - await new Promise((resolve) => { - chart.onSymbolLoaded(() => { - console.log('Chart loaded'); - resolve(true); - }); - }); + await new Promise((r) => chart.onSymbolLoaded(() => r(true))); + console.log('Chart loaded'); expect(chart.infos.full_name).toBe('BINANCE:BTCEUR'); }); it('steps forward automatically', async () => { console.log('Play replay mode'); - await chart.replayStart(200); + await chart.replayStart(100); chart.onUpdate(() => { console.log('Point ->', chart.periods[0].time); }); - await new Promise((resolve) => { - chart.onReplayEnd(() => { - console.log('Replay end'); - resolve(true); - }); - }); + const msg = await Promise.race([ + new Promise((r) => chart.onReplayEnd(() => r('Replay end'))), + new Promise((r) => setTimeout(() => r('Timeout'), 9000)), + ]); + + console.log(msg); expect( utils.calculateTimeGap(chart.periods),