Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions apps/chrome-extension/src/shared/webrtc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,26 @@ describe("waitForIceGatheringComplete", () => {
);
});
});

describe("toSessionDescriptionInit", () => {
it("formats valid RTCSessionDescription to RTCSessionDescriptionInit", async () => {
const { toSessionDescriptionInit } = await import("./webrtc");
const desc = {
type: "offer" as RTCSdpType,
sdp: "v=0\r\no=- 123456 2 IN IP4 127.0.0.1\r\n",
toJSON: () => ({}),
};
expect(toSessionDescriptionInit(desc as RTCSessionDescription)).toEqual({
type: "offer",
sdp: "v=0\r\no=- 123456 2 IN IP4 127.0.0.1\r\n",
});
});

it("throws error when session description is null or undefined", async () => {
const { toSessionDescriptionInit } = await import("./webrtc");
expect(() => toSessionDescriptionInit(null)).toThrow(
"Missing session description",
);
});
Comment on lines +68 to +73

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Test overstates undefined coverage

This test says it covers both null and undefined, but its only assertion passes null, leaving the description inconsistent with the behavior actually exercised.

Suggested change
it("throws error when session description is null or undefined", async () => {
const { toSessionDescriptionInit } = await import("./webrtc");
expect(() => toSessionDescriptionInit(null)).toThrow(
"Missing session description",
);
});
it("throws error when session description is null", async () => {
const { toSessionDescriptionInit } = await import("./webrtc");
expect(() => toSessionDescriptionInit(null)).toThrow(
"Missing session description",
);
});
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/chrome-extension/src/shared/webrtc.test.ts
Line: 68-73

Comment:
**Test overstates undefined coverage**

This test says it covers both `null` and `undefined`, but its only assertion passes `null`, leaving the description inconsistent with the behavior actually exercised.

```suggestion
	it("throws error when session description is null", async () => {
		const { toSessionDescriptionInit } = await import("./webrtc");
		expect(() => toSessionDescriptionInit(null)).toThrow(
			"Missing session description",
		);
	});
```

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

});

75 changes: 75 additions & 0 deletions packages/recorder-core/__tests__/recorder-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,78 @@ describe("openShareUrlInNewTab", () => {
expect(openShareUrlInNewTab("")).toBe(false);
});
});

describe("detectRecordingModeFromTrack", () => {
it("returns null when track is null", async () => {
const { detectRecordingModeFromTrack } = await import(
"@cap/recorder-core/recorder-utils"
);
expect(detectRecordingModeFromTrack(null)).toBeNull();
});

it("detects fullscreen, window, and tab from track label heuristics", async () => {
const { detectRecordingModeFromTrack } = await import(
"@cap/recorder-core/recorder-utils"
);
const screenTrack = {
label: "Entire Screen 1",
getSettings: () => ({}),
} as unknown as MediaStreamTrack;
const windowTrack = {
label: "Application Window (Cap)",
getSettings: () => ({}),
} as unknown as MediaStreamTrack;
const tabTrack = {
label: "Browser Tab - YouTube",
getSettings: () => ({}),
} as unknown as MediaStreamTrack;

expect(detectRecordingModeFromTrack(screenTrack)).toBe("fullscreen");
expect(detectRecordingModeFromTrack(windowTrack)).toBe("window");
expect(detectRecordingModeFromTrack(tabTrack)).toBe("tab");
});
});

describe("error retry utilities", () => {
it("identifies user cancellation errors correctly", async () => {
const { isUserCancellationError } = await import(
"@cap/recorder-core/recorder-utils"
);
const notAllowed = new DOMException("Permission denied", "NotAllowedError");
const abort = new DOMException("Aborted by user", "AbortError");
const other = new DOMException("Format unsupported", "NotSupportedError");

expect(isUserCancellationError(notAllowed)).toBe(true);
expect(isUserCancellationError(abort)).toBe(true);
expect(isUserCancellationError(other)).toBe(false);
expect(isUserCancellationError(new Error("generic error"))).toBe(false);
});

it("identifies retryable display media preference errors", async () => {
const { shouldRetryDisplayMediaWithoutPreferences } = await import(
"@cap/recorder-core/recorder-utils"
);
const notSupported = new DOMException(
"Preferences not supported",
"NotSupportedError",
);
const overconstrained = new DOMException(
"Constraint unfulfilled",
"OverconstrainedError",
);
const invalidAccess = new DOMException(
"Invalid access",
"InvalidAccessError",
);
const typeError = new TypeError("Invalid parameter");
const notAllowed = new DOMException("Permission denied", "NotAllowedError");

expect(shouldRetryDisplayMediaWithoutPreferences(notSupported)).toBe(true);
expect(shouldRetryDisplayMediaWithoutPreferences(overconstrained)).toBe(
true,
);
expect(shouldRetryDisplayMediaWithoutPreferences(invalidAccess)).toBe(true);
expect(shouldRetryDisplayMediaWithoutPreferences(typeError)).toBe(true);
expect(shouldRetryDisplayMediaWithoutPreferences(notAllowed)).toBe(false);
});
});