# Migrate a Chrome Extension from Jest to Vitest

Yes. An agent reads your extension's Jest and TypeScript setup, moves the tests to Vitest with a chrome API mock, drops ts-jest, and shows suite and build pass.

[Run this on Rush](https://cloud.getrush.ai/run/migrate-jest-to-vitest/chrome-extension/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads the current test setup before replacing it. In a project like chibat/chrome-extension-typescript-starter it finds `jest.config.js` with `roots: ["src"]` and a `transform` that runs `ts-jest` against `tsconfig.test.json`, which extends `tsconfig.json` only to switch `moduleResolution` from `bundler` to `node`. `package.json` has `"test": "npx jest"`, with `jest` 29, `ts-jest` 29 and `@types/jest` as dev dependencies next to `webpack` 5, `ts-loader`, `copy-webpack-plugin`, `prettier` and `@types/chrome`. The only test is `src/__tests__/sum.ts`, two cases against `src/sum.ts` using the global `test` and `expect`.

It reads the rest of the extension to know what the tests will need to touch next. `public/manifest.json` is Manifest V3 with a `background.service_worker`, a popup, an options page and a content script on `<all_urls>`; `src/popup.tsx` calls `chrome.action.setBadgeText`, `chrome.tabs.query` and `chrome.tabs.sendMessage`; `webpack/webpack.common.js` bundles `popup`, `options`, `background` and `content_script` entries with `ts-loader`. `.github/workflows/build.yml` runs `npm ci`, `npm run build --if-present` and `npm test` on Node 20 and 22, so the migrated suite runs in CI without a workflow change.

The agent installs `vitest` and removes `jest`, `ts-jest` and `@types/jest`, adds a `vitest.config.ts` with `test.include` set to the existing `src/__tests__` pattern and `globals: true` so `test` and `expect` keep working unimported, and changes the `test` script to `vitest run`. It deletes `jest.config.js` and `tsconfig.test.json`, because Vitest uses esbuild and reads `tsconfig.json` as it is, and adds `vitest/globals` to the `types` in `tsconfig.json` in place of the Jest types. Since `src/popup.tsx` uses the `chrome` namespace, it adds a `src/__tests__/setup.ts` registered as `setupFiles` that stubs `chrome.action`, `chrome.tabs`, `chrome.runtime` and `chrome.storage` with `vi.fn()`, so the next test written against the popup or the background worker has a mock ready, and writes one test using it so the setup is exercised.

Before pushing it runs `npm run build` to confirm webpack and `ts-loader` still compile every entry with the changed `tsconfig.json`, then `npm test` and `npx vitest run --coverage` to see the two original cases and the new one pass. It opens the pull request, reads the `build` workflow on both Node versions, and fixes anything that fails there.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Migrate this Chrome extension's tests from Jest to Vitest. Read jest.config.js, tsconfig.json, tsconfig.test.json, package.json, the tests under src and the GitHub Actions workflow first. Install vitest, remove jest, ts-jest and @types/jest, add vitest.config.ts with globals enabled and the existing test pattern, change the test script to vitest run, delete the Jest config and the test tsconfig, and replace the Jest types with vitest/globals in tsconfig.json. Add a setup file that stubs the chrome namespace APIs the extension uses and one test that exercises it. Run the webpack build and the tests before you push. Do not change the manifest or the webpack config. Open a pull request and make sure the build workflow passes on it.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

What comes back is a pull request on a new branch that removes `jest.config.js` and `tsconfig.test.json`, adds `vitest.config.ts` and `src/__tests__/setup.ts`, changes `package.json` and `package-lock.json` to swap the Jest packages for `vitest`, updates `tsconfig.json` types, keeps `src/__tests__/sum.ts` passing without edits to its assertions, and adds one test that uses the `chrome` stubs. In a project shaped like the TypeScript starter, `public/manifest.json` and the `webpack/` directory are untouched, and the `build` workflow runs unchanged because its `npm test` step now runs Vitest.

The proof is that workflow on the pull request, green on both Node versions in its matrix, plus the `npm run build`, `vitest run` and coverage output kept in the session's trajectory with every command. The pull request description lists the packages removed and added, the config files deleted, and which `chrome` APIs the setup file stubs.

Before merging, a reviewer checks that the stubbed `chrome` APIs are the ones their real tests will call, that `globals: true` is the style they want rather than explicit imports from `vitest`, and that nothing else in the repository still imports from `@jest/globals`. Then they can write popup and background tests against the mock without further setup.

## Run it on every extension repository still on Jest

Run this once per repository: have a script send the same request with each repository's URL in `resources` and a fresh UUID as `request_id`, so a retried request returns the run already started instead of a second pull request. Each run has its own sandbox and its own branch, and the Rush GitHub App must be installed on each repository; `GET /o/{org}/github` lists the ones it can clone.

Set a webhook URL on the API key and Rush POSTs `run.completed` or `run.failed` when each run's turn finishes, with `session_url` so your server can post the pull request link to the team's channel. A batch across many extensions needs no queue on your server: with `max_concurrent` runs in progress, 4 by default and up to 100, the key answers further requests `202` with `status: "queued"` and starts them, oldest first, when a slot frees.

## Why run it on Rush?

A test-runner migration is mostly bookkeeping until a type setting breaks the webpack build or a `chrome` call explodes in the first real test. On Rush the agent does the swap in its own sandbox, runs the webpack build and the suite there before the first push, and then reads the build workflow on its own pull request across the Node matrix. Your laptop never installs a second test runner alongside the first.

The result is checkable rather than claimed. The workflow on the agent's pull request shows the suite passing under Vitest on both Node versions, and the trajectory keeps the build and test output, so a reviewer can see the two original cases and the new one pass before opening the diff. Because each run is independent, the same request can migrate every extension repository the team maintains at once, one pull request each.

## Frequently asked questions

### Will it change my webpack config or manifest?

No. The prompt tells it not to, and Vitest runs the TypeScript sources directly through esbuild without `ts-loader`, so `webpack/webpack.common.js`, `webpack.dev.js`, `webpack.prod.js` and `public/manifest.json` are left alone. The only build-related edit is the `types` entry in `tsconfig.json`, and the agent runs `npm run build` to show webpack still compiles.

### Do my existing tests need rewriting?

Tests that use the global `test`, `expect` and `describe` run unchanged with `globals: true`, which is how `src/__tests__/sum.ts` is written. Tests that import `jest.fn` or `jest.mock` are changed to `vi.fn` and `vi.mock`, and the agent lists each such edit in the pull request. Snapshot files keep working.

### How are chrome.* APIs handled in tests?

A `setupFiles` entry registers `src/__tests__/setup.ts`, which defines a `chrome` global with `vi.fn()` stubs for `action`, `tabs`, `runtime` and `storage`, the namespaces `src/popup.tsx` and the background worker use. One test exercises the setup so it is not dead code. Ask for `sinon-chrome` or a fuller mock package in the prompt and the agent uses that instead.

### Why delete tsconfig.test.json?

It existed only to switch `moduleResolution` from `bundler` to `node` for `ts-jest`. Vitest's esbuild transform does not need it and reads `tsconfig.json` directly, so keeping the file would leave a config nothing uses. The pull request description says so, and a reviewer can keep it if another tool depends on it.

## More Chrome Extension jobs

- [Replace setTimeout Polling With chrome.alarms in a Chrome Extension](https://getrush.ai/run/migrate-to-chrome-alarms/chrome-extension/)
- [Migrate a Chrome Extension from Webpack to Vite](https://getrush.ai/run/migrate-webpack-to-vite/chrome-extension/)
- [Make a Chrome Extension Popup Remember Its State](https://getrush.ai/run/persist-popup-state/chrome-extension/)

## The same job on other stacks

- [Migrate Jest to Vitest in an Electron App](https://getrush.ai/run/migrate-jest-to-vitest/electron/)
- [Migrate an Expo Project from Jest to Vitest](https://getrush.ai/run/migrate-jest-to-vitest/expo/)
- [Migrate an Express Project from Jest to Vitest](https://getrush.ai/run/migrate-jest-to-vitest/express/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
