mirror of
https://github.com/Tria-plc/emaui.git
synced 2026-08-27 12:01:00 +00:00
6.6 KiB
6.6 KiB
Rstest migration plan for packages/enhanced
This document captures the work needed to migrate the enhanced package tests from Jest to Rstest. It is written against the current repo state and the Rstest docs listed in the references section.
Current state
- Jest configs are in
packages/enhanced/jest.config.tsandpackages/enhanced/jest.embed.ts, with Nx targetstest:jestandtest:experimentsinpackages/enhanced/project.json. - The default
enhanced:testtarget runs Vitest viapackages/enhanced/vitest.config.ts. - Rstest is already wired in
packages/enhanced/rstest.config.ts, but only includestest/ConfigTestCases.*.rstest.tsfiles. - Many unit and compiler tests under
packages/enhanced/test/**are Jest-only (globaljest,jest.mock,jest.fn, callback-styledone, etc).
Target state
- All enhanced package tests run under Rstest via
enhanced:rstest. - Nx target
enhanced:testuses Rstest and no longer depends on Jest/Vitest. - Jest-only helpers/configs in
packages/enhancedare removed or unused.
Work items
1) Update scripts and Nx targets
- Switch
packages/enhanced/project.jsontesttarget to Rstest:rstest run -c packages/enhanced/rstest.config.ts(match CLI usage). - Replace or remove
test:jestandtest:experimentstargets, or rewrite them as Rstest equivalents (for example, separate includes/projects). - Keep
enhanced:rstestin the rootpackage.jsonas the user-facing entry point and ensure it usesrstest run(orrstest) consistently.
2) Expand rstest.config.ts coverage
- Include unit and compiler tests (not just ConfigTestCases):
test/**/*.test.tstest/**/*.spec.tstest/**/*.rstest.ts(keep existing Rstest cases)
- Exclude non-Rstest variants to prevent duplicate runs:
test/**/*.vitest.tstest/**/*.basictest.js(Jest-only)test/**/*.embedruntime.js(Jest-only)
- Consider Rstest
projectsto separate long-running config-case tests from fast unit tests (differenttestTimeout,include, etc). - Add
setupFilesto reapplytest/setupTestFramework.jslogic (custom matchers and debug hooks). - If cleaning
packages/enhanced/test/jsis still required, move it toglobalSetupor a pretest script instead of Jest config.
3) Replace Jest APIs in tests
Map Jest-only APIs to Rstest equivalents and update imports where needed.
Core mappings:
jest.fn->rs.fn(from@rstest/core)jest.spyOn->rs.spyOnjest.mock->rs.mockjest.doMock->rs.doMockjest.dontMock->rs.unmockorrs.doUnmockjest.resetModules->rs.resetModules(note: does not clear mocks)jest.clearAllMocks->rs.clearAllMocksjest.resetAllMocks->rs.resetAllMocksjest.restoreAllMocks->rs.restoreAllMocksjest.setTimeout->rs.setConfig({ testTimeout })or configtestTimeoutjest.requireActual->await rs.importActual(...)orimport ... with { rstest: 'importActual' }
Known gaps to rework:
jest.isolateModuleshas no direct Rstest equivalent; users.resetModules+ dynamicimport()and refactor those tests.
Files to review specifically (non-exhaustive):
packages/enhanced/test/helpers/webpackMocks.tspackages/enhanced/test/compiler-unit/**/*.test.tspackages/enhanced/test/unit/**/*.test.tspackages/enhanced/test/ConfigTestCases.template.jspackages/enhanced/test/ConfigTestCases.embedruntime.jspackages/enhanced/test/ConfigTestCases.basictest.js
4) Remove callback-style done usage
Rstest does not support done callbacks in tests. Convert to async/Promise
style (return a Promise or async function). Key files include:
packages/enhanced/test/warmup-webpack.jspackages/enhanced/test/helpers/expectWarningFactory.jspackages/enhanced/test/compiler-unit/container/HoistContainerReferencesPlugin.test.tspackages/enhanced/test/ConfigTestCases.template.js(if still used)
Note: callback-style functions inside config-case bundles are already wrapped
in packages/enhanced/test/ConfigTestCases.rstest.ts and do not require
Rstest to support done.
5) TypeScript types and globals
- Decide between explicit imports (
import { describe, it, expect, rs }) vsglobals: true. The currentrstest.config.tsusesglobals: true. - If keeping globals, update
packages/enhanced/tsconfig.spec.jsonto include@rstest/core/globalsand removejesttypes. - Replace
jest.Mock,jest.MockedFunction, etc. with Rstest types (Mock,MockInstance) from@rstest/core.
6) Remove Jest-only infra
- Drop or ignore
packages/enhanced/jest.config.ts,packages/enhanced/jest.embed.ts, andpackages/enhanced/test/patch-node-env.jsonce no tests rely on them. - Rework
packages/enhanced/test/helpers/createLazyTestEnv.js, which depends onJEST_STATE_SYMBOL. Prefer avoiding this helper under Rstest or implement a Rstest-native alternative if still needed.
7) Verify behavior and parity
- Run
pnpm enhanced:rstestand check for parity with the old Jest suite. - Use
rstest list --filesOnly -c packages/enhanced/rstest.config.tsto verify include/exclude patterns. - Validate that custom matchers in
test/setupTestFramework.jsstill work with Rstest'sexpect.extend.
Suggested file-level checklist
packages/enhanced/project.json: updatetesttarget and pre-release steps.packages/enhanced/rstest.config.ts: include patterns, setupFiles, globalSetup, timeouts.packages/enhanced/tsconfig.spec.json: replace Jest types with Rstest types.packages/enhanced/test/setupTestFramework.js: ensure compatibility with Rstest (nodoneusage).packages/enhanced/test/helpers/webpackMocks.ts: replace Jest mocks.packages/enhanced/test/unit/**: replace Jest APIs and types.packages/enhanced/test/compiler-unit/**: replace Jest APIs and types.
References (Rstest docs)
- https://rstest.rs/llms.txt
- https://rstest.rs/guide/migration/jest.md
- https://rstest.rs/guide/basic/cli.md
- https://rstest.rs/guide/basic/configure-rstest.md
- https://rstest.rs/guide/basic/projects.md
- https://rstest.rs/config/test/include.md
- https://rstest.rs/config/test/setup-files.md
- https://rstest.rs/config/test/global-setup.md
- https://rstest.rs/config/test/globals.md
- https://rstest.rs/config/test/test-environment.md
- https://rstest.rs/api/runtime-api/test-api/expect.md
- https://rstest.rs/api/runtime-api/rstest/mock-modules.md
- https://rstest.rs/api/runtime-api/rstest/mock-functions.md
- https://rstest.rs/api/runtime-api/rstest/mock-instance.md
- https://rstest.rs/api/runtime-api/rstest/utilities.md
- https://rstest.rs/api/javascript-api/rstest-core.md