From f5c31626a66552a8236b35deeef6d12b999cd17b Mon Sep 17 00:00:00 2001 From: Timo K Date: Fri, 16 Jan 2026 12:43:13 +0100 Subject: [PATCH] fix unit tests --- .../DeveloperSettingsTab.test.tsx.snap | 6 ++++ .../localMember/LocalMember.test.ts | 31 +++++++------------ .../localMember/Publisher.test.ts | 11 ++++--- 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/src/settings/__snapshots__/DeveloperSettingsTab.test.tsx.snap b/src/settings/__snapshots__/DeveloperSettingsTab.test.tsx.snap index 57afe4d9..cfa25ca5 100644 --- a/src/settings/__snapshots__/DeveloperSettingsTab.test.tsx.snap +++ b/src/settings/__snapshots__/DeveloperSettingsTab.test.tsx.snap @@ -359,6 +359,9 @@ exports[`DeveloperSettingsTab > renders and matches snapshot 1`] = ` LivekitAlias: TestAlias

+

+ connectionState (wont hot reload): +

ws-url: wss://local-sfu.example.org/ @@ -401,6 +404,9 @@ exports[`DeveloperSettingsTab > renders and matches snapshot 1`] = ` LivekitAlias: TestAlias2

+

+ connectionState (wont hot reload): +

LiveKit Server Info ( diff --git a/src/state/CallViewModel/localMember/LocalMember.test.ts b/src/state/CallViewModel/localMember/LocalMember.test.ts index af12c98b..76c0f4a8 100644 --- a/src/state/CallViewModel/localMember/LocalMember.test.ts +++ b/src/state/CallViewModel/localMember/LocalMember.test.ts @@ -301,6 +301,7 @@ describe("LocalMembership", () => { logger.info(`stopPublishing [${a}]`); }), stopTracks: vi.fn(), + destroy: vi.fn(), }; publishers.push(p as unknown as Publisher); return p; @@ -325,13 +326,12 @@ describe("LocalMembership", () => { await flushPromises(); localTransport$.next(bTransport); await flushPromises(); + expect(publisherFactory).toHaveBeenCalledTimes(2); expect(publishers.length).toBe(2); // stop the first Publisher and let the second one life. - expect(publishers[0].stopTracks).toHaveBeenCalled(); - expect(publishers[1].stopTracks).not.toHaveBeenCalled(); - expect(publishers[0].stopPublishing).toHaveBeenCalled(); - expect(publishers[1].stopPublishing).not.toHaveBeenCalled(); + expect(publishers[0].destroy).toHaveBeenCalled(); + expect(publishers[1].destroy).not.toHaveBeenCalled(); expect(publisherFactory.mock.calls[0][0].transport).toBe( aTransport.transport, ); @@ -341,7 +341,7 @@ describe("LocalMembership", () => { scope.end(); await flushPromises(); // stop all tracks after ending scopes - expect(publishers[1].stopPublishing).toHaveBeenCalled(); + expect(publishers[1].destroy).toHaveBeenCalled(); // expect(publishers[1].stopTracks).toHaveBeenCalled(); defaultCreateLocalMemberValues.createPublisherFactory.mockReset(); @@ -359,8 +359,7 @@ describe("LocalMembership", () => { defaultCreateLocalMemberValues.createPublisherFactory.mockImplementation( () => { const p = { - stopPublishing: vi.fn(), - stopTracks: vi.fn(), + destroy: vi.fn(), createAndSetupTracks: vi.fn().mockImplementation(async () => { tracks$.next([{}, {}] as LocalTrack[]); return Promise.resolve(); @@ -395,11 +394,11 @@ describe("LocalMembership", () => { localMembership.startTracks(); await flushPromises(); expect(publishers[0].createAndSetupTracks).toHaveBeenCalled(); - // expect(localMembership.tracks$.value.length).toBe(2); + scope.end(); await flushPromises(); // stop all tracks after ending scopes - expect(publishers[0].stopPublishing).toHaveBeenCalled(); + expect(publishers[0].destroy).toHaveBeenCalled(); // expect(publishers[0].stopTracks).toHaveBeenCalled(); publisherFactory.mockClear(); }); @@ -416,27 +415,21 @@ describe("LocalMembership", () => { ); const publishers: Publisher[] = []; - const tracks$ = new BehaviorSubject([]); const publishing$ = new BehaviorSubject(false); const createTrackResolver = Promise.withResolvers(); const publishResolver = Promise.withResolvers(); defaultCreateLocalMemberValues.createPublisherFactory.mockImplementation( () => { const p = { - stopPublishing: vi.fn(), - stopTracks: vi.fn().mockImplementation(() => { - logger.info("stopTracks"); - tracks$.next([]); - }), + destroy: vi.fn(), createAndSetupTracks: vi.fn().mockImplementation(async () => { await createTrackResolver.promise; - tracks$.next([{}, {}] as LocalTrack[]); }), startPublishing: vi.fn().mockImplementation(async () => { await publishResolver.promise; publishing$.next(true); }), - tracks$, + publishing$, }; publishers.push(p as unknown as Publisher); @@ -536,7 +529,7 @@ describe("LocalMembership", () => { (localMembership.localMemberState$.value as any).media, ).toStrictEqual(PublishState.Publishing); - expect(publishers[0].stopPublishing).not.toHaveBeenCalled(); + expect(publishers[0].destroy).not.toHaveBeenCalled(); expect(localMembership.localMemberState$.isStopped).toBe(false); scope.end(); @@ -547,7 +540,7 @@ describe("LocalMembership", () => { (localMembership.localMemberState$.value as any).media, ).toStrictEqual(PublishState.Publishing); // stop all tracks after ending scopes - expect(publishers[0].stopPublishing).toHaveBeenCalled(); + expect(publishers[0].destroy).toHaveBeenCalled(); // expect(publishers[0].stopTracks).toHaveBeenCalled(); }); // TODO add tests for matrix local matrix participation. diff --git a/src/state/CallViewModel/localMember/Publisher.test.ts b/src/state/CallViewModel/localMember/Publisher.test.ts index 38a80bed..0bb97797 100644 --- a/src/state/CallViewModel/localMember/Publisher.test.ts +++ b/src/state/CallViewModel/localMember/Publisher.test.ts @@ -183,7 +183,6 @@ describe("Publisher", () => { beforeEach(() => { publisher = new Publisher( - scope, connection, mockMediaDevices({}), muteStates, @@ -192,7 +191,9 @@ describe("Publisher", () => { ); }); - afterEach(() => {}); + afterEach(async () => { + await publisher.destroy(); + }); it("Should not create tracks if started muted to avoid unneeded permission requests", async () => { const createTracksSpy = vi.spyOn( @@ -267,7 +268,6 @@ describe("Publisher", () => { let publisher: Publisher; beforeEach(() => { publisher = new Publisher( - scope, connection, mockMediaDevices({}), muteStates, @@ -275,6 +275,9 @@ describe("Publisher", () => { logger, ); }); + afterEach(async () => { + await publisher.destroy(); + }); test.each([ { mutes: { audioEnabled: true, videoEnabled: false } }, @@ -320,7 +323,6 @@ describe("Bug fix", () => { it("wrongly publish tracks while muted", async () => { // setLogLevel(`debug`); const publisher = new Publisher( - scope, connection, mockMediaDevices({}), muteStates, @@ -356,5 +358,6 @@ describe("Bug fix", () => { expect(track!.mute).toHaveBeenCalled(); expect(track!.isMuted).toBe(true); } + await publisher.destroy(); }); });