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
1 change: 1 addition & 0 deletions apps/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"localdev": "dotenv -e ../../.env -- vinxi dev --port 3002",
"build": "vinxi build",
"tauri": "tauri",
"test": "vitest run",
"test:memory": "node scripts/desktop-memory-soak.js",
"test:memory:unit": "vitest run scripts/desktop-memory-soak.test.js"
},
Expand Down
6 changes: 4 additions & 2 deletions apps/storybook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"type": "module",
"scripts": {
"dev:storybook": "storybook dev -p 6006",
"build:storybook": "storybook build"
"build:storybook": "storybook build",
"test": "vitest run"
},
"dependencies": {
"@cap/ui-solid": "workspace:*",
Expand All @@ -25,6 +26,7 @@
"storybook-solidjs-vite": "^1.0.0-beta.2",
"typescript": "^5.8.3",
"vite": "^6.3.5",
"vite-plugin-solid": "^2.10.2"
"vite-plugin-solid": "^2.10.2",
"vitest": "~2.1.9"
}
}
9 changes: 9 additions & 0 deletions apps/storybook/storybook-vite.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { describe, expect, it } from "vitest";
import config from "./vite.config";

describe("storybook Vite config", () => {
it("loads Solid and Cap UI plugins", () => {
expect(Array.isArray(config.plugins)).toBe(true);
expect(config.plugins).toHaveLength(2);
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 Plugin-count assertion is fragile

toHaveLength(2) checks the number of top-level entries in the raw plugins array literal — it passes regardless of whether the plugins are correct objects and will break silently when a third plugin is added to the config. Consider asserting on plugin identity instead (e.g. checking a plugin's name field), or at minimum checking >= 2.

Suggested change
expect(config.plugins).toHaveLength(2);
expect(config.plugins!.length).toBeGreaterThanOrEqual(2);
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/storybook/storybook-vite.test.ts
Line: 7

Comment:
**Plugin-count assertion is fragile**

`toHaveLength(2)` checks the number of top-level entries in the raw `plugins` array literal — it passes regardless of whether the plugins are correct objects and will break silently when a third plugin is added to the config. Consider asserting on plugin identity instead (e.g. checking a plugin's `name` field), or at minimum checking `>= 2`.

```suggestion
		expect(config.plugins!.length).toBeGreaterThanOrEqual(2);
```

How can I resolve this? If you propose a fix, please make it concise.

});
});
8 changes: 8 additions & 0 deletions apps/storybook/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
environment: "node",
include: ["**/*.test.ts"],
},
});
6 changes: 4 additions & 2 deletions apps/web-cluster/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"scripts": {
"dev_": "pnpm dotenv -e ../../.env -- concurrently \"deno run --allow-all --watch ./src/runner/index.ts\" \"deno run --allow-all --watch ./src/shard-manager.ts\"",
"build": "pnpm run --filter @cap/web-cluster^... build",
"build:docker": "cd ../.. && docker build -f apps/web-cluster/Dockerfile -t ghcr.io/brendonovich/cap-web-cluster:latest ."
"build:docker": "cd ../.. && docker build -f apps/web-cluster/Dockerfile -t ghcr.io/brendonovich/cap-web-cluster:latest .",
"test": "vitest run"
},
"dependencies": {
"@cap/web-backend": "workspace:*",
Expand All @@ -26,6 +27,7 @@
},
"devDependencies": {
"concurrently": "^9.2.1",
"dotenv-cli": "^10.0.0"
"dotenv-cli": "^10.0.0",
"vitest": "~2.1.9"
}
}
47 changes: 47 additions & 0 deletions apps/web-cluster/src/cluster/container-metadata.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { Effect } from "effect";
import { afterEach, describe, expect, it, vi } from "vitest";
import { ContainerMetadata } from "./container-metadata";

const originalEnv = { ...process.env };

afterEach(() => {
process.env = { ...originalEnv };
vi.unstubAllGlobals();
});

function getContainerMetadata() {
return Effect.gen(function* () {
return yield* ContainerMetadata;
}).pipe(Effect.provide(ContainerMetadata.Default));
}

describe("ContainerMetadata", () => {
it("uses local defaults when ECS metadata is unavailable", async () => {
delete process.env.ECS_CONTAINER_METADATA_URI_V4;
delete process.env.PORT;

const metadata = await Effect.runPromise(getContainerMetadata());

expect(metadata).toEqual({ ipAddress: "0.0.0.0", port: 42069 });
});

it("reads container IP and port from the runtime environment", async () => {
process.env.ECS_CONTAINER_METADATA_URI_V4 = "http://metadata.local";
process.env.PORT = "5173";
const fetchMock = vi.fn(async () => ({
json: async () => ({
Containers: [
{
Networks: [{ IPv4Addresses: ["10.0.0.42"] }],
},
],
}),
}));
vi.stubGlobal("fetch", fetchMock);

const metadata = await Effect.runPromise(getContainerMetadata());

expect(fetchMock).toHaveBeenCalledWith("http://metadata.local/task");
expect(metadata).toEqual({ ipAddress: "10.0.0.42", port: 5173 });
});
});
8 changes: 8 additions & 0 deletions apps/web-cluster/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
environment: "node",
include: ["src/**/*.test.ts"],
},
});
6 changes: 5 additions & 1 deletion packages/config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
"./*": "./*",
"./vite": "./vite"
},
"scripts": {
"test": "vitest run"
},
"devDependencies": {
"@types/node": "^20.4.5",
"@typescript-eslint/eslint-plugin": "^5.59.6",
Expand All @@ -17,7 +20,8 @@
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-tailwindcss": "^3.12.0",
"eslint-utils": "^3.0.0"
"eslint-utils": "^3.0.0",
"vitest": "~2.1.9"
},
"dependencies": {
"@vitejs/plugin-react": "^4.0.3",
Expand Down
32 changes: 32 additions & 0 deletions packages/config/vite/relativeAliasResolver.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { afterEach, describe, expect, it } from "vitest";
import resolver from "./relativeAliasResolver";

let testRoot: string | undefined;

afterEach(async () => {
if (testRoot) await rm(testRoot, { recursive: true, force: true });
testRoot = undefined;
});

describe("relativeAliasResolver", () => {
it("resolves ~/ imports relative to a package src directory", async () => {
testRoot = await mkdtemp(join(tmpdir(), "cap-alias-"));
await mkdir(join(testRoot, "src", "nested"), { recursive: true });
await writeFile(join(testRoot, "package.json"), "{}");
await writeFile(join(testRoot, "src", "nested", "target.ts"), "");

const customResolver = resolver.customResolver;
if (!customResolver) throw new Error("customResolver is not configured");

const resolved = await customResolver(
"~/nested/target",
join(testRoot, "src", "importer.ts"),
{},
);

expect(resolved).toBe(join(testRoot, "src", "nested", "target.ts"));
});
});
8 changes: 8 additions & 0 deletions packages/config/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
environment: "node",
include: ["**/*.test.ts"],
},
});
21 changes: 21 additions & 0 deletions packages/database/crypto.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { describe, expect, it } from "vitest";
import { hashPassword, verifyPassword } from "./crypto";

describe("password hashing", () => {
it("verifies matching passwords and rejects mismatches", async () => {
const hash = await hashPassword("correct horse battery staple");

await expect(
verifyPassword(hash, "correct horse battery staple"),
).resolves.toBe(true);
await expect(verifyPassword(hash, "wrong password")).resolves.toBe(false);
});

it("rejects empty stored hashes or password input", async () => {
await expect(verifyPassword("", "password")).resolves.toBe(false);
await expect(verifyPassword("stored", "")).resolves.toBe(false);
await expect(hashPassword("")).rejects.toThrow(
"Cannot hash empty or null password",
);
});
});
6 changes: 4 additions & 2 deletions packages/database/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"db:studio": "drizzle-kit studio --config=drizzle.config.ts",
"db:check-integrity": "node scripts/check-migration-integrity.js",
"drizzle-kit": "pnpm dotenv -e ../../.env drizzle-kit --config=drizzle.config.ts",
"build": "tsdown"
"build": "tsdown",
"test": "vitest run"
},
"dependencies": {
"@cap/env": "workspace:*",
Expand Down Expand Up @@ -50,7 +51,8 @@
"react-dom": "^19.1.1",
"react-router-dom": "^6.18.0",
"tsconfig": "workspace:*",
"typescript": "^5.8.3"
"typescript": "^5.8.3",
"vitest": "~2.1.9"
},
"engines": {
"node": ">=20"
Expand Down
8 changes: 8 additions & 0 deletions packages/database/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
environment: "node",
include: ["**/*.test.ts"],
},
});
32 changes: 32 additions & 0 deletions packages/env/build.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";

const originalEnv = { ...process.env };

