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
35 changes: 35 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,38 @@ 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("formats answer RTCSessionDescription to RTCSessionDescriptionInit", async () => {
const { toSessionDescriptionInit } = await import("./webrtc");
const desc = {
type: "answer" as RTCSdpType,
sdp: "v=0\r\no=- 654321 2 IN IP4 127.0.0.1\r\n",
toJSON: () => ({}),
};
expect(toSessionDescriptionInit(desc as RTCSessionDescription)).toEqual({
type: "answer",
sdp: "v=0\r\no=- 654321 2 IN IP4 127.0.0.1\r\n",
});
});

it("throws error when session description is null or undefined", async () => {

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 invalid-input coverage

The test description names both null and undefined, but its only assertion passes null. This reports coverage for an undefined-input case that the test never executes, making future coverage assessments misleading.

Suggested change
it("throws error when session description is null or undefined", async () => {
it("throws error when session description is null", async () => {
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/chrome-extension/src/shared/webrtc.test.ts
Line: 81

Comment:
**Test overstates invalid-input coverage**

The test description names both `null` and `undefined`, but its only assertion passes `null`. This reports coverage for an undefined-input case that the test never executes, making future coverage assessments misleading.

```suggestion
	it("throws error when session description is null", async () => {
```

---

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

const { toSessionDescriptionInit } = await import("./webrtc");
expect(() => toSessionDescriptionInit(null)).toThrow(
"Missing session description",
);
});
});
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);
});
});