Skip to content

Conversation

dstaley
Copy link
Member

@dstaley dstaley commented Sep 19, 2025

Description

This PR replaces Jest with Vitest for @clerk/chrome-extension. In order to get --maxWorkers=70% to work correctly, it also updates vitest to the latest version. This in turn caused a previous @ts-expect-error directive to become unused (for some reason??). Adding dom.iterable to the lib config for @clerk/nextjs fixed the type error, allowing for the removal of the directive.

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Summary by CodeRabbit

  • Tests
    • Chrome Extension tests migrated from Jest to Vitest: added Vitest config and setup, test scripts updated, and tests updated for explicit Vitest imports and vi-based mocks.
  • Chores
    • Dev dependency updates for Vitest tooling.
    • Added a placeholder changeset entry.
    • Removed legacy Jest config and related scripts.
    • TypeScript config extended (dom.iterable), minor TS comment removal, and new .gitignore rule for bundling outputs.

Copy link

changeset-bot bot commented Sep 19, 2025

🦋 Changeset detected

Latest commit: 1203c64

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 0 packages

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Sep 19, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
clerk-js-sandbox Ready Ready Preview Comment Sep 30, 2025 0:52am

Copy link
Contributor

coderabbitai bot commented Sep 19, 2025

Walkthrough

Replaces Jest with Vitest for the chrome-extension package (scripts, config, setup, and tests); adds a placeholder changeset; updates root Vitest-related devDependencies; removes chrome-extension Jest config file; adjusts Next.js TypeScript lib and removes a TS expect-error comment; updates .gitignore.

Changes

