Skip to content

Commit 90c51c6

Browse files
committed
chore: fix sisyfos unit tests reliability
1 parent 71fcc04 commit 90c51c6

3 files changed

Lines changed: 17 additions & 3 deletions

File tree

packages/timeline-state-resolver/src/__tests__/lib.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,9 @@ declare global {
8686
}
8787
}
8888
}
89-
/** setTimeout (not affected by jest.fakeTimers) */
90-
const setTimeoutOrg = setTimeout
9189
/** Sleep for a */
9290
export async function waitTime(ms: number): Promise<void> {
93-
return new Promise((resolve) => setTimeoutOrg(resolve, ms))
91+
return new Promise((resolve) => jest.requireActual('timers').setTimeout(resolve, ms))
9492
}
9593

9694
/** The current time, not affected by jest.fakeTimers */

packages/timeline-state-resolver/src/__tests__/mockTime.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { waitTime } from './lib'
2+
13
export class MockTime {
24
private _now = 10000
35
private _hasBeeninit = false
@@ -53,6 +55,8 @@ export class MockTime {
5355
jest.advanceTimersByTime(advanceChunk)
5456
}
5557
await this.tick()
58+
59+
await waitTime(1) // Do an extra setTimeout here, so that any waiting timers are executed
5660
}
5761
advanceTimeToTicks = async (time: number) => {
5862
const advance = time - this._now

packages/timeline-state-resolver/src/integrations/sisyfos/__tests__/sisyfos.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ describe('Sisyfos', () => {
262262
channel: 0,
263263
value: false,
264264
})
265+
await myConductor.destroy()
265266
})
266267
test('Sisyfos: set ch1: pgm & ch2: lookahead and then ch1: vo, ch2: pgm', async () => {
267268
const commandReceiver0: any = jest.fn(async () => {
@@ -489,6 +490,7 @@ describe('Sisyfos', () => {
489490
channel: 0,
490491
value: false,
491492
})
493+
await myConductor.destroy()
492494
})
493495

494496
test('Sisyfos: set lookahead and take to pgm, with lookahead still on', async () => {
@@ -633,6 +635,7 @@ describe('Sisyfos', () => {
633635
channel: 1,
634636
values: [0],
635637
})
638+
await myConductor.destroy()
636639
})
637640

638641
test('Sisyfos: using CHANNELS', async () => {
@@ -853,6 +856,8 @@ describe('Sisyfos', () => {
853856
})
854857

855858
commandReceiver0.mockClear()
859+
860+
await myConductor.destroy()
856861
})
857862

858863
test('Sisyfos: using global triggerValue', async () => {
@@ -1061,6 +1066,8 @@ describe('Sisyfos', () => {
10611066
})
10621067

10631068
commandReceiver0.mockClear()
1069+
1070+
await myConductor.destroy()
10641071
})
10651072

10661073
test('Sisyfos: using per-channel triggerValue - initially defined', async () => {
@@ -1213,6 +1220,8 @@ describe('Sisyfos', () => {
12131220
})
12141221

12151222
commandReceiver0.mockClear()
1223+
1224+
await myConductor.destroy()
12161225
})
12171226

12181227
test('Sisyfos: using per-channel triggerValue - initially undefined', async () => {
@@ -1351,6 +1360,8 @@ describe('Sisyfos', () => {
13511360
expect(commandReceiver0.mock.calls.length).toEqual(0)
13521361

13531362
commandReceiver0.mockClear()
1363+
1364+
await myConductor.destroy()
13541365
})
13551366

13561367
test('Connection status', async () => {
@@ -1417,6 +1428,7 @@ describe('Sisyfos', () => {
14171428

14181429
expect(await device.connected).toEqual(true)
14191430
expect(onConnectionChanged.mock.calls.length).toBeGreaterThanOrEqual(1)
1431+
await myConductor.destroy()
14201432
})
14211433

14221434
describe('convertTimelineStateToDeviceState', () => {

0 commit comments

Comments
 (0)