-
Notifications
You must be signed in to change notification settings - Fork 1.6k
test: bootstrap Vitest coverage across JS workspaces #1841
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
Open
partyplatter08-lab
wants to merge
3
commits into
CapSoftware:main
Choose a base branch
from
partyplatter08-lab:partyplatter08-lab/bounty-54
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 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,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); | ||
| }); | ||
| }); | ||
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,8 @@ | ||
| import { defineConfig } from "vitest/config"; | ||
|
|
||
| export default defineConfig({ | ||
| test: { | ||
| environment: "node", | ||
| include: ["**/*.test.ts"], | ||
| }, | ||
| }); |
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,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 }); | ||
| }); | ||
| }); |
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,8 @@ | ||
| import { defineConfig } from "vitest/config"; | ||
|
|
||
| export default defineConfig({ | ||
| test: { | ||
| environment: "node", | ||
| include: ["src/**/*.test.ts"], | ||
| }, | ||
| }); |
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,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")); | ||
| }); | ||
| }); |
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,8 @@ | ||
| import { defineConfig } from "vitest/config"; | ||
|
|
||
| export default defineConfig({ | ||
| test: { | ||
| environment: "node", | ||
| include: ["**/*.test.ts"], | ||
| }, | ||
| }); |
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,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", | ||
| ); | ||
| }); | ||
| }); |
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,8 @@ | ||
| import { defineConfig } from "vitest/config"; | ||
|
|
||
| export default defineConfig({ | ||
| test: { | ||
| environment: "node", | ||
| include: ["**/*.test.ts"], | ||
| }, | ||
| }); |
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,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"); | ||
| }); | ||
| }); |
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,8 @@ | ||
| import { defineConfig } from "vitest/config"; | ||
|
|
||
| export default defineConfig({ | ||
| test: { | ||
| environment: "node", | ||
| include: ["**/*.test.ts"], | ||
| }, | ||
| }); |
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,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", | ||
| ); | ||
| }); | ||
| }); |
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,8 @@ | ||
| import { defineConfig } from "vitest/config"; | ||
|
|
||
| export default defineConfig({ | ||
| test: { | ||
| environment: "node", | ||
| include: ["src/**/*.test.ts"], | ||
| }, | ||
| }); |
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,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(""); | ||
| }); | ||
| }); |
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.
toHaveLength(2)checks the number of top-level entries in the rawpluginsarray 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'snamefield), or at minimum checking>= 2.Prompt To Fix With AI