Cohort / File(s) Summary
Repository metadata & ignores
package.json, .changeset/brown-icons-shine.md, .gitignore
Updates devDependencies for @vitest/coverage-v8 and vitest versions in root package.json; adds an empty placeholder changeset file .changeset/brown-icons-shine.md (contains ---); adds /packages/*/tsup.config.bundled_* to .gitignore.
Chrome extension: test-runner switch & config
packages/chrome-extension/package.json, packages/chrome-extension/jest.config.js, packages/chrome-extension/vitest.config.mts, packages/chrome-extension/vitest.setup.mts
Switches chrome-extension test scripts from Jest to Vitest (test, test:ci, adds test:watch), removes Jest-specific scripts and deletes jest.config.js; adds vitest.config.mts exporting defineConfig (jsdom, includeSource, tsconfig.test.json, setup file, PACKAGE_NAME/PACKAGE_VERSION via define) and vitest.setup.mts (assigns globalThis.jest = vi before importing jest-chrome).
Chrome extension: test files — imports & helpers
packages/chrome-extension/src/__tests__/exports.test.ts, packages/chrome-extension/src/internal/utils/__tests__/manifest.test.ts
Adds explicit imports from vitest (e.g., describe, expect, it, test) instead of relying on globals; no test logic changes.
Chrome extension: test files — mocks & assertions
packages/chrome-extension/src/internal/utils/__tests__/cookies.test.ts, packages/chrome-extension/src/internal/utils/__tests__/storage.test.ts
Replaces Jest mock utilities with Vitest equivalents (vi, vi.mocked), adds ESLint disable(s) where necessary, adds afterEach restores and explicit storage-call argument assertions in storage tests; semantics preserved.
Next.js: TypeScript tweak & comment removal
packages/nextjs/src/server/clerkMiddleware.ts, packages/nextjs/tsconfig.json
Removes a // @ts-expect-error comment in clerkMiddleware.ts; adds "dom.iterable" to lib in packages/nextjs/tsconfig.json.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Dev as Developer
  participant CLI as Vitest CLI
  participant Cfg as vitest.config.mts
  participant Setup as vitest.setup.mts
  participant JC as jest-chrome
  participant Tests as Test Suites

  Dev->>CLI: run `vitest` / `vitest run`
  CLI->>Cfg: load config (env, jsdom, globals PACKAGE_NAME/PACKAGE_VERSION)
  CLI->>Setup: execute setup file
  note right of Setup #e8f6ff: assign globalThis.jest = vi\nthen import `jest-chrome`
  Setup->>JC: initialize chrome mocks
  CLI->>Tests: discover & run `**/*.test.{ts,tsx}`
  Tests->>JC: use chrome.* mocks via global `jest`
  Tests-->>CLI: return results
  CLI-->>Dev: report pass/fail
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

I swapped my jest for vi with a hop and a grin,
Configs refreshed, the old file tucked in.
Globals set, chrome mocks ready to play,
Tests hop along through the bright new day.
A rabbit's small cheer for the tidy relay. 🥕🐇

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title clearly and concisely describes the primary change of replacing Jest with Vitest in the chrome-extension package, uses a conventional commit style with the correct scope, and is specific enough for reviewers to understand the main purpose at a glance.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ds.feat/chrome-extension-vitest

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between ceb14d8 and 1203c64.

⛔ Files ignored due to path filters (2)
  • packages/chrome-extension/src/__tests__/__snapshots__/exports.test.ts.snap is excluded by !**/*.snap
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (3)
  • package.json (2 hunks)
  • packages/chrome-extension/package.json (1 hunks)
  • packages/nextjs/src/server/clerkMiddleware.ts (0 hunks)
💤 Files with no reviewable changes (1)
  • packages/nextjs/src/server/clerkMiddleware.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/chrome-extension/package.json
  • package.json
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: Formatting | Dedupe | Changeset
  • GitHub Check: Build Packages
  • GitHub Check: semgrep/ci
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

pkg-pr-new bot commented Sep 19, 2025

Open in StackBlitz

@clerk/agent-toolkit

npm i https://pkg.pr.new/@clerk/agent-toolkit@6820

@clerk/astro

npm i https://pkg.pr.new/@clerk/astro@6820

@clerk/backend

npm i https://pkg.pr.new/@clerk/backend@6820

@clerk/chrome-extension

npm i https://pkg.pr.new/@clerk/chrome-extension@6820

@clerk/clerk-js

npm i https://pkg.pr.new/@clerk/clerk-js@6820

@clerk/dev-cli

npm i https://pkg.pr.new/@clerk/dev-cli@6820

@clerk/elements

npm i https://pkg.pr.new/@clerk/elements@6820

@clerk/clerk-expo

npm i https://pkg.pr.new/@clerk/clerk-expo@6820

@clerk/expo-passkeys

npm i https://pkg.pr.new/@clerk/expo-passkeys@6820

@clerk/express

npm i https://pkg.pr.new/@clerk/express@6820

@clerk/fastify

npm i https://pkg.pr.new/@clerk/fastify@6820

@clerk/localizations

npm i https://pkg.pr.new/@clerk/localizations@6820

@clerk/nextjs

npm i https://pkg.pr.new/@clerk/nextjs@6820

@clerk/nuxt

npm i https://pkg.pr.new/@clerk/nuxt@6820

@clerk/clerk-react

npm i https://pkg.pr.new/@clerk/clerk-react@6820

@clerk/react-router

npm i https://pkg.pr.new/@clerk/react-router@6820

@clerk/remix

npm i https://pkg.pr.new/@clerk/remix@6820

@clerk/shared

npm i https://pkg.pr.new/@clerk/shared@6820

@clerk/tanstack-react-start

npm i https://pkg.pr.new/@clerk/tanstack-react-start@6820

@clerk/testing

npm i https://pkg.pr.new/@clerk/testing@6820

@clerk/themes

npm i https://pkg.pr.new/@clerk/themes@6820

@clerk/types

npm i https://pkg.pr.new/@clerk/types@6820

@clerk/upgrade

npm i https://pkg.pr.new/@clerk/upgrade@6820

@clerk/vue

npm i https://pkg.pr.new/@clerk/vue@6820

commit: 1203c64

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/chrome-extension/src/internal/utils/__tests__/cookies.test.ts (1)

44-44: Replace jest.fn with vi.fn

packages/chrome-extension/src/internal/utils/tests/cookies.test.ts:44

-      expect(await getClientCookie({ callback: jest.fn(), name, url })).toBe(cookie);
+      expect(await getClientCookie({ callback: vi.fn(), name, url })).toBe(cookie);
🧹 Nitpick comments (7)
.changeset/brown-icons-shine.md (1)

1-2: Optional: add a note so this empty changeset is self‑documenting.

Empty changesets are fine; adding a one‑line body helps future readers.

Apply this diff:

 ---
 ---
+chore(chrome-extension): migrate tests from Jest to Vitest (no published changes)

If your pipeline discourages empty changesets, confirm this is intentional for a non-publishing infra change.

packages/chrome-extension/vitest.setup.mts (1)

9-9: Prefer globalThis over global for portability.

Minor consistency tweak with the earlier globalThis usage.

Apply this diff:

-Object.assign(global, { chrome, browser: chrome });
+Object.assign(globalThis, { chrome, browser: chrome });
packages/chrome-extension/package.json (1)

47-48: Scripts migration to Vitest looks good.

If CI depends on coverage, consider adding a coverage script with v8 provider; otherwise ignore.

Optional:

   "scripts": {
     ...
-    "test": "vitest",
-    "test:ci": "vitest run --maxWorkers=70%"
+    "test": "vitest",
+    "test:ci": "vitest run --maxWorkers=70%",
+    "test:coverage": "vitest run --coverage"
   },

Confirm that removing the old test:coverage doesn’t affect any CI jobs expecting it.

packages/chrome-extension/vitest.config.mts (4)

8-11: Declare types for PACKAGE_NAME / PACKAGE_VERSION.

These are injected at build time; TS will flag usage unless declared in a .d.ts included by tsconfig.test.json.

Add a file (e.g., packages/chrome-extension/env.globals.d.ts):

declare const PACKAGE_NAME: string;
declare const PACKAGE_VERSION: string;

Ensure tsconfig.test.json includes it.


13-17: Typecheck also .spec. files.*

Current include only matches .test.. Many repos also use .spec..

-      include: ['**/*.test.{ts,tsx}'],
+      include: ['**/*.{test,spec}.{ts,tsx}'],

22-22: Scope includeSource to sources to speed up collection.

The global pattern can pull in config/setup and other non‑source files.

-    includeSource: ['**/*.{js,ts,jsx,tsx}'],
+    includeSource: ['src/**/*.{js,ts,jsx,tsx}'],

Adjust the glob if your sources live outside src/.


7-7: Remove empty plugins array.

No plugins configured—drop the empty property.

-  plugins: [],
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 651b27e and 2f8d760.

⛔ Files ignored due to path filters (2)
  • packages/chrome-extension/src/__tests__/__snapshots__/exports.test.ts.snap is excluded by !**/*.snap
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (10)
  • .changeset/brown-icons-shine.md (1 hunks)
  • package.json (1 hunks)
  • packages/chrome-extension/jest.config.js (0 hunks)
  • packages/chrome-extension/package.json (1 hunks)
  • packages/chrome-extension/src/__tests__/exports.test.ts (1 hunks)
  • packages/chrome-extension/src/internal/utils/__tests__/cookies.test.ts (2 hunks)
  • packages/chrome-extension/src/internal/utils/__tests__/manifest.test.ts (1 hunks)
  • packages/chrome-extension/src/internal/utils/__tests__/storage.test.ts (4 hunks)
  • packages/chrome-extension/vitest.config.mts (1 hunks)
  • packages/chrome-extension/vitest.setup.mts (1 hunks)
💤 Files with no reviewable changes (1)
  • packages/chrome-extension/jest.config.js
🧰 Additional context used
📓 Path-based instructions (10)
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Use Prettier for consistent code formatting

Files:

  • package.json
  • packages/chrome-extension/src/__tests__/exports.test.ts
  • packages/chrome-extension/src/internal/utils/__tests__/manifest.test.ts
  • packages/chrome-extension/package.json
  • packages/chrome-extension/src/internal/utils/__tests__/cookies.test.ts
  • packages/chrome-extension/src/internal/utils/__tests__/storage.test.ts
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

**/*.{js,jsx,ts,tsx}: All code must pass ESLint checks with the project's configuration
Follow established naming conventions (PascalCase for components, camelCase for variables)
Maintain comprehensive JSDoc comments for public APIs
Use dynamic imports for optional features
All public APIs must be documented with JSDoc
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Profile and optimize critical paths
Validate all inputs and sanitize outputs
Implement proper logging with different levels

Files:

  • packages/chrome-extension/src/__tests__/exports.test.ts
  • packages/chrome-extension/src/internal/utils/__tests__/manifest.test.ts
  • packages/chrome-extension/src/internal/utils/__tests__/cookies.test.ts
  • packages/chrome-extension/src/internal/utils/__tests__/storage.test.ts
packages/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

TypeScript is required for all packages

Files:

  • packages/chrome-extension/src/__tests__/exports.test.ts
  • packages/chrome-extension/src/internal/utils/__tests__/manifest.test.ts
  • packages/chrome-extension/src/internal/utils/__tests__/cookies.test.ts
  • packages/chrome-extension/src/internal/utils/__tests__/storage.test.ts
packages/**/*.{ts,tsx,d.ts}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Packages should export TypeScript types alongside runtime code

Files:

  • packages/chrome-extension/src/__tests__/exports.test.ts
  • packages/chrome-extension/src/internal/utils/__tests__/manifest.test.ts
  • packages/chrome-extension/src/internal/utils/__tests__/cookies.test.ts
  • packages/chrome-extension/src/internal/utils/__tests__/storage.test.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Use proper TypeScript error types

**/*.{ts,tsx}: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoid any type - prefer unknown when type is uncertain, then narrow with type guards
Use interface for object shapes that might be extended
Use type for unions, primitives, and computed types
Prefer readonly properties for immutable data structures
Use private for internal implementation details
Use protected for inheritance hierarchies
Use public explicitly for clarity in public APIs
Prefer readonly for properties that shouldn't change after construction
Prefer composition and interfaces over deep inheritance chains
Use mixins for shared behavior across unrelated classes
Implement dependency injection for loose coupling
Let TypeScript infer when types are obvious
Use const assertions for literal types: as const
Use satisfies operator for type checking without widening
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Use type-only imports: import type { ... } from ...
No any types without justification
Proper error handling with typed errors
Consistent use of readonly for immutable data
Proper generic constraints
No unused type parameters
Proper use of utility types instead of manual type construction
Type-only imports where possible
Proper tree-shaking friendly exports
No circular dependencies
Efficient type computations (avoid deep recursion)

Files:

  • packages/chrome-extension/src/__tests__/exports.test.ts
  • packages/chrome-extension/src/internal/utils/__tests__/manifest.test.ts
  • packages/chrome-extension/src/internal/utils/__tests__/cookies.test.ts
  • packages/chrome-extension/src/internal/utils/__tests__/storage.test.ts
packages/**/*.{test,spec}.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

Unit tests should use Jest or Vitest as the test runner.

Files:

  • packages/chrome-extension/src/__tests__/exports.test.ts
  • packages/chrome-extension/src/internal/utils/__tests__/manifest.test.ts
  • packages/chrome-extension/src/internal/utils/__tests__/cookies.test.ts
  • packages/chrome-extension/src/internal/utils/__tests__/storage.test.ts
**/*.{js,ts,tsx,jsx}

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

Support multiple Clerk environment variables (CLERK_, NEXT_PUBLIC_CLERK_, etc.) for configuration.

Files:

  • packages/chrome-extension/src/__tests__/exports.test.ts
  • packages/chrome-extension/src/internal/utils/__tests__/manifest.test.ts
  • packages/chrome-extension/src/internal/utils/__tests__/cookies.test.ts
  • packages/chrome-extension/src/internal/utils/__tests__/storage.test.ts
**/__tests__/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/typescript.mdc)

**/__tests__/**/*.{ts,tsx}: Create type-safe test builders/factories
Use branded types for test isolation
Implement proper mock types that match interfaces

Files:

  • packages/chrome-extension/src/__tests__/exports.test.ts
  • packages/chrome-extension/src/internal/utils/__tests__/manifest.test.ts
  • packages/chrome-extension/src/internal/utils/__tests__/cookies.test.ts
  • packages/chrome-extension/src/internal/utils/__tests__/storage.test.ts
packages/*/package.json

📄 CodeRabbit inference engine (.cursor/rules/global.mdc)

All publishable packages should be placed under the packages/ directory

packages/*/package.json: All publishable packages must be located in the 'packages/' directory.
All packages must be published under the @clerk namespace on npm.
Semantic versioning must be used across all packages.

Files:

  • packages/chrome-extension/package.json
.changeset/**

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

Automated releases must use Changesets.

Files:

  • .changeset/brown-icons-shine.md
🧬 Code graph analysis (1)
packages/chrome-extension/src/internal/utils/__tests__/storage.test.ts (1)
packages/chrome-extension/src/internal/utils/storage.ts (1)
  • BrowserStorageCache (46-46)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: Build Packages
  • GitHub Check: Formatting | Dedupe | Changeset
  • GitHub Check: semgrep/ci
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (6)
packages/chrome-extension/src/internal/utils/__tests__/cookies.test.ts (1)

28-32: Good swap to vi.mocked and proper reset/restore.

packages/chrome-extension/src/internal/utils/__tests__/manifest.test.ts (1)

1-1: LGTM: explicit Vitest imports.

packages/chrome-extension/vitest.setup.mts (1)

1-4: LGTM: aliasing jest to vi before importing jest‑chrome is correct.

packages/chrome-extension/src/__tests__/exports.test.ts (1)

1-1: LGTM: moved to Vitest APIs; snapshot test remains stable.

packages/chrome-extension/src/internal/utils/__tests__/storage.test.ts (1)

25-30: Nice Vitest migration + stronger assertions.

  • Using vi.mocked with argument verification tightens the contract.
  • afterEach with vi.restoreAllMocks prevents cross‑test bleed.

Also applies to: 35-40, 44-47, 49-54, 57-62

packages/chrome-extension/vitest.config.mts (1)

1-25: Sanity check — vitest config & package globals verified.
All referenced files exist (packages/chrome-extension/{vitest.config.mts, tsconfig.test.json, vitest.setup.mts, package.json}); vitest defines PACKAGE_NAME/PACKAGE_VERSION and matching declarations exist at packages/chrome-extension/src/global.d.ts; usages found in packages/chrome-extension/tsup.config.ts, packages/chrome-extension/src/internal/clerk.ts, and packages/chrome-extension/src/index.ts; config path refs confirmed.

Comment on lines +1 to +5
import { defineConfig } from 'vitest/config';
import { readFileSync } from 'node:fs';

const { name, version } = JSON.parse(readFileSync('./package.json', 'utf8'));

Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Make config CWD‑independent (monorepo‑safe).

Relative paths here resolve from process.cwd(), which can point to the repo root when running Vitest via a workspace filter. Read package.json and resolve tsconfig/setupFiles relative to this config file to avoid misreads/breakage.

Apply this diff:

@@
-import { defineConfig } from 'vitest/config';
-import { readFileSync } from 'node:fs';
+import { defineConfig } from 'vitest/config';
+import { readFileSync } from 'node:fs';
+import { fileURLToPath } from 'node:url';
+import { resolve } from 'node:path';
@@
-const { name, version } = JSON.parse(readFileSync('./package.json', 'utf8'));
+const rootDir = fileURLToPath(new URL('.', import.meta.url));
+const { name, version } = JSON.parse(
+  readFileSync(new URL('./package.json', import.meta.url), 'utf8'),
+);
@@
-export default defineConfig({
-  plugins: [],
+export default defineConfig({
+  root: rootDir,
+  plugins: [],
@@
-      tsconfig: './tsconfig.test.json',
+      tsconfig: resolve(rootDir, 'tsconfig.test.json'),
@@
-    setupFiles: './vitest.setup.mts',
+    setupFiles: resolve(rootDir, 'vitest.setup.mts'),

Also applies to: 6-9, 15-16, 23-23

🤖 Prompt for AI Agents
In packages/chrome-extension/vitest.config.mts around lines 1-5 (and similarly
for lines 6-9, 15-16, 23-23), relative paths are being resolved from
process.cwd(), which breaks in a monorepo; change file-loading and path
resolution to be relative to this config file by using import.meta.url (e.g.
read package.json via new URL('./package.json', import.meta.url) and resolve
tsconfig/setupFiles using new URL('./path/to/file', import.meta.url) or URL +
pathname, then pass the resulting absolute paths to Vitest so the config is
CWD‑independent.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/chrome-extension/src/internal/utils/__tests__/cookies.test.ts (1)

28-33: Use vi.spyOn instead of vi.mocked; mockRestore only works on spies

vi.mocked is a type helper; it doesn’t turn browser.cookies.get into a spy. Calling mockRestore on a non‑spy will fail. Spy on the method, then reset/restore the spy.

Apply this diff:

-  // eslint-disable-next-line jest/unbound-method -- The Jest ESLint plugin doesn't support Vitest
-  const getMock = vi.mocked(browser.cookies.get);
+  const getSpy = vi.spyOn(browser.cookies, 'get');

-  afterEach(() => getMock.mockReset());
-  afterAll(() => getMock.mockRestore());
+  afterEach(() => getSpy.mockReset());
+  afterAll(() => getSpy.mockRestore());

And update usages below:

-  function expectMockCalls(mockedFn: typeof getMock, name: string, urls: string[]) {
+  function expectMockCalls(mockedFn: typeof getSpy, name: string, urls: string[]) {
-    expect(mockedFn.mock.calls.flat()).toEqual(urls.map(url => ({ url, name })));
+    expect(mockedFn.mock.calls.map(([arg]) => arg)).toEqual(urls.map(url => ({ url, name })));
   }
🧹 Nitpick comments (2)
packages/chrome-extension/src/internal/utils/__tests__/cookies.test.ts (2)

43-48: Align with Vitest API and updated spy name

Use the spy instance and prefer vi.fn() for consistency with the migration.

Apply this diff:

-      getMock.mockResolvedValue(cookie);
+      getSpy.mockResolvedValue(cookie);

-      expect(await getClientCookie({ callback: jest.fn(), name, url })).toBe(cookie);
+      expect(await getClientCookie({ callback: vi.fn(), name, url })).toBe(cookie);
-      expectMockCalls(getMock, name, [url]);
+      expectMockCalls(getSpy, name, [url]);

40-41: Test description vs. assertion mismatch (value vs. object)

Name says “cookie value” but the assertion checks the whole cookie object identity. Either rename the test or assert on cookie.value.

Option A (rename):

-    test('returns cookie value from browser.cookies if is set for url', async () => {
+    test('returns cookie from browser.cookies if it is set for the url', async () => {

Option B (assert value):

-      expect(await getClientCookie({ callback: vi.fn(), name, url })).toBe(cookie);
+      expect((await getClientCookie({ callback: vi.fn(), name, url }))?.value).toBe(cookie.value);
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 2f8d760 and 5f196e6.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (2)
  • packages/chrome-extension/src/internal/utils/__tests__/cookies.test.ts (2 hunks)
  • packages/chrome-extension/src/internal/utils/__tests__/storage.test.ts (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/chrome-extension/src/internal/utils/tests/storage.test.ts
🧰 Additional context used
📓 Path-based instructions (8)
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

**/*.{js,jsx,ts,tsx}: All code must pass ESLint checks with the project's configuration
Follow established naming conventions (PascalCase for components, camelCase for variables)
Maintain comprehensive JSDoc comments for public APIs
Use dynamic imports for optional features
All public APIs must be documented with JSDoc
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Profile and optimize critical paths
Validate all inputs and sanitize outputs
Implement proper logging with different levels

Files:

  • packages/chrome-extension/src/internal/utils/__tests__/cookies.test.ts
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Use Prettier for consistent code formatting

Files:

  • packages/chrome-extension/src/internal/utils/__tests__/cookies.test.ts
packages/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

TypeScript is required for all packages

Files:

  • packages/chrome-extension/src/internal/utils/__tests__/cookies.test.ts
packages/**/*.{ts,tsx,d.ts}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Packages should export TypeScript types alongside runtime code

Files:

  • packages/chrome-extension/src/internal/utils/__tests__/cookies.test.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Use proper TypeScript error types

**/*.{ts,tsx}: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoid any type - prefer unknown when type is uncertain, then narrow with type guards
Use interface for object shapes that might be extended
Use type for unions, primitives, and computed types
Prefer readonly properties for immutable data structures
Use private for internal implementation details
Use protected for inheritance hierarchies
Use public explicitly for clarity in public APIs
Prefer readonly for properties that shouldn't change after construction
Prefer composition and interfaces over deep inheritance chains
Use mixins for shared behavior across unrelated classes
Implement dependency injection for loose coupling
Let TypeScript infer when types are obvious
Use const assertions for literal types: as const
Use satisfies operator for type checking without widening
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Use type-only imports: import type { ... } from ...
No any types without justification
Proper error handling with typed errors
Consistent use of readonly for immutable data
Proper generic constraints
No unused type parameters
Proper use of utility types instead of manual type construction
Type-only imports where possible
Proper tree-shaking friendly exports
No circular dependencies
Efficient type computations (avoid deep recursion)

Files:

  • packages/chrome-extension/src/internal/utils/__tests__/cookies.test.ts
packages/**/*.{test,spec}.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

Unit tests should use Jest or Vitest as the test runner.

Files:

  • packages/chrome-extension/src/internal/utils/__tests__/cookies.test.ts
**/*.{js,ts,tsx,jsx}

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

Support multiple Clerk environment variables (CLERK_, NEXT_PUBLIC_CLERK_, etc.) for configuration.

Files:

  • packages/chrome-extension/src/internal/utils/__tests__/cookies.test.ts
**/__tests__/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/typescript.mdc)

**/__tests__/**/*.{ts,tsx}: Create type-safe test builders/factories
Use branded types for test isolation
Implement proper mock types that match interfaces

Files:

  • packages/chrome-extension/src/internal/utils/__tests__/cookies.test.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (28)
  • GitHub Check: Integration Tests (tanstack-react-router, chrome)
  • GitHub Check: Integration Tests (vue, chrome)
  • GitHub Check: Integration Tests (nextjs, chrome, 15)
  • GitHub Check: Integration Tests (react-router, chrome)
  • GitHub Check: Integration Tests (tanstack-react-start, chrome)
  • GitHub Check: Integration Tests (custom, chrome)
  • GitHub Check: Integration Tests (nextjs, chrome, 14)
  • GitHub Check: Integration Tests (astro, chrome)
  • GitHub Check: Integration Tests (localhost, chrome)
  • GitHub Check: Integration Tests (machine, chrome)
  • GitHub Check: Integration Tests (nuxt, chrome)
  • GitHub Check: Integration Tests (sessions, chrome)
  • GitHub Check: Integration Tests (elements, chrome)
  • GitHub Check: Integration Tests (expo-web, chrome)
  • GitHub Check: Integration Tests (billing, chrome)
  • GitHub Check: Integration Tests (ap-flows, chrome)
  • GitHub Check: Integration Tests (quickstart, chrome)
  • GitHub Check: Integration Tests (generic, chrome)
  • GitHub Check: Integration Tests (express, chrome)
  • GitHub Check: Unit Tests (22, **)
  • GitHub Check: Publish with pkg-pr-new
  • GitHub Check: Unit Tests (18, --filter=@clerk/astro --filter=@clerk/backend --filter=@clerk/express --filter=@c...
  • GitHub Check: Static analysis
  • GitHub Check: Formatting | Dedupe | Changeset
  • GitHub Check: semgrep/ci
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (1)
packages/chrome-extension/src/internal/utils/__tests__/cookies.test.ts (1)

1-1: Vitest import migration looks correct

Direct Vitest imports are fine here.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 5f196e6 and 68b09e8.

📒 Files selected for processing (2)
  • packages/nextjs/src/server/clerkMiddleware.ts (0 hunks)
  • packages/nextjs/tsconfig.json (1 hunks)
💤 Files with no reviewable changes (1)
  • packages/nextjs/src/server/clerkMiddleware.ts
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Use Prettier for consistent code formatting

Files:

  • packages/nextjs/tsconfig.json
packages/*/tsconfig.json

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

Type checking must be performed with TypeScript and publint.

Files:

  • packages/nextjs/tsconfig.json
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: semgrep/ci
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (1)
packages/nextjs/tsconfig.json (1)

1-24: Confirm intent: Next.js tsconfig change in a chrome-extension Vitest PR.

This tweak lives in packages/nextjs and seems orthogonal to the chrome-extension Jest→Vitest migration. Confirm it’s intentional and won’t be bundled with unrelated changes.

"isolatedModules": true,
"jsx": "react",
"lib": ["es6", "dom"],
"lib": ["es6", "dom", "dom.iterable"],
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix lib/target mismatch: use ES2019 libs (or drop custom lib).

Specifying "lib": ["es6", ...] while "target" is "ES2019" removes ES2016–ES2019 lib typings (Promise.finally, newer Array/TypedArray methods, etc.). Use ES2019 to match target (plus DOM libs) or omit "lib" entirely and rely on defaults if DOM isn’t required everywhere.

-    "lib": ["es6", "dom", "dom.iterable"],
+    "lib": ["es2019", "dom", "dom.iterable"],
📝 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
"lib": ["es6", "dom", "dom.iterable"],
"lib": ["es2019", "dom", "dom.iterable"],
🤖 Prompt for AI Agents
In packages/nextjs/tsconfig.json around line 9, the "lib" entry uses "es6" which
conflicts with the "target": "ES2019" setting and omits ES2016–ES2019 type
definitions; update the "lib" to include "ES2019" (and DOM/dom.iterable if
needed) or remove the custom "lib" entirely so TypeScript defaults match the
target, ensuring typings like Promise.finally and newer array/typedarray methods
are available.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/chrome-extension/package.json (1)

47-49: Optional: add a coverage script for parity

If coverage is package-scoped (vs. only at root), consider adding:

   "scripts": {
     "build": "tsup",
     "postbuild": "node ../../scripts/search-for-rhc.mjs directory dist",
@@
-    "test:watch": "vitest"
+    "test:watch": "vitest",
+    "test:coverage": "vitest run --coverage"
   },
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 4302356 and ceb14d8.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (2)
  • package.json (2 hunks)
  • packages/chrome-extension/package.json (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • package.json
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Use Prettier for consistent code formatting

Files:

  • packages/chrome-extension/package.json
packages/*/package.json

📄 CodeRabbit inference engine (.cursor/rules/global.mdc)

All publishable packages should be placed under the packages/ directory

packages/*/package.json: All publishable packages must be located in the 'packages/' directory.
All packages must be published under the @clerk namespace on npm.
Semantic versioning must be used across all packages.

Files:

  • packages/chrome-extension/package.json
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: Build Packages
  • GitHub Check: Formatting | Dedupe | Changeset
  • GitHub Check: semgrep/ci
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan

Comment on lines +47 to +49
"test": "vitest run",
"test:ci": "vitest run --maxWorkers=70%",
"test:watch": "vitest"
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

🧩 Analysis chain

Vitest switch LGTM; please verify flag support and workspace bin resolution

  • Confirm the repo’s Vitest version supports --maxWorkers=70%.
  • Ensure this package can resolve the vitest binary (since it’s not listed in this package’s devDependencies).

🏁 Script executed:

#!/bin/bash
# 1) Check Vitest version at repo root
jq -r '.devDependencies.vitest // .dependencies.vitest // .pnpm.overrides.vitest // empty' package.json

# 2) Verify this package does not declare vitest (expected if using root toolchain)
jq -r '.devDependencies.vitest // empty' packages/chrome-extension/package.json

# 3) (Optional) Inspect root scripts to see how tests are invoked in CI
jq -r '.scripts | to_entries[] | select(.key|test("test|ci|vitest|coverage")) | "\(.key): \(.value)"' package.json

Length of output: 2613


🌐 Web query:

Does Vitest support the CLI flag `--maxWorkers` with percentage values (e.g., `--maxWorkers=70%`)? If yes, since which version?

💡 Result:

Yes. Vitest's maxWorkers accepts numeric or percentage values (e.g. --maxWorkers=70%). It was added in the v1.1.0 release (Dec 19, 2023), and a parsing fix for --maxWorkers/--minWorkers was applied in Jan 2024 (PR #7759). [1][2][3]

Sources:

  • v1.1.0 release notes (adds --maxWorkers/--minWorkers). [1]
  • Vitest CLI/config docs stating "Maximum number or percentage of workers" for maxWorkers. [2]
  • PR fixing parsing of --maxWorkers/--minWorkers (Jan 10, 2024). [3]

Add Vitest devDependency and confirm flag support
Verified v3.2.4 (≥v1.1.0) accepts --maxWorkers=70%. Add "vitest": "^3.2.4" to packages/chrome-extension/package.json devDependencies so its vitest scripts resolve the CLI binary.

🤖 Prompt for AI Agents
In packages/chrome-extension/package.json around lines 47 to 49, add a
devDependency entry "vitest": "^3.2.4" to ensure the package-local vitest CLI is
used for the existing "test", "test:ci", and "test:watch" scripts and that the
--maxWorkers flag is supported; update devDependencies to include that version,
run package manager install to update lockfile, and commit the package.json and
lockfile changes.

@jacekradko jacekradko merged commit 981fae6 into main Sep 30, 2025
70 of 72 checks passed
@jacekradko jacekradko deleted the ds.feat/chrome-extension-vitest branch September 30, 2025 01:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants