fix unit tests

This commit is contained in:
Timo K
2026-01-16 12:43:13 +01:00
parent 5a48820927
commit f5c31626a6
3 changed files with 25 additions and 23 deletions

View File

@@ -359,6 +359,9 @@ exports[`DeveloperSettingsTab > renders and matches snapshot 1`] = `
LivekitAlias: LivekitAlias:
TestAlias TestAlias
</p> </p>
<p>
connectionState (wont hot reload):
</p>
<p> <p>
ws-url: ws-url:
wss://local-sfu.example.org/ wss://local-sfu.example.org/
@@ -401,6 +404,9 @@ exports[`DeveloperSettingsTab > renders and matches snapshot 1`] = `
LivekitAlias: LivekitAlias:
TestAlias2 TestAlias2
</p> </p>
<p>
connectionState (wont hot reload):
</p>
<p> <p>
LiveKit Server Info LiveKit Server Info
( (

View File

@@ -301,6 +301,7 @@ describe("LocalMembership", () => {
logger.info(`stopPublishing [${a}]`); logger.info(`stopPublishing [${a}]`);
}), }),
stopTracks: vi.fn(), stopTracks: vi.fn(),
destroy: vi.fn(),
}; };
publishers.push(p as unknown as Publisher); publishers.push(p as unknown as Publisher);
return p; return p;
@@ -325,13 +326,12 @@ describe("LocalMembership", () => {
await flushPromises(); await flushPromises();
localTransport$.next(bTransport); localTransport$.next(bTransport);
await flushPromises(); await flushPromises();
expect(publisherFactory).toHaveBeenCalledTimes(2); expect(publisherFactory).toHaveBeenCalledTimes(2);
expect(publishers.length).toBe(2); expect(publishers.length).toBe(2);
// stop the first Publisher and let the second one life. // stop the first Publisher and let the second one life.
expect(publishers[0].stopTracks).toHaveBeenCalled(); expect(publishers[0].destroy).toHaveBeenCalled();
expect(publishers[1].stopTracks).not.toHaveBeenCalled(); expect(publishers[1].destroy).not.toHaveBeenCalled();
expect(publishers[0].stopPublishing).toHaveBeenCalled();
expect(publishers[1].stopPublishing).not.toHaveBeenCalled();
expect(publisherFactory.mock.calls[0][0].transport).toBe( expect(publisherFactory.mock.calls[0][0].transport).toBe(
aTransport.transport, aTransport.transport,
); );
@@ -341,7 +341,7 @@ describe("LocalMembership", () => {
scope.end(); scope.end();
await flushPromises(); await flushPromises();
// stop all tracks after ending scopes // stop all tracks after ending scopes
expect(publishers[1].stopPublishing).toHaveBeenCalled(); expect(publishers[1].destroy).toHaveBeenCalled();
// expect(publishers[1].stopTracks).toHaveBeenCalled(); // expect(publishers[1].stopTracks).toHaveBeenCalled();
defaultCreateLocalMemberValues.createPublisherFactory.mockReset(); defaultCreateLocalMemberValues.createPublisherFactory.mockReset();
@@ -359,8 +359,7 @@ describe("LocalMembership", () => {
defaultCreateLocalMemberValues.createPublisherFactory.mockImplementation( defaultCreateLocalMemberValues.createPublisherFactory.mockImplementation(
() => { () => {
const p = { const p = {
stopPublishing: vi.fn(), destroy: vi.fn(),
stopTracks: vi.fn(),
createAndSetupTracks: vi.fn().mockImplementation(async () => { createAndSetupTracks: vi.fn().mockImplementation(async () => {
tracks$.next([{}, {}] as LocalTrack[]); tracks$.next([{}, {}] as LocalTrack[]);
return Promise.resolve(); return Promise.resolve();
@@ -395,11 +394,11 @@ describe("LocalMembership", () => {
localMembership.startTracks(); localMembership.startTracks();
await flushPromises(); await flushPromises();
expect(publishers[0].createAndSetupTracks).toHaveBeenCalled(); expect(publishers[0].createAndSetupTracks).toHaveBeenCalled();
// expect(localMembership.tracks$.value.length).toBe(2);
scope.end(); scope.end();
await flushPromises(); await flushPromises();
// stop all tracks after ending scopes // stop all tracks after ending scopes
expect(publishers[0].stopPublishing).toHaveBeenCalled(); expect(publishers[0].destroy).toHaveBeenCalled();
// expect(publishers[0].stopTracks).toHaveBeenCalled(); // expect(publishers[0].stopTracks).toHaveBeenCalled();
publisherFactory.mockClear(); publisherFactory.mockClear();
}); });
@@ -416,27 +415,21 @@ describe("LocalMembership", () => {
); );
const publishers: Publisher[] = []; const publishers: Publisher[] = [];
const tracks$ = new BehaviorSubject<LocalTrack[]>([]);
const publishing$ = new BehaviorSubject<boolean>(false); const publishing$ = new BehaviorSubject<boolean>(false);
const createTrackResolver = Promise.withResolvers<void>(); const createTrackResolver = Promise.withResolvers<void>();
const publishResolver = Promise.withResolvers<void>(); const publishResolver = Promise.withResolvers<void>();
defaultCreateLocalMemberValues.createPublisherFactory.mockImplementation( defaultCreateLocalMemberValues.createPublisherFactory.mockImplementation(
() => { () => {
const p = { const p = {
stopPublishing: vi.fn(), destroy: vi.fn(),
stopTracks: vi.fn().mockImplementation(() => {
logger.info("stopTracks");
tracks$.next([]);
}),
createAndSetupTracks: vi.fn().mockImplementation(async () => { createAndSetupTracks: vi.fn().mockImplementation(async () => {
await createTrackResolver.promise; await createTrackResolver.promise;
tracks$.next([{}, {}] as LocalTrack[]);
}), }),
startPublishing: vi.fn().mockImplementation(async () => { startPublishing: vi.fn().mockImplementation(async () => {
await publishResolver.promise; await publishResolver.promise;
publishing$.next(true); publishing$.next(true);
}), }),
tracks$,
publishing$, publishing$,
}; };
publishers.push(p as unknown as Publisher); publishers.push(p as unknown as Publisher);
@@ -536,7 +529,7 @@ describe("LocalMembership", () => {
(localMembership.localMemberState$.value as any).media, (localMembership.localMemberState$.value as any).media,
).toStrictEqual(PublishState.Publishing); ).toStrictEqual(PublishState.Publishing);
expect(publishers[0].stopPublishing).not.toHaveBeenCalled(); expect(publishers[0].destroy).not.toHaveBeenCalled();
expect(localMembership.localMemberState$.isStopped).toBe(false); expect(localMembership.localMemberState$.isStopped).toBe(false);
scope.end(); scope.end();
@@ -547,7 +540,7 @@ describe("LocalMembership", () => {
(localMembership.localMemberState$.value as any).media, (localMembership.localMemberState$.value as any).media,
).toStrictEqual(PublishState.Publishing); ).toStrictEqual(PublishState.Publishing);
// stop all tracks after ending scopes // stop all tracks after ending scopes
expect(publishers[0].stopPublishing).toHaveBeenCalled(); expect(publishers[0].destroy).toHaveBeenCalled();
// expect(publishers[0].stopTracks).toHaveBeenCalled(); // expect(publishers[0].stopTracks).toHaveBeenCalled();
}); });
// TODO add tests for matrix local matrix participation. // TODO add tests for matrix local matrix participation.

View File

@@ -183,7 +183,6 @@ describe("Publisher", () => {
beforeEach(() => { beforeEach(() => {
publisher = new Publisher( publisher = new Publisher(
scope,
connection, connection,
mockMediaDevices({}), mockMediaDevices({}),
muteStates, 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 () => { it("Should not create tracks if started muted to avoid unneeded permission requests", async () => {
const createTracksSpy = vi.spyOn( const createTracksSpy = vi.spyOn(
@@ -267,7 +268,6 @@ describe("Publisher", () => {
let publisher: Publisher; let publisher: Publisher;
beforeEach(() => { beforeEach(() => {
publisher = new Publisher( publisher = new Publisher(
scope,
connection, connection,
mockMediaDevices({}), mockMediaDevices({}),
muteStates, muteStates,
@@ -275,6 +275,9 @@ describe("Publisher", () => {
logger, logger,
); );
}); });
afterEach(async () => {
await publisher.destroy();
});
test.each([ test.each([
{ mutes: { audioEnabled: true, videoEnabled: false } }, { mutes: { audioEnabled: true, videoEnabled: false } },
@@ -320,7 +323,6 @@ describe("Bug fix", () => {
it("wrongly publish tracks while muted", async () => { it("wrongly publish tracks while muted", async () => {
// setLogLevel(`debug`); // setLogLevel(`debug`);
const publisher = new Publisher( const publisher = new Publisher(
scope,
connection, connection,
mockMediaDevices({}), mockMediaDevices({}),
muteStates, muteStates,
@@ -356,5 +358,6 @@ describe("Bug fix", () => {
expect(track!.mute).toHaveBeenCalled(); expect(track!.mute).toHaveBeenCalled();
expect(track!.isMuted).toBe(true); expect(track!.isMuted).toBe(true);
} }
await publisher.destroy();
}); });
}); });