beforeEach(() => {
process.env = { ...originalEnv };
vi.resetModules();
});

afterEach(() => {
process.env = { ...originalEnv };
});

describe("buildEnv", () => {
it("uses WEB_URL as the public web URL when present", async () => {
process.env.WEB_URL = "https://web-url.example";
process.env.NEXT_PUBLIC_WEB_URL = "https://next-public.example";

const { buildEnv } = await import("./build");

expect(buildEnv.NEXT_PUBLIC_WEB_URL).toBe("https://web-url.example");
});

it("falls back to NEXT_PUBLIC_WEB_URL when WEB_URL is absent", async () => {
delete process.env.WEB_URL;
process.env.NEXT_PUBLIC_WEB_URL = "https://next-public.example";

const { buildEnv } = await import("./build");

expect(buildEnv.NEXT_PUBLIC_WEB_URL).toBe("https://next-public.example");
});
});
6 changes: 4 additions & 2 deletions packages/env/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"main": "./index.ts",
"types": "./index.ts",
"scripts": {
"build": "tsdown"
"build": "tsdown",
"test": "vitest run"
},
"publishConfig": {
"main": "./dist/index.js"
Expand All @@ -15,6 +16,7 @@
"zod": "^3.25.76"
},
"devDependencies": {
"@types/node": "^22.15.14"
"@types/node": "^22.15.14",
"vitest": "~2.1.9"
}
}
8 changes: 8 additions & 0 deletions packages/env/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
environment: "node",
include: ["**/*.test.ts"],
},
});
4 changes: 3 additions & 1 deletion packages/sdk-embed/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
],
"scripts": {
"build": "tsup",
"test": "vitest run",
"typecheck": "tsc --noEmit"
},
"dependencies": {},
Expand All @@ -39,6 +40,7 @@
"@types/react": "^19.0.0",
"@types/react-dom": "^19.0.0",
"tsup": "^8.0.0",
"typescript": "^5.7.3"
"typescript": "^5.7.3",
"vitest": "~2.1.9"
}
}
30 changes: 30 additions & 0 deletions packages/sdk-embed/src/vanilla/cap-embed.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { describe, expect, it } from "vitest";
import { createEmbedUrl } from "./cap-embed";

describe("createEmbedUrl", () => {
it("builds the default Cap embed URL", () => {
const url = createEmbedUrl({
videoId: "video_123",
publicKey: "pk_test",
});

expect(url).toBe("https://cap.so/embed/video_123?sdk=1&pk=pk_test");
});

it("includes optional base, playback, and branding parameters", () => {
const url = createEmbedUrl({
videoId: "video_123",
publicKey: "pk_test",
apiBase: "https://app.example",
autoplay: true,
branding: {
logoUrl: "https://cdn.example/logo.png",
accentColor: "#abcdef",
},
});

expect(url).toBe(
"https://app.example/embed/video_123?sdk=1&pk=pk_test&autoplay=1&logo=https%3A%2F%2Fcdn.example%2Flogo.png&accent=%23abcdef",
);
});
});
8 changes: 8 additions & 0 deletions packages/sdk-embed/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
environment: "node",
include: ["src/**/*.test.ts"],
},
});
4 changes: 3 additions & 1 deletion packages/sdk-recorder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
],
"scripts": {
"build": "tsup",
"test": "vitest run",
"typecheck": "tsc --noEmit"
},
"dependencies": {},
Expand All @@ -35,6 +36,7 @@
"@types/react": "^19.0.0",
"@types/react-dom": "^19.0.0",
"tsup": "^8.0.0",
"typescript": "^5.7.3"
"typescript": "^5.7.3",
"vitest": "~2.1.9"
}
}
24 changes: 24 additions & 0 deletions packages/sdk-recorder/src/core/mime-types.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import { getSupportedMimeType } from "./mime-types";

afterEach(() => {
vi.unstubAllGlobals();
});

describe("getSupportedMimeType", () => {
it("selects the first supported MIME type by priority", () => {
vi.stubGlobal("MediaRecorder", {
isTypeSupported: vi.fn((mimeType: string) => mimeType.includes("vp8")),
});

expect(getSupportedMimeType()).toBe("video/webm;codecs=vp8,opus");
});

it("returns an empty string when no preferred type is supported", () => {
vi.stubGlobal("MediaRecorder", {
isTypeSupported: vi.fn(() => false),
});

expect(getSupportedMimeType()).toBe("");
});
});
Loading