From 64749d0b7ac7a97bcd7f2a9dc104cc697ad291aa Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Mon, 18 Nov 2024 22:39:59 +0000 Subject: [PATCH] Expose TestScheduler as global (#2796) --- src/utils/test.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/utils/test.ts b/src/utils/test.ts index 2af6016c..771dd574 100644 --- a/src/utils/test.ts +++ b/src/utils/test.ts @@ -4,7 +4,7 @@ Copyright 2023, 2024 New Vector Ltd. SPDX-License-Identifier: AGPL-3.0-only Please see LICENSE in the repository root for full details. */ -import { map, Observable, of } from "rxjs"; +import { map, Observable, of, SchedulerLike } from "rxjs"; import { RunHelpers, TestScheduler } from "rxjs/testing"; import { expect, vi } from "vitest"; import { RoomMember, Room as MatrixRoom } from "matrix-js-sdk/src/matrix"; @@ -39,15 +39,23 @@ export interface OurRunHelpers extends RunHelpers { schedule: (marbles: string, actions: Record void>) => void; } +interface TestRunnerGlobal { + rxjsTestScheduler?: SchedulerLike; +} + /** * Run Observables with a scheduler that virtualizes time, for testing purposes. */ export function withTestScheduler( continuation: (helpers: OurRunHelpers) => void, ): void { - new TestScheduler((actual, expected) => { + const scheduler = new TestScheduler((actual, expected) => { expect(actual).deep.equals(expected); - }).run((helpers) => + }); + // we set the test scheduler as a global so that you can watch it in a debugger + // and get the frame number. e.g. `rxjsTestScheduler?.now()` + (global as unknown as TestRunnerGlobal).rxjsTestScheduler = scheduler; + scheduler.run((helpers) => continuation({ ...helpers, schedule(marbles, actions) {