Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

vitest-migration

БесплатноБез исполняемых скриптовНе проверен

Migrate an Nx repo package's unit tests from Jest to Vitest, reusing the shared setup that packages/workspace established. Use when asked to "move <pkg> to…

nrwlот nrwl★ 29 499 звёзд на GitHub

Об этом скилле

Migrate a package's unit tests to Vitest

Move packages/<name>'s unit tests from Jest to Vitest 4, inferred through the @nx/vitest plugin.

Start from packages/workspace, not packages/nx. The shared machinery a sibling package needs already exists — read these first and reuse them as-is:

  • tools/vitest/setup.mts — the port of scripts/unit-test-setup.js; every migrated package loads it as its setupFiles
  • tools/vitest/nx-source-resolver.mts — resolves nx / @nx/* to this repo's source, for both vite and node
  • tools/vitest/tsconfig.json — a leaf tsconfig whose only job is to stop vite's tsconfig lookup. Do not move these files to the workspace root. With no tsconfig beside them, the nearest one is the root solution file, and vite walks its references — reading all ~114 project tsconfigs on every run, which lands as a sandbox violation. tools/vitest is deliberately a plain directory, not an Nx project: adding project.json makes @nx/js:typescript-sync demand a project reference to a test-only tool from each consuming package's published tsconfig.lib.json (composite: false does not suppress it)
  • packages/workspace/vitest.config.mts — the config those two plug into
  • packages/workspace/project.json — test.inputs naming the shared scripts

packages/nx (PR #36754, commit 32dd3fb533) is the original migration but a poor template: it is the one package that imports almost no siblings, so it needs neither the source resolver nor the CJS-channel mocks. Consult it only for vitest-write-guard.cjs and src/internal-testing-utils/cjs-mock.ts. packages/angular-rspack/vitest.config.mts is the simple end of the spectrum (no nx source at all).

Argument

The package name (e.g. js, devkit, workspace). The package lives at packages/<name>/.

Why this is not a find-and-replace

Jest and Vitest disagree on module semantics, not just API names. The mechanical jest.* → vi.* rename is maybe 80% of the diff and 20% of the work. The rest is: which channel a mock reaches (ESM graph vs CJS require()), whether a namespace is frozen, and what resetAllMocks does to a spy. Budget for hand-fixing specs after the codemod.


Step 0 — Survey the package

Run these and write the answers into tmp/notes/vitest-migration-<name>.md before touching anything:

ls packages/<name>/jest.config.cts packages/<name>/jest*.js 2>/dev/null
cat packages/<name>/jest.config.cts
cat packages/<name>/tsconfig.spec.json
grep -rl "\.spec\.ts" -c packages/<name>/src | wc -l   # rough spec count
pnpm nx show project <name> --json | head -40

Capture:

  1. Spec count and current runtime. Run pnpm nx test <name> --skip-nx-cache once and record the reported test count and wall time. That number is the parity target in Step 6 — you cannot verify the migration without it.
  2. Jest config specials — anything beyond displayName/preset/ moduleFileExtensions is behavior you must reproduce:
    • setupFiles (e.g. packages/devkit/jest-setup-nx-workspace-data-dir.js)
    • moduleNameMapper (path shims; also identity-obj-proxy for CSS)
    • testEnvironment: 'jsdom' → needs environment: 'jsdom' and the jsdom dep
    • modulePathIgnorePatterns / testPathIgnorePatterns → exclude
    • resolver → resolve.conditions (see Step 2)
  3. Inherited preset behavior (jest.preset.js) that Vitest does not get for free:
    • setupFiles: ['../../scripts/unit-test-setup.js'] — the workspace-wide project-graph / workspace-context / native guards. This must be ported (Step 3).
    • resolver: '../../scripts/patched-jest-resolver.js' — maps @nx/* and nx/* onto packages/* source, and sets NX_WORKSPACE_ROOT_PATH=<repo>/tmp/unit as a side effect. Both are reproduced by the shared scripts (Steps 2 and 3).
    • moduleNameMapper ESM shims (@clack/prompts, ora, chalk, yargs-parser, prettier, magic-string, oxfmt). Most are pure ESM interop Vitest does not need — but check each for behavior before dropping it. @clack/prompts is load-bearing: the stub answers undefined where the real library drives a synchronous prompt, and a generator that asks a question blocks the worker forever with no test timeout. tools/vitest/setup.mts already keeps that one. prettier's stub also pins resolveConfig: () => null, which matters if the package snapshots formatted output.
    • maxWorkers: 1 — Vitest runs files in parallel. Any spec relying on cross-file ordering or a shared mutable temp dir will now fail. This is the main source of "it passed under jest" flakes.
  4. Native bindings — does the package load nx/src/native or a .node file? If yes you need pool: 'forks' and the native shim plugin from packages/nx/vitest.config.mts.
  5. Lazy require() of TS source — `grep -rn "require(" packages//
Полный SKILL.md на GitHub

Установить vitest-migration в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Read
Glob
Grep
Agent
Edit(*)
Write(*)
Bash(pnpm nx *)
Bash(npx nx *)
Bash(nx *)
Bash(git *)
Bash(ls *)
Bash(cat *)
Bash(head *)
Bash(tail *)
Bash(sed *)
Bash(grep *)
Bash(rg *)
Bash(find *)
Bash(wc *)
Bash(echo *)
Bash(mkdir *)
Bash(rm *)
Bash(mv *)
Bash(node *)
Bash(npx oxfmt *)
Bash(gh pr view *)
Bash(gh pr diff *)

FAQ

Что делает скилл vitest-migration?

Migrate an Nx repo package's unit tests from Jest to Vitest, reusing the shared setup that packages/workspace established. Use when asked to "move <pkg> to vitest", "migrate <pkg> tests off jest", or "run <pkg> unit tests with vitest".

Как установить скилл vitest-migration?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл vitest-migration запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить vitest-migration с