-
Notifications
You must be signed in to change notification settings - Fork 1.6k
test: add package-level Vitest examples #1818
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
Closed
NeurArk
wants to merge
4
commits into
CapSoftware:main
from
NeurArk:test/issue-54-monorepo-bootstrap
Closed
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { createEmbedUrl } from "./cap-embed"; | ||
|
|
||
| describe("createEmbedUrl", () => { | ||
| it("builds a default Cap embed URL with SDK and public-key markers", () => { | ||
| const url = new URL( | ||
| createEmbedUrl({ videoId: "video-123", publicKey: "pk_test" }), | ||
| ); | ||
|
|
||
| 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"); | ||
| }); | ||
|
|
||
| it("includes autoplay and branding options when provided", () => { | ||
| const url = new URL( | ||
| createEmbedUrl({ | ||
| videoId: "video-123", | ||
| publicKey: "pk_live", | ||
| apiBase: "https://app.example.com", | ||
| autoplay: true, | ||
| branding: { | ||
| logoUrl: "https://cdn.example.com/logo.png", | ||
| accentColor: "#ff00aa", | ||
| }, | ||
| }), | ||
| ); | ||
|
|
||
| expect(url.origin).toBe("https://app.example.com"); | ||
| expect(url.searchParams.get("autoplay")).toBe("1"); | ||
| expect(url.searchParams.get("logo")).toBe( | ||
| "https://cdn.example.com/logo.png", | ||
| ); | ||
| expect(url.searchParams.get("accent")).toBe("#ff00aa"); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import { afterEach, describe, expect, it, vi } from "vitest"; | ||
| import { getSupportedMimeType } from "./mime-types"; | ||
|
|
||
| describe("getSupportedMimeType", () => { | ||
| afterEach(() => { | ||
| vi.unstubAllGlobals(); | ||
| }); | ||
|
|
||
| it("returns the first supported preferred MIME type", () => { | ||
| vi.stubGlobal("MediaRecorder", { | ||
| isTypeSupported: (mimeType: string) => | ||
| mimeType === "video/webm;codecs=vp8,opus", | ||
| }); | ||
|
|
||
| expect(getSupportedMimeType()).toBe("video/webm;codecs=vp8,opus"); | ||
| }); | ||
|
|
||
| it("returns an empty string when the browser supports none of the preferred types", () => { | ||
| vi.stubGlobal("MediaRecorder", { | ||
| isTypeSupported: () => false, | ||
| }); | ||
|
|
||
| expect(getSupportedMimeType()).toBe(""); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { | ||
| calculateStrokeDashoffset, | ||
| classNames, | ||
| getDisplayProgress, | ||
| getProgressCircleConfig, | ||
| isEmailAllowedByRestriction, | ||
| uuidFormat, | ||
| uuidParse, | ||
| } from "./helpers"; | ||
|
|
||
| describe("helpers", () => { | ||
| it("merges conditional class names and resolves Tailwind conflicts", () => { | ||
| expect(classNames("p-2", false && "hidden", "p-4", ["text-sm"])).toBe( | ||
| "p-4 text-sm", | ||
| ); | ||
| }); | ||
|
|
||
| it("round-trips UUIDs between dashed and compact forms", () => { | ||
| const dashed = "123e4567-e89b-12d3-a456-426614174000"; | ||
| const compact = "123e4567e89b12d3a456426614174000"; | ||
|
|
||
| expect(uuidParse(dashed)).toBe(compact); | ||
| expect(uuidFormat(compact)).toBe(dashed); | ||
| }); | ||
|
|
||
| it("keeps zero upload progress as the displayed progress", () => { | ||
| expect(getDisplayProgress(0, 75)).toBe(0); | ||
| expect(getDisplayProgress(undefined, 75)).toBe(75); | ||
| }); | ||
|
|
||
| it("calculates circular progress stroke offsets", () => { | ||
| const { circumference } = getProgressCircleConfig(); | ||
|
|
||
| expect(calculateStrokeDashoffset(0, circumference)).toBe(circumference); | ||
| expect(calculateStrokeDashoffset(100, circumference)).toBe(0); | ||
| }); | ||
|
|
||
| it("allows exact emails and domain restrictions case-insensitively", () => { | ||
| expect( | ||
| isEmailAllowedByRestriction( | ||
| "Founders@Cap.so", | ||
| "team@example.com, cap.so", | ||
| ), | ||
| ).toBe(true); | ||
| expect( | ||
| isEmailAllowedByRestriction( | ||
| "team@example.com", | ||
| "team@example.com, cap.so", | ||
| ), | ||
| ).toBe(true); | ||
| expect( | ||
| isEmailAllowedByRestriction("team@other.com", "team@example.com, cap.so"), | ||
| ).toBe(false); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import { Cause, Effect, Option } from "effect"; | ||
| import { describe, expect, it } from "vitest"; | ||
| import { publicPolicy, withPublicPolicy } from "./Policy"; | ||
|
|
||
| describe("publicPolicy", () => { | ||
| it("allows an effect when the public predicate succeeds", async () => { | ||
| const result = await Effect.runPromise( | ||
| Effect.succeed("allowed").pipe( | ||
| withPublicPolicy( | ||
| publicPolicy((user) => Effect.succeed(Option.isNone(user))), | ||
| ), | ||
| ), | ||
| ); | ||
|
|
||
| expect(result).toBe("allowed"); | ||
| }); | ||
|
|
||
| it("fails with PolicyDeniedError when the public predicate denies access", async () => { | ||
| const exit = await Effect.runPromiseExit( | ||
| publicPolicy(() => Effect.succeed(false)), | ||
| ); | ||
|
|
||
| expect(exit._tag).toBe("Failure"); | ||
| if (exit._tag === "Failure") { | ||
| expect(Cause.pretty(exit.cause)).toContain("PolicyDenied"); | ||
| } | ||
| }); | ||
| }); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
vitest.config.tsacross new packagesNone of the four new packages (
@cap/utils,@cap/sdk-embed,@cap/sdk-recorder,@cap/web-domain) ship avitest.config.ts. Vitest will fall back to its built-in defaults, which works here because all test imports use relative paths and no DOM environment is required. However, without an explicit config thetsconfigpath aliases (if any are added later) won't be resolved, and the test environment can't be pinned — making the setup fragile as coverage grows. The existingapps/desktop/vitest.config.tsis a handy reference for what a minimal config looks like.Prompt To Fix With AI