Skip to content
Closed
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 .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:

- name: Run test
run: bun test
Comment on lines 35 to 36
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Update test command to use npm scripts.

The test command should use the newly added npm scripts instead of directly using bun.

-      - name: Run test
-        run: bun test
+      - name: Run test
+        run: bun run test:once
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: Run test
run: bun test
- name: Run test
run: bun run test:once


test-build:
runs-on: ubuntu-latest
steps:
Expand Down
61 changes: 61 additions & 0 deletions apps/docs/components/page/copy-button.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { afterEach, describe, expect, it, vi } from "vitest";
import { CopyButton } from "./copy-button";

// Mock Sentry
vi.mock("@sentry/nextjs", () => ({

Check failure on line 7 in apps/docs/components/page/copy-button.test.tsx

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

TypeError: vi.mock is not a function. (In 'vi.mock("@sentry/nextjs"

}))', 'vi.mock' is undefined) at /home/runner/work/ark.env/ark.env/apps/docs/components/page/copy-button.test.tsx:7:4

Check failure on line 7 in apps/docs/components/page/copy-button.test.tsx

View workflow job for this annotation

GitHub Actions / test (macos-latest)

TypeError: vi.mock is not a function. (In 'vi.mock("@sentry/nextjs"

}))', 'vi.mock' is undefined) at /Users/runner/work/ark.env/ark.env/apps/docs/components/page/copy-button.test.tsx:7:4
captureException: vi.fn(),
}));

// Mock the useToast hook
vi.mock("~/hooks/use-toast", () => ({
useToast: () => ({
toast: vi.fn(),
}),
}));

describe("CopyButton", () => {
afterEach(() => {
vi.restoreAllMocks();
});

it("renders with initial state", () => {
render(<CopyButton command="npm install" />);
expect(screen.getByRole("button")).toBeInTheDocument();
expect(screen.getByLabelText("Copy command")).toBeInTheDocument();
});

it("shows copied state when clicked", async () => {
const user = userEvent.setup();
const mockWriteText = vi.fn();

// Mock the clipboard API
const clipboardSpy = vi.spyOn(navigator.clipboard, "writeText");
clipboardSpy.mockImplementation(mockWriteText);

render(<CopyButton command="npm install" />);
const button = screen.getByRole("button");

await user.click(button);

expect(mockWriteText).toHaveBeenCalledWith("npm install");
expect(screen.getByLabelText("Copy command")).toBeInTheDocument();
});

it("handles clipboard error", async () => {
const user = userEvent.setup();

// Mock the clipboard API with an error
const clipboardSpy = vi.spyOn(navigator.clipboard, "writeText");
clipboardSpy.mockRejectedValue(new Error("Clipboard error"));

render(<CopyButton command="npm install" />);
const button = screen.getByRole("button");

await user.click(button);

expect(clipboardSpy).toHaveBeenCalledWith("npm install");
expect(screen.getByLabelText("Copy command")).toBeInTheDocument();
});
});
17 changes: 15 additions & 2 deletions apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
"dev": "next dev",
"start": "next start",
"postinstall": "fumadocs-mdx",
"clean": "rimraf node_modules"
"clean": "rimraf node_modules",
"test": "vitest",
"test:ui": "vitest --ui",
"test:once": "vitest run",
"coverage": "vitest run --coverage"
},
"dependencies": {
"@icons-pack/react-simple-icons": "^11.2.0",
Expand Down Expand Up @@ -38,6 +42,15 @@
"@types/mdx": "^2.0.13",
"@tailwindcss/postcss": "^4.0.3",
"tailwindcss": "^4.0.3",
"postcss": "^8.5.1"
"postcss": "^8.5.1",
"@testing-library/react": "^14.2.1",
"@testing-library/user-event": "^14.5.2",
"@vitejs/plugin-react": "^4.2.1",
"@vitest/coverage-v8": "^1.3.1",
"@vitest/ui": "^1.3.1",
"jsdom": "^24.0.0",
"vitest": "^1.3.1",
"@testing-library/jest-dom": "^6.4.2",
"@types/testing-library__jest-dom": "^5.14.9"
}
}
9 changes: 9 additions & 0 deletions apps/docs/test/setup.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/// <reference types="vitest" />
/// <reference types="@testing-library/jest-dom" />

import type { TestingLibraryMatchers } from "@testing-library/jest-dom/matchers";

declare module "vitest" {
interface Assertion<T = unknown>
extends TestingLibraryMatchers<typeof expect.stringContaining, T> {}
}
32 changes: 32 additions & 0 deletions apps/docs/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/// <reference types="vitest" />
/// <reference types="./test/setup" />

import { resolve } from "node:path";
import react from "@vitejs/plugin-react";
import { defineConfig } from "vitest/config";

export default defineConfig({
plugins: [react()],
test: {
environment: "jsdom",
globals: true,
setupFiles: ["./vitest.setup.ts"],
coverage: {
provider: "v8",
reporter: ["text", "html"],
exclude: [
"node_modules/**",
".next/**",
"coverage/**",
"**/*.d.ts",
"**/*.config.*",
"**/index.ts",
],
},
},
resolve: {
alias: {
"~": resolve(__dirname, "./"),
},
},
});
11 changes: 11 additions & 0 deletions apps/docs/vitest.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import "@testing-library/jest-dom";
import * as matchers from "@testing-library/jest-dom/matchers";
import { cleanup } from "@testing-library/react";
import { afterEach, expect } from "vitest";

expect.extend(matchers);

// runs a cleanup after each test case
afterEach(() => {
cleanup();
});
Binary file modified bun.lockb
Binary file not shown.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
"fix": "biome check --write .",
"check": "biome check",
"check:errors": "biome check --diagnostic-level=error",
"clean": "rimraf dist node_modules"
"clean": "rimraf dist node_modules",
"test": "turbo run test",
"test:once": "turbo run test:once",
"coverage": "turbo run test:coverage"
},
"devDependencies": {
"turbo": "^2.4.0",
Expand Down
6 changes: 6 additions & 0 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
"cache": false,
"persistent": true
},
"test:once": {},
"test": {
"cache": false,
"persistent": true
},
"coverage": {},
"clean": {
"cache": false
},
Expand Down
Loading