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★ 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 ofscripts/unit-test-setup.js; every migrated package loads it as itssetupFilestools/vitest/nx-source-resolver.mts— resolvesnx/@nx/*to this repo's source, for both vite and nodetools/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 itsreferences— reading all ~114 project tsconfigs on every run, which lands as a sandbox violation.tools/vitestis deliberately a plain directory, not an Nx project: addingproject.jsonmakes@nx/js:typescript-syncdemand a project reference to a test-only tool from each consuming package's publishedtsconfig.lib.json(composite: falsedoes not suppress it)packages/workspace/vitest.config.mts— the config those two plug intopackages/workspace/project.json—test.inputsnaming 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:
- Spec count and current runtime. Run
pnpm nx test <name> --skip-nx-cacheonce 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. - Jest config specials — anything beyond
displayName/preset/moduleFileExtensionsis behavior you must reproduce:setupFiles(e.g.packages/devkit/jest-setup-nx-workspace-data-dir.js)moduleNameMapper(path shims; alsoidentity-obj-proxyfor CSS)testEnvironment: 'jsdom'→ needsenvironment: 'jsdom'and thejsdomdepmodulePathIgnorePatterns/testPathIgnorePatterns→excluderesolver→resolve.conditions(see Step 2)
- 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/*andnx/*ontopackages/*source, and setsNX_WORKSPACE_ROOT_PATH=<repo>/tmp/unitas a side effect. Both are reproduced by the shared scripts (Steps 2 and 3).moduleNameMapperESM 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/promptsis load-bearing: the stub answersundefinedwhere 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.mtsalready keeps that one.prettier's stub also pinsresolveConfig: () => 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.
- Native bindings — does the package load
nx/src/nativeor a.nodefile? If yes you needpool: 'forks'and the native shim plugin frompackages/nx/vitest.config.mts. - Lazy
require()of TS source — `grep -rn "require(" packages//
Установить vitest-migration в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
ReadGlobGrepAgentEdit(*)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), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic