Repository navigation
test: run unit tests on Vitest - #80
Conversation
title.macro hasn't been imported since the Storybook 8 move, which relies on auto-titles. Also drop babel-plugin-macros and the unused @testing-library/react-hooks and react-test-renderer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Story tests pass unpinned and pinned to month-, year-, and leap-day edges. Unpinned, a11y checks also cover the "today" cell. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Move every test out of __tests__/tests folders and split codemods' lib.test.ts per module. Still runs on Jest; keep tests out of builds, coverage, and npm. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add jsdom and node Vitest projects alongside storybook, port every non-story test from Jest (and agent-tools from node:test), and run them all from one vitest:test Nx target. Jest stays installed until the next PR. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fe19625 to
82e0284
Compare
# Conflicts: # packages/gamut-agent-tools/cli/lib/design.test.mjs # packages/gamut-agent-tools/package.json # packages/gamut-agent-tools/project.json # packages/gamut-codemods/src/lib/eslint.test.ts # packages/gamut-codemods/src/lib/git.test.ts # packages/gamut-codemods/src/lib/leftovers.test.ts # packages/gamut-codemods/src/lib/manifest.test.ts # packages/gamut-codemods/src/migrations/eslint-comments/index.test.ts # packages/gamut-codemods/src/migrations/markdown-video-overrides/index.test.ts # packages/gamut-codemods/src/presets/index.test.ts # packages/gamut-icons/jest.config.ts # packages/gamut-icons/tsconfig.json # packages/gamut-illustrations/tsconfig.json # packages/gamut-patterns/jest.config.ts # packages/gamut-patterns/tsconfig.json # packages/gamut-styles/src/AssetProvider.fontLoading.test.tsx # packages/gamut-styles/src/AssetProvider.test.tsx # packages/gamut-styles/src/Background.test.tsx # packages/gamut-styles/src/GamutProvider.test.tsx # packages/gamut-styles/src/cache/createEmotionCache.test.ts # packages/gamut-styles/src/fontUtilsMock.ts # packages/gamut-styles/src/themes/theme.test.ts # packages/gamut-styles/src/utilities/elementDir.test.ts # packages/gamut-styles/src/utilities/fontUtils.test.ts # packages/gamut-styles/src/utilities/themed.test.ts # packages/gamut-styles/tsconfig.lib.json # packages/gamut/src/index.test.ts # packages/gamut/src/utils/generateResponsiveClassnames.test.ts # packages/gamut/src/utils/nullish.test.ts # packages/variance/integration/__snapshots__/variance.test.ts.snap # packages/variance/integration/component.test.tsx # packages/variance/integration/queries.test.ts # packages/variance/src/transforms/transformSize.test.ts # packages/variance/src/utils/propNames.test.ts # vitest.config.ts
@skillsoft/eslint-plugin-gamut
@skillsoft/gamut
@skillsoft/gamut-agent-tools
@skillsoft/gamut-codemods
@skillsoft/gamut-icons
@skillsoft/gamut-illustrations
@skillsoft/gamut-patterns
@skillsoft/gamut-styles
@skillsoft/gamut-tests
@skillsoft/variance
commit: |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #80 +/- ##
=======================================
Coverage ? 77.20%
=======================================
Files ? 464
Lines ? 32091
Branches ? 1536
=======================================
Hits ? 24776
Misses ? 7307
Partials ? 8
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes recommended
The watch command bypasses Nx build prerequisites, causing test collection to fail on a clean checkout when required package artifacts are missing.
1 open issue
What changed in this PR
Moves Gamut’s non-story tests to Vitest, completing the runner migration after #79’s test relocation. Shared Jest infrastructure remains for removal in #81.
Changes:
- Consolidates testing into Storybook, jsdom, and Node projects with shared coverage reporting.
- Converts test imports, mocks, hooks, and snapshots to Vitest.
- Replaces package-level test targets with one build-aware Nx target and updates scripts, CI, and documentation.
| File | Description |
|---|---|
yarn.lock |
Locks coverage dependencies and related updates. |
vitest.config.ts |
Defines three test projects and shared reporting. |
script/vitest/project.json |
Adds the build-aware unit-test target. |
script/vitest/node-setup.ts |
Connects ESLint RuleTester to Vitest. |
script/vitest/jsdom-setup.ts |
Registers matchers, cleanup, and jsdom adjustments. |
packages/variance/tsconfig.spec.json |
Removes Jest test types and config inclusion. |
packages/variance/tsconfig.lib.json |
Removes the obsolete Jest config exclusion. |
packages/variance/src/utils/propNames.test.ts |
Imports Vitest test APIs. |
packages/variance/src/transforms/transformSize.test.ts |
Imports Vitest test APIs. |
packages/variance/src/getPropertyMode/getPropertyMode.test.ts |
Imports Vitest test APIs. |
packages/variance/src/createTheme/createTheme.test.ts |
Imports Vitest test APIs. |
packages/variance/project.json |
Removes the package-level Jest target. |
packages/variance/jest.config.ts |
Deletes the package’s Jest configuration. |
packages/variance/integration/variance.test.ts |
Converts test APIs and mocks. |
packages/variance/integration/queries.test.ts |
Imports Vitest test APIs. |
packages/variance/integration/component.test.tsx |
Uses Vitest and shared Emotion matchers. |
packages/variance/integration/__snapshots__/variance.test.ts.snap |
Updates snapshot headers and keys. |
packages/gamut/tsconfig.spec.json |
Switches to Vitest-compatible matcher types. |
packages/gamut/tsconfig.lib.json |
Removes the obsolete Jest config exclusion. |
packages/gamut/src/utils/omitProps.test.tsx |
Imports Vitest test APIs. |
packages/gamut/src/utils/nullish.test.ts |
Imports Vitest test APIs. |
packages/gamut/src/utils/generateResponsiveClassnames.test.ts |
Imports Vitest test APIs. |
packages/gamut/src/Tips/shared/utils.test.tsx |
Imports Vitest test APIs. |
packages/gamut/src/Tips/shared/popoverAlignmentUtils.test.ts |
Imports Vitest test APIs. |
packages/gamut/src/ProgressBar/ProgressBar.test.tsx |
Imports Vitest test APIs. |
packages/gamut/src/PopoverContainer/testUtils.ts |
Converts the DOM rectangle mock to Vitest. |
packages/gamut/src/PopoverContainer/PopoverContainer.test.tsx |
Converts mocks, spies, and test APIs. |
packages/gamut/src/PopoverContainer/hooks.test.tsx |
Imports Vitest hooks and test APIs. |
packages/gamut/src/Popover/utils.test.ts |
Imports Vitest test APIs. |
packages/gamut/src/Popover/styles/beak.test.ts |
Imports Vitest test APIs. |
packages/gamut/src/PatternBackdrop/PatternBackdrop.test.tsx |
Imports Vitest test APIs. |
packages/gamut/src/Modals/Modal.test.tsx |
Converts test APIs and callback mocks. |
packages/gamut/src/Modals/Dialog.test.tsx |
Converts test APIs and callback mocks. |
packages/gamut/src/Menu/Menu.test.tsx |
Imports Vitest test APIs. |
packages/gamut/src/Markdown/libs/overrides/Video/MarkdownVideo.test.tsx |
Converts media module mocks to Vitest. |
packages/gamut/src/index.test.ts |
Uses Vitest for export snapshots. |
packages/gamut/src/Form/utils.test.tsx |
Imports Vitest test APIs. |
packages/gamut/src/Form/inputs/SelectDropdown/hooks/useNoOptionsAnnouncement.test.tsx |
Converts fake timers and test APIs. |
packages/gamut/src/Form/inputs/SelectDropdown/core/utils.test.tsx |
Imports Vitest test APIs. |
packages/gamut/src/Form/__snapshots__/utils.test.tsx.snap |
Updates snapshot headers and keys. |
packages/gamut/src/FeatureShimmer/FeatureShimmer.test.tsx |
Converts mocks and partial module loading. |
packages/gamut/src/DatePicker/utils/locale.test.ts |
Imports Vitest test APIs. |
packages/gamut/src/DatePicker/DatePickerInput/utils/validation.test.ts |
Converts test APIs and validation mocks. |
packages/gamut/src/DatePicker/DatePickerInput/Segment/utils.test.ts |
Converts date spies and lifecycle hooks. |
packages/gamut/src/DatePicker/DatePickerContext/DatePickerContext.test.tsx |
Converts context callback mocks. |
packages/gamut/src/DatePicker/DatePickerCalendar/utils/quickActions.test.ts |
Imports Vitest test APIs. |
packages/gamut/src/DatePicker/DatePickerCalendar/utils/dateSelect.test.ts |
Converts selection callback mocks. |
packages/gamut/src/DatePicker/DatePickerCalendar/Calendar/utils/keyHandler.test.tsx |
Converts keyboard-event and callback mocks. |
packages/gamut/src/DatePicker/DatePickerCalendar/Calendar/utils/format.test.ts |
Imports Vitest test APIs. |
packages/gamut/src/DatePicker/DatePickerCalendar/Calendar/utils/dateGrid.test.ts |
Imports Vitest test APIs. |
packages/gamut/src/DatePicker/DatePickerCalendar/Calendar/CalendarBody.test.tsx |
Converts calendar callback mocks. |
packages/gamut/src/ConnectedForm/ConnectedInputs/ConnectedNestedCheckboxes/utils.test.tsx |
Converts checkbox callback mocks. |
packages/gamut/src/Card/Card.test.tsx |
Imports Vitest test APIs. |
packages/gamut/src/ButtonBase/ButtonBase.test.tsx |
Imports Vitest test APIs. |
packages/gamut/src/BarChart/utils/index.test.tsx |
Imports Vitest test APIs. |
packages/gamut/src/Anchor/Anchor.test.tsx |
Imports Vitest test APIs. |
packages/gamut/src/Alert/Alert.test.tsx |
Converts test APIs and close-handler mocks. |
packages/gamut/src/__snapshots__/index.test.ts.snap |
Updates the snapshot header. |
packages/gamut/project.json |
Removes the package-level Jest target. |
packages/gamut/jest.config.ts |
Deletes the package’s Jest configuration. |
packages/gamut-tests/project.json |
Removes the package-level Jest target. |
packages/gamut-styles/tsconfig.spec.json |
Adds Vitest-compatible matcher types. |
packages/gamut-styles/tsconfig.lib.json |
Removes exclusions for deleted files. |
packages/gamut-styles/src/utilities/useLogicalProperties.test.tsx |
Imports Vitest test APIs. |
packages/gamut-styles/src/utilities/useElementDir.test.tsx |
Imports Vitest hooks and test APIs. |
packages/gamut-styles/src/utilities/themed.test.ts |
Imports Vitest test APIs. |
packages/gamut-styles/src/utilities/fontUtils.test.ts |
Converts module mocks and dynamic reimports. |
packages/gamut-styles/src/utilities/elementDir.test.ts |
Imports Vitest hooks and test APIs. |
packages/gamut-styles/src/themes/theme.test.ts |
Imports Vitest test APIs. |
packages/gamut-styles/src/themes/__snapshots__/theme.test.ts.snap |
Updates snapshot headers and keys. |
packages/gamut-styles/src/GamutProvider.test.tsx |
Converts provider mocks and reset hooks. |
packages/gamut-styles/src/GamutProvider.csp.test.tsx |
Imports Vitest hooks and test APIs. |
packages/gamut-styles/src/fontUtilsMock.ts |
Deletes the superseded shared mock. |
packages/gamut-styles/src/cache/createEmotionCache.test.ts |
Imports Vitest hooks and test APIs. |
packages/gamut-styles/src/Background.test.tsx |
Uses Vitest and shared Emotion matchers. |
packages/gamut-styles/src/AssetProvider.test.tsx |
Introduces hoisted Vitest font mocks. |
packages/gamut-styles/src/AssetProvider.fontLoading.test.tsx |
Converts font-loading and fetch mocks. |
packages/gamut-styles/project.json |
Removes the package-level Jest target. |
packages/gamut-styles/jest.config.ts |
Deletes the package’s Jest configuration. |
packages/gamut-patterns/tsconfig.json |
Removes the obsolete Jest config exclusion. |
packages/gamut-patterns/src/patterns.test.tsx |
Imports Vitest test APIs. |
packages/gamut-patterns/project.json |
Removes the package-level Jest target. |
packages/gamut-patterns/jest.config.ts |
Deletes the package’s Jest configuration. |
packages/gamut-illustrations/tsconfig.json |
Removes Jest types and config exclusion. |
packages/gamut-illustrations/src/index.test.tsx |
Imports Vitest test APIs. |
packages/gamut-illustrations/project.json |
Removes the package-level Jest target. |
packages/gamut-illustrations/jest.config.ts |
Deletes the package’s Jest configuration. |
packages/gamut-icons/tsconfig.json |
Removes the obsolete Jest config exclusion. |
packages/gamut-icons/src/index.test.tsx |
Imports Vitest test APIs. |
packages/gamut-icons/project.json |
Removes the package-level Jest target. |
packages/gamut-icons/mask-plugin.test.tsx |
Imports Vitest test APIs. |
packages/gamut-icons/jest.config.ts |
Deletes the package’s Jest configuration. |
packages/gamut-codemods/tsconfig.spec.json |
Removes Jest types and config inclusion. |
packages/gamut-codemods/tsconfig.lib.json |
Removes the obsolete Jest config exclusion. |
packages/gamut-codemods/src/transform.test.ts |
Imports Vitest for fixture tests. |
packages/gamut-codemods/src/presets/manifest.test.ts |
Imports Vitest test APIs. |
packages/gamut-codemods/src/presets/index.test.ts |
Imports Vitest test APIs. |
packages/gamut-codemods/src/migrations/markdown-video-overrides/index.test.ts |
Imports Vitest test APIs. |
packages/gamut-codemods/src/migrations/eslint-comments/index.test.ts |
Imports Vitest test APIs. |
packages/gamut-codemods/src/lib/module-strings.test.ts |
Imports Vitest test APIs. |
packages/gamut-codemods/src/lib/manifest.test.ts |
Imports Vitest test APIs. |
packages/gamut-codemods/src/lib/leftovers.test.ts |
Imports Vitest test APIs. |
packages/gamut-codemods/src/lib/git.test.ts |
Imports Vitest test APIs. |
packages/gamut-codemods/src/lib/eslint.test.ts |
Imports Vitest test APIs. |
packages/gamut-codemods/src/cli.test.ts |
Replaces Runner module mocking with a CommonJS spy. |
packages/gamut-codemods/README.md |
Documents the new test commands. |
packages/gamut-codemods/project.json |
Removes the package-level Jest target. |
packages/gamut-codemods/jest.config.ts |
Deletes the package’s Jest configuration. |
packages/gamut-agent-tools/project.json |
Removes the standalone Node test target. |
packages/gamut-agent-tools/package.json |
Removes the standalone test script. |
packages/gamut-agent-tools/cli/lib/design.test.mjs |
Replaces Node test APIs with Vitest. |
packages/eslint-plugin-gamut/tsconfig.spec.json |
Removes Jest types and config inclusion. |
packages/eslint-plugin-gamut/tsconfig.lib.json |
Removes the obsolete Jest config exclusion. |
packages/eslint-plugin-gamut/project.json |
Removes the package-level Jest target. |
packages/eslint-plugin-gamut/jest.config.ts |
Deletes the package’s Jest configuration. |
package.json |
Adds coverage support and updates test scripts. |
CONTRIBUTING.md |
Clarifies that unit testing builds packages first. |
.github/workflows/quality.yml |
Removes Jest-only command-line flags. |
.changeset/brave-tests-run.md |
Records the test-tooling migration. |
Review effort: Balanced
| "test": "nx run vitest:test", | ||
| "test:stories": "vitest run --project=storybook", | ||
| "test:stories:watch": "vitest --project=storybook", | ||
| "test:watch": "vitest --project=jsdom --project=node", |
There was a problem hiding this comment.
could be nx watch --all -- nx run \$NX_PROJECT_NAME:test
Each package's test target runs its own Vitest files, stories included. Folds the test-storybook job into test to compare CI time. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
They type-check built packages and time out when sharing CPU with Chromium. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Undo folding stories into the test job; that moves to a future ticket. Unit tests stay on per-package Vitest targets. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
They still time out on CI while Nx builds other packages in parallel. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jakemhiller
left a comment
There was a problem hiding this comment.
lgtm! added a comment about the yarn test:watch command, but it isn't blocking.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Overview
Part 3 of 4 in the Jest → Vitest migration, stacked on #79. This PR moves every non-story test from Jest to Vitest. It's step 4 of the testing revamp plan ("migrate node tests Jest → Vitest"). One Vitest workspace in the root
vitest.config.tsnow holds every test project: the existing Storybook browser project plus the unit tests, which used to run as one Jest project per package. Each package keeps its own Nxtesttarget, which now runs Vitest on that package's files.Each package's Jest setup is replaced in this PR, because it would break once the tests are Vitest code: its
jest.config.ts, its Nxtesttarget, andjestin its spec tsconfigtypes. The shared Jest infrastructure stays for now: the root Jest configs and preset,script/jest/, the@nx/jesttarget default and the Jest dependencies. #81 removes those, which keeps this PR focused on the switch and easy to revert.Results: 1,277 tests in 77 files pass. That's the same count as Jest plus
node --teston #79.One Vitest workspace, three projects
storybook: the existing browser project, unchanged apart from now sitting intest.projects.jsdom: gamut, gamut-styles, gamut-icons, gamut-illustrations, gamut-patterns, variance. Component, hook and style tests that need a DOM. Going to look into moving/removing some of these in the futurenode: eslint-plugin-gamut, gamut-codemods, gamut-agent-tools. Node tooling tests that ran in Jest'snodeenvironment and shouldn't get jsdom's browser globals.I chose a separate
nodeproject over adding// @vitest-environment nodeto the top of 11 files, so each group's environment is set in one place.environmentMatchGlobswould also work, but Vitest has deprecated it.Coverage (v8) and reporters are set for the whole workspace, because Vitest doesn't allow them per project. Each package's run writes coverage, lcov and junit to
coverage/vitest/<package>/, the same one-directory-per-package layout Jest used undercoverage/packages/. As with Jest, coverage only reports files the tests load (all: false).Setup files (
script/vitest/)jsdom-setup.ts:@emotion/jest'stoHaveStyleRule.@emotion/jesttypes its matchers for Jest'sexpect, hence the cast. Its runtime has no Jest dependency, and there's no@emotion/vitest.cleanup. RTL only registers it automatically whenafterEachis a global, and we're keeping Vitest's default ofglobals: false, so tests importdescribe/it/expect/vifromvitest.undefinedwindow.matchMediathat Vitest's jsdom environment defines. jsdom doesn't implementmatchMedia, but Vitest copies a fixed list of window keys onto the global, so the key exists with no value. That made'matchMedia' in windowtrue inusePrefersDarkMode, and every test that rendered through a provider threw.Date.nowpin orwindow.scrollTostub. Nothing calls either, and the suite passes without them.node-setup.ts: points ESLint'sRuleTesterat Vitest'sdescribe/it. Without globals, RuleTester would run its cases outside any test.Converting the tests
jest.*becamevi.*, with explicit imports fromvitest.jest.mock+requireActualbecame an async factory usingimportOriginal.require()d a sibling mock module now usevi.hoisted, so gamut-styles'fontUtilsMock.tsis deleted.fontUtils.test.ts:jest.doMock+resetModules+requirebecamevi.doMock+vi.resetModules+await import().cli.test.ts:cli.tsloads jscodeshift's Runner withrequire(), whichvi.mockcan't intercept. The test spies on the shared CommonJS module object instead, andcli.tsis unchanged.node:testbecame Vitest (before/afterbecamebeforeAll/afterAll).node:assertis kept. Thetest:binscript is removed, and the package's Nxtesttarget now runs Vitest like the others.describe/itnames with>, and the varianceit.eachtitles format their%oargs differently. I diffed the stored values against Jest's with the keys excluded, and they're identical.Running tests
yarn testis unchanged:nx run-many --target=test --all. Each package'stesttarget goes from@nx/jest:jesttonx:run-commands, runningvitest run --project=jsdom --project=node packages/<package>/. The trailing path limits the run to that package's test files. Listing both projects is harmless, because the one a package doesn't use matches none of its files. The flags are there to leave out thestorybookproject, which would otherwise run that package's stories in Chromium.project.jsondeclares its ownexecutor,outputsandcommand.nx.json'stargetDefaults.testholds what they share:cache,dependsOn: ["^build"], andinputs, which addvitest.config.ts, the setup files and theCIenv var.^buildhandles it per package: gamut, gamut-styles and codemods import sibling packages through theirdist, and codemods'manifest.test.tstype-checks the built.d.tsfiles. gamut-icons and gamut-patterns also depend on their ownbuild, because it generates thesrc/iconsandsrc/patternstheir tests import (same as their Jest targets).manifest.test.tsgets a 15s timeout on itsdescribeblock. Two of its tests build a TypeScript program over the built packages. Locally they take under a second, but on CI with Nx building other packages in parallel, one took 7.7s and failed at Vitest's 5s default.testtarget (Jest withpassWithNoTests) is removed rather than ported.NX_TASK_TARGET_PROJECT, which Nx sets for each task. Nx runs up to three packages in parallel, and with one shared directory they raced on Vitest'scoverage/.tmpand failed withENOENT. Passing--coverage.reportsDirectoryper target doesn't work: CI's trailing--coveragereplaces the wholecoverageoption.yarn test --coverage.--ciand--runInBandwere Jest-only flags, and Vitest rejects unknown flags. Stories still run in their owntest-storybookjob.yarn test:watchscript, which watches thejsdomandnodeprojects across all packages. Adds@vitest/coverage-v8.Known limitations
test-storybookruns without--coverage, as onmain.no-consolelint error in codemods'cli.test.ts, and type errors in some gamut, gamut-styles and variance test files. CI doesn't typecheck those tests.Notes for reviewers
cli.test.tscovers how the codemod handlesjest.config.jsin consumer repos. That's codemod behavior, not leftover Jest setup.testtarget and mergingtest-storybookinto thetestjob (828d9e494,29fc8697d), then reverted it (e19ce89ec). That's for a follow-up ticket. On one 4-core runner, the test step took 3m 31s, against 47s of unit tests and 1m 44s of stories when they ran on separate machines. The codemods manifest tests also slowed from about 7s to 19.5s next to Chromium.PR Checklist
Testing Instructions
yarn test. Nx should build the packages the tests need, then run atesttask for each of the 9 packages with tests, passing 1,277 tests in 77 files. Run it again and every task should come from the Nx cache.CI=true yarn test --coverage --skip-nx-cache. Check that each package has its owncoverage/vitest/<package>/directory withlcov.infoandjunit.xml.yarn nx run gamut-icons:test. It should build gamut-icons first, then pass 2 test files.yarn test:stories. All 686 story tests in 87 files should pass.yarn verify. It should pass.yarn test:watch, edit a test file, and check that it re-runs.PR Links and Envs
🤖 Generated with Claude Code