add test to check if publisher is properly destroyed
This commit is contained in:
@@ -297,11 +297,13 @@ describe("LocalMembership", () => {
|
|||||||
seed += 1;
|
seed += 1;
|
||||||
logger.info(`creating [${a}]`);
|
logger.info(`creating [${a}]`);
|
||||||
const p = {
|
const p = {
|
||||||
|
// It is enought to check if destroy is called. Destroy itself is tested in the publisher to make sure it does
|
||||||
|
// all the cleanup we need.
|
||||||
|
destroy: vi.fn(),
|
||||||
stopPublishing: vi.fn().mockImplementation(() => {
|
stopPublishing: vi.fn().mockImplementation(() => {
|
||||||
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;
|
||||||
@@ -359,6 +361,8 @@ describe("LocalMembership", () => {
|
|||||||
defaultCreateLocalMemberValues.createPublisherFactory.mockImplementation(
|
defaultCreateLocalMemberValues.createPublisherFactory.mockImplementation(
|
||||||
() => {
|
() => {
|
||||||
const p = {
|
const p = {
|
||||||
|
// It is enought to check if destroy is called. Destroy itself is tested in the publisher to make sure it does
|
||||||
|
// all the cleanup we need.
|
||||||
destroy: vi.fn(),
|
destroy: vi.fn(),
|
||||||
createAndSetupTracks: vi.fn().mockImplementation(async () => {
|
createAndSetupTracks: vi.fn().mockImplementation(async () => {
|
||||||
tracks$.next([{}, {}] as LocalTrack[]);
|
tracks$.next([{}, {}] as LocalTrack[]);
|
||||||
@@ -421,6 +425,8 @@ describe("LocalMembership", () => {
|
|||||||
defaultCreateLocalMemberValues.createPublisherFactory.mockImplementation(
|
defaultCreateLocalMemberValues.createPublisherFactory.mockImplementation(
|
||||||
() => {
|
() => {
|
||||||
const p = {
|
const p = {
|
||||||
|
// It is enought to check if destroy is called. Destroy itself is tested in the publisher to make sure it does
|
||||||
|
// all the cleanup we need.
|
||||||
destroy: vi.fn(),
|
destroy: vi.fn(),
|
||||||
createAndSetupTracks: vi.fn().mockImplementation(async () => {
|
createAndSetupTracks: vi.fn().mockImplementation(async () => {
|
||||||
await createTrackResolver.promise;
|
await createTrackResolver.promise;
|
||||||
|
|||||||
@@ -209,10 +209,35 @@ describe("Publisher", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should unsetHandler and stop tracks on destroy", async () => {
|
it("should unsetHandler and stop tracks on destroy", async () => {
|
||||||
|
// setup all spies
|
||||||
|
const unsetVideoSpy = vi.spyOn(
|
||||||
|
(
|
||||||
|
publisher as unknown as {
|
||||||
|
muteStates: { video: { unsetHandler: () => void } };
|
||||||
|
}
|
||||||
|
).muteStates.video,
|
||||||
|
"unsetHandler",
|
||||||
|
);
|
||||||
|
const unsetAudioSpy = vi.spyOn(
|
||||||
|
(
|
||||||
|
publisher as unknown as {
|
||||||
|
muteStates: { audio: { unsetHandler: () => void } };
|
||||||
|
}
|
||||||
|
).muteStates.audio,
|
||||||
|
"unsetHandler",
|
||||||
|
);
|
||||||
|
const scopeEndSpy = vi.spyOn(
|
||||||
|
(publisher as unknown as { scope: { end: () => void } }).scope,
|
||||||
|
"end",
|
||||||
|
);
|
||||||
|
const stopTracksSpy = vi.spyOn(publisher, "stopTracks");
|
||||||
|
// destroy publisher
|
||||||
await publisher.destroy();
|
await publisher.destroy();
|
||||||
expect(publisher.stopTracks).toHaveBeenCalled();
|
|
||||||
expect( this.muteStates.audio.unsetHandler();
|
expect(stopTracksSpy).toHaveBeenCalledOnce();
|
||||||
this.muteStates.video.unsetHandler();).toHaveBeenCalled();
|
expect(unsetVideoSpy).toHaveBeenCalledOnce();
|
||||||
|
expect(unsetAudioSpy).toHaveBeenCalledOnce();
|
||||||
|
expect(scopeEndSpy).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should minimize permission request by querying create at once", async () => {
|
it("Should minimize permission request by querying create at once", async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user