-
Notifications
You must be signed in to change notification settings - Fork 1.5k
test: add package-level Vitest examples #1819
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { createEmbedUrl } from "./cap-embed"; | ||
|
|
||
| describe("createEmbedUrl", () => { | ||
| it("builds a default Cap embed URL", () => { | ||
| const url = new URL( | ||
| createEmbedUrl({ | ||
| videoId: "video_123", | ||
| publicKey: "pk_test_123", | ||
| }), | ||
| ); | ||
|
|
||
| expect(url.origin).toBe("https://cap.so"); | ||
| expect(url.pathname).toBe("/embed/video_123"); | ||
| expect(url.searchParams.get("sdk")).toBe("1"); | ||
| expect(url.searchParams.get("pk")).toBe("pk_test_123"); | ||
| expect(url.searchParams.has("autoplay")).toBe(false); | ||
| }); | ||
|
|
||
| it("includes optional playback and branding parameters", () => { | ||
| const url = new URL( | ||
| createEmbedUrl({ | ||
| apiBase: "https://app.example.com", | ||
| videoId: "video_456", | ||
| publicKey: "pk_live_456", | ||
| autoplay: true, | ||
| branding: { | ||
| logoUrl: "https://cdn.example.com/logo.svg", | ||
| accentColor: "#ff3366", | ||
| }, | ||
| }), | ||
| ); | ||
|
|
||
| expect(url.origin).toBe("https://app.example.com"); | ||
| expect(url.pathname).toBe("/embed/video_456"); | ||
| expect(url.searchParams.get("sdk")).toBe("1"); | ||
| expect(url.searchParams.get("pk")).toBe("pk_live_456"); | ||
| expect(url.searchParams.get("autoplay")).toBe("1"); | ||
| expect(url.searchParams.get("logo")).toBe( | ||
| "https://cdn.example.com/logo.svg", | ||
| ); | ||
| expect(url.searchParams.get("accent")).toBe("#ff3366"); | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,42 @@ | ||||||||||||||||||||||||||||||||||||||||
| import { afterEach, describe, expect, it, vi } from "vitest"; | ||||||||||||||||||||||||||||||||||||||||
| import { getSupportedMimeType } from "./mime-types"; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| const originalMediaRecorder = globalThis.MediaRecorder; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| afterEach(() => { | ||||||||||||||||||||||||||||||||||||||||
| if (originalMediaRecorder) { | ||||||||||||||||||||||||||||||||||||||||
| globalThis.MediaRecorder = originalMediaRecorder; | ||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||
| delete (globalThis as { MediaRecorder?: typeof MediaRecorder }) | ||||||||||||||||||||||||||||||||||||||||
| .MediaRecorder; | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| const setSupportedMimeTypes = (mimeTypes: ReadonlyArray<string>) => { | ||||||||||||||||||||||||||||||||||||||||
| globalThis.MediaRecorder = { | ||||||||||||||||||||||||||||||||||||||||
| isTypeSupported: vi.fn((mimeType: string) => mimeTypes.includes(mimeType)), | ||||||||||||||||||||||||||||||||||||||||
| } as unknown as typeof MediaRecorder; | ||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| describe("getSupportedMimeType", () => { | ||||||||||||||||||||||||||||||||||||||||
| it("returns the first supported MIME type by preference order", () => { | ||||||||||||||||||||||||||||||||||||||||
| setSupportedMimeTypes(["video/webm;codecs=vp8,opus", "video/webm"]); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| expect(getSupportedMimeType()).toBe("video/webm;codecs=vp8,opus"); | ||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+22
to
+26
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Prompt To Fix With AIThis is a comment left during a code review.
Path: packages/sdk-recorder/src/core/mime-types.test.ts
Line: 22-26
Comment:
The test title claims it verifies "first supported MIME type by preference order", but the mock only marks `vp8,opus` and `video/webm` as supported — so `vp9,opus` is simply absent. The test never exercises the case where a higher-priority type wins over a lower-priority one that is also available. If someone accidentally swapped the first two entries in `PREFERRED_MIME_TYPES`, this test would still pass. Adding a case where both `vp9,opus` and `vp8,opus` are supported confirms the priority ordering is actually enforced.
```suggestion
it("returns the first supported MIME type by preference order", () => {
setSupportedMimeTypes(["video/webm;codecs=vp8,opus", "video/webm"]);
expect(getSupportedMimeType()).toBe("video/webm;codecs=vp8,opus");
});
it("prefers vp9,opus over vp8,opus when both are supported", () => {
setSupportedMimeTypes([
"video/webm;codecs=vp9,opus",
"video/webm;codecs=vp8,opus",
]);
expect(getSupportedMimeType()).toBe("video/webm;codecs=vp9,opus");
});
```
How can I resolve this? If you propose a fix, please make it concise. |
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| it("prefers vp9,opus over vp8,opus when both are supported", () => { | ||||||||||||||||||||||||||||||||||||||||
| setSupportedMimeTypes([ | ||||||||||||||||||||||||||||||||||||||||
| "video/webm;codecs=vp9,opus", | ||||||||||||||||||||||||||||||||||||||||
| "video/webm;codecs=vp8,opus", | ||||||||||||||||||||||||||||||||||||||||
| ]); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| expect(getSupportedMimeType()).toBe("video/webm;codecs=vp9,opus"); | ||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| it("falls back to an empty string when no preferred types are supported", () => { | ||||||||||||||||||||||||||||||||||||||||
| setSupportedMimeTypes([]); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| expect(getSupportedMimeType()).toBe(""); | ||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import { Option } from "effect"; | ||
| import { describe, expect, it } from "vitest"; | ||
| import { extractFileKey } from "./ImageUpload"; | ||
|
|
||
| const unwrap = <A>(option: Option.Option<A>) => | ||
| Option.isSome(option) ? option.value : undefined; | ||
|
|
||
| describe("extractFileKey", () => { | ||
| it("keeps existing image keys unchanged", () => { | ||
| expect(unwrap(extractFileKey("users/user-1/avatar.png", false))).toBe( | ||
| "users/user-1/avatar.png", | ||
| ); | ||
| }); | ||
|
|
||
| it("extracts keys from virtual-hosted S3 URLs", () => { | ||
| expect( | ||
| unwrap( | ||
| extractFileKey("https://assets.cap.so/users/user-1/avatar.png", false), | ||
| ), | ||
| ).toBe("users/user-1/avatar.png"); | ||
| }); | ||
|
|
||
| it("drops the bucket segment for path-style S3 URLs", () => { | ||
| expect( | ||
| unwrap( | ||
| extractFileKey( | ||
| "https://s3.us-east-1.amazonaws.com/cap-bucket/users/user-1/avatar.png", | ||
| true, | ||
| ), | ||
| ), | ||
| ).toBe("users/user-1/avatar.png"); | ||
| }); | ||
|
|
||
| it("ignores Google profile image URLs", () => { | ||
| expect( | ||
| Option.isNone( | ||
| extractFileKey( | ||
| "https://lh3.googleusercontent.com/a/profile-image", | ||
| false, | ||
| ), | ||
| ), | ||
| ).toBe(true); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { | ||
| M3U8Source, | ||
| Mp4Source, | ||
| normalizeSegmentEntry, | ||
| SegmentsSource, | ||
| } from "./Video"; | ||
|
|
||
| describe("video source file keys", () => { | ||
| it("builds deterministic keys for MP4 sources", () => { | ||
| const source = new Mp4Source({ ownerId: "owner-1", videoId: "video-1" }); | ||
|
|
||
| expect(source.getFileKey()).toBe("owner-1/video-1/result.mp4"); | ||
| }); | ||
|
|
||
| it("builds deterministic keys for HLS playlist sources", () => { | ||
| const source = new M3U8Source({ | ||
| ownerId: "owner-1", | ||
| videoId: "video-1", | ||
| subpath: "combined-source/stream.m3u8", | ||
| }); | ||
|
|
||
| expect(source.getPlaylistFileKey()).toBe( | ||
| "owner-1/video-1/combined-source/stream.m3u8", | ||
| ); | ||
| }); | ||
|
|
||
| it("builds deterministic keys for segmented desktop recordings", () => { | ||
| const source = new SegmentsSource({ | ||
| ownerId: "owner-1", | ||
| videoId: "video-1", | ||
| }); | ||
|
|
||
| expect(source.getManifestKey()).toBe( | ||
| "owner-1/video-1/segments/manifest.json", | ||
| ); | ||
| expect(source.getVideoInitKey()).toBe( | ||
| "owner-1/video-1/segments/video/init.mp4", | ||
| ); | ||
| expect(source.getAudioInitKey()).toBe( | ||
| "owner-1/video-1/segments/audio/init.mp4", | ||
| ); | ||
| expect(source.getVideoSegmentKey(7)).toBe( | ||
| "owner-1/video-1/segments/video/segment_007.m4s", | ||
| ); | ||
| expect(source.getAudioSegmentKey(12)).toBe( | ||
| "owner-1/video-1/segments/audio/segment_012.m4s", | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe("normalizeSegmentEntry", () => { | ||
| it("uses the legacy default duration for numeric manifest entries", () => { | ||
| expect(normalizeSegmentEntry(4)).toEqual({ index: 4, duration: 3.0 }); | ||
| }); | ||
|
|
||
| it("preserves explicit segment durations", () => { | ||
| expect(normalizeSegmentEntry({ index: 2, duration: 1.5 })).toEqual({ | ||
| index: 2, | ||
| duration: 1.5, | ||
| }); | ||
| }); | ||
| }); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
publicKeyandsdkparams but never asserts their values.pkandsdkcould silently regress (e.g., a rename or removal) while this test still passes. Adding the two assertions closes that blind spot without any extra setup.Prompt To Fix With AI