Repository navigation
chore: consolidate Vitest execution - #29142
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
Walkthrough
🚥 Pre-merge checks | ✅ 2 | ❌ 1
✨ Finishing touches
|
There was a problem hiding this comment.
Actionable comments posted: 4
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
packages/adapter-mariadb/package.json (1)
20-24:⚠️ Potential issue | 🟡 MinorPre-existing:
repository.directorypoints toadapter-planetscaleinstead ofadapter-mariadb.Line 23 has
"directory": "packages/adapter-planetscale"— this appears to be a copy-paste error from when the adapter was created. Not introduced by this PR, but worth fixing while you're touching the file.Proposed fix
- "directory": "packages/adapter-planetscale" + "directory": "packages/adapter-mariadb"package.json (1)
55-55:⚠️ Potential issue | 🔴 CriticalUpdate
@vitest/coverage-v8to match vitest major version.
@vitest/coverage-v8@3.2.4declares peerDependencies requiringvitest@3.2.4exactly. Withvitestupgraded to^4.0.18, the version mismatch will cause peer dependency violations and coverage collection will fail at runtime.Proposed fix
- "@vitest/coverage-v8": "3.2.4", + "@vitest/coverage-v8": "^4.0.18",
|
@aqrln @jacek-prisma please review. Once merged I would like to help with migrating unit tests from jest to vitest. |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (3)
packages/client-engine-runtime/package.json (1)
43-49:⚠️ Potential issue | 🟠 MajorStale
"test": "jest"script — Jest was removed from devDependencies.Jest (
jest,@types/jest,jest-junit) has been removed fromdevDependencies, but the"test": "jest"script on line 49 still references it. Runningpnpm testin this package will fail. Since tests are now executed via the root Vitest workspace, either remove or update this script to align with the migration.🔧 Proposed fix
"scripts": { "dev": "DEV=true tsx helpers/build.ts", "build": "tsx helpers/build.ts", - "prepublishOnly": "pnpm run build", - "test": "jest" + "prepublishOnly": "pnpm run build" },Based on learnings: "do not declare vitest in package.json devDependencies for internal packages. Remove vitest from each package under packages/*/package.json and rely on the root-level vitest installation (via workspace hoisting)."
.github/workflows/test-template.yml (2)
638-661: 🧹 Nitpick | 🔵 TrivialUse
pnpm vitest runinstead ofpnpm vitestfor explicit CI behavior.
pnpm vitestwithout therunsubcommand defaults to watch mode. It only runs once in CI because Vitest detectsprocess.env.CI, but usingvitest runis more explicit and avoids accidental hangs if CI detection fails or when running locally for debugging.The same applies to line 1040.
♻️ Proposed fix
- - run: pnpm vitest + - run: pnpm vitest runAnd at line 1040:
- - run: pnpm vitest + - run: pnpm vitest run
640-646:⚠️ Potential issue | 🟠 Majorvitest job trigger condition is missing
-query-plan-executor-flag.The
vitestjob runs whenjobsToRuncontains-all-or-client-, but changes topackages/query-plan-executorset only-query-plan-executor-injobsToRun. Sincequery-plan-executoris included in the rootvitest.config.tsworkspace and has test files, the vitest job will be skipped for query-plan-executor-only changes. Addcontains(inputs.jobsToRun, '-query-plan-executor-')to the condition, or ensure query-plan-executor changes trigger-all-instead of a dedicated flag.(Note: Other packages like
dmmf,ts-builders, and adapters are handled differently—changes to them trigger the-all-fallback, so vitest runs for those.)
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
.github/workflows/test-template.yml (1)
638-661:⚠️ Potential issue | 🟠 MajorInconsistent trigger condition between standalone vitest job and no-docker vitest step.
The standalone
vitestjob (lines 645–646) triggers on-all-or-client-, but theno-dockerjob'spnpm viteststep (line 1036) triggers only on-all-. This inconsistency means whenpackages/clientchanges, the standalone job runs but theno-dockerstep doesn't—creating a split test execution path.Additionally, the root
vitest.config.tsexplicitly excludespackages/clientfrom its test projects, making the-client-trigger condition in the standalone job semantically incorrect: it will run the job but won't actually test the packages/client changes.Align the trigger conditions so both jobs/steps run under the same conditions, or reconsider whether the standalone vitest job should trigger on
-client-at all if it doesn't test client-related code.
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (3)
.github/workflows/test-template.yml (1)
638-661: 🧹 Nitpick | 🔵 TrivialJob trigger condition (
-client-) is misleading for a job named "Vitest".The
ifcondition (line 644-646) triggers this job on-all-or-client-, inherited from the old "Client internals and generator packages" job. Now that this job is named "Vitest" and runs tests for many non-client packages (debug, dmmf, adapters, ts-builders, etc.), the-client-trigger is confusing. Consider introducing a dedicated trigger like-vitest-to make the intent clearer, or at minimum add a comment explaining why-client-is used.packages/debug/src/__tests__/debug.extended.test.ts (2)
12-19:⚠️ Potential issue | 🟡 Minor
FORCE_COLORenv var leaks across tests.The "with colors" test (line 44) sets
process.env.FORCE_COLOR = 'true', butbeforeEachonly cleans upDEBUGandDEBUG_COLORS.FORCE_COLORis never deleted and can leak into all subsequent tests. With the previousisolateModulesAsyncapproach this was less impactful since each test got a fully isolated module, but with the current shared-cache +resetModulesapproach it could affect color detection in later tests.Suggested fix
beforeEach(() => { delete process.env.DEBUG delete process.env.DEBUG_COLORS + delete process.env.FORCE_COLOR // `@ts-ignore` delete globalThis.DEBUG // `@ts-ignore` delete globalThis.DEBUG_COLORS })
40-53:⚠️ Potential issue | 🟠 MajorFix the "with colors" test:
TERM=dumbin the test environment prevents color verificationThe test sets
DEBUG_COLORS=trueandFORCE_COLOR=trueintending to verify colored output, but the snapshot shows plain text with no ANSI codes. The root cause is that kleur readsTERM,FORCE_COLOR, andNODE_DISABLE_COLORSat module load time and determines color support via:enabled: !NODE_DISABLE_COLORS && TERM !== 'dumb' && FORCE_COLOR !== '0'.The test environment has
TERM=dumb, which disables colors in kleur regardless ofFORCE_COLORbeing set to'true'. This means the test never actually exercises the color code path (lines 117–118 of index.ts), even though the snapshot appears valid for a non-colored environment.To verify colors work, either override
TERMin the test before the module import, or update the test expectations to acknowledge that color testing is not possible in this environment.
| const importDebug = async () => { | ||
| const mod = await import('../index') | ||
| Debug = mod.default | ||
| } |
There was a problem hiding this comment.
Module isolation relies on vi.resetModules() ordering — verify fresh module per test.
The old code used jest.isolateModulesAsync which guaranteed a sandboxed module evaluation per call. The new approach relies on vi.resetModules() in afterEach (line 22) so that the next test's await import('../index') fetches a re-evaluated module. This should work in Vitest, but the very first test has no preceding resetModules call — the static import on line 3 may seed the module cache before any env vars are set.
Consider moving vi.resetModules() into beforeEach (or adding it there in addition to afterEach) to guarantee a clean slate before every dynamic import, including the first test.
Suggested fix
beforeEach(() => {
+ vi.resetModules()
delete process.env.DEBUG
delete process.env.DEBUG_COLORS
// `@ts-ignore`
delete globalThis.DEBUG
// `@ts-ignore`
delete globalThis.DEBUG_COLORS
})| afterEach(() => { | ||
| jest.resetModules() | ||
| jest.restoreAllMocks() | ||
| vi.resetModules() | ||
| vi.restoreAllMocks() | ||
| }) |
There was a problem hiding this comment.
🧹 Nitpick | 🔵 Trivial
Minor: vi.resetModules() in afterEach is now redundant.
Since importDebug() already calls vi.resetModules() before each dynamic import, the call here is a no-op in practice. Keeping it is harmless (belt-and-suspenders), but you could remove it to avoid confusion about where module resets actually happen.
|
@aqrln @jacek-prisma please review and merge. I hope that this change will improve test performance and simplify CI workflow thus developer experience. I'm planning on more vitest migration and further improvements in CI workflow simplification. |
Merging this PR will degrade performance by 34.54%
Performance Changes
Comparing |
|
The |
|
Thank you for this, and sorry it sat so long. Prisma 7 is now a maintenance line that takes bug fixes and security updates, so we are not taking CI or test-tooling changes on it, and this branch has drifted far from |
|
Reopening this, with an apology. We closed it on the grounds that Prisma 7 takes only bug fixes and security updates, but our policy never excluded tooling work on |
v7 already has vitest 4 and the Vitest migrations of debug, get-platform and client-engine-runtime, so their test files take the v7 version. packages/config keeps v7's loadConfigFromFile tests, which v7 extended with the shared vitestContext helper. Signed-off-by: willbot <w.a.madden+machine@gmail.com> Signed-off-by: Will Madden <madden@prisma.io> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The root vitest config runs these packages now. Signed-off-by: willbot <w.a.madden+machine@gmail.com> Signed-off-by: Will Madden <madden@prisma.io> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A change that touches only packages/query-plan-executor sets jobsToRun to -query-plan-executor-. The removed QPE Unit Tests job ran on that; the Vitest job that replaces it must too. Signed-off-by: willbot <w.a.madden+machine@gmail.com> Signed-off-by: Will Madden <madden@prisma.io> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Internals moved to vitest on v7 and relied on the root config. With the root config now listing projects, vitest run inside packages/internals found no projects. Signed-off-by: willbot <w.a.madden+machine@gmail.com> Signed-off-by: Will Madden <madden@prisma.io> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
vitestContext copies fixtures from process.cwd(). The root vitest run keeps the repository root as cwd, so fixture paths pointed outside the package. Signed-off-by: willbot <w.a.madden+machine@gmail.com> Signed-off-by: Will Madden <madden@prisma.io> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
convertDriverError reports the table since prisma#29628. CI never ran this package's tests, so the expectation went stale; the root vitest run now includes it. Signed-off-by: willbot <w.a.madden+machine@gmail.com> Signed-off-by: Will Madden <madden@prisma.io> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ntenance (prisma#31132) Prisma 7 now accepts corrections to, improvements to, and maintenance of the tooling that builds, tests and releases it. For example, a contributed pull request against `v7` that moves the client's unit tests from Jest to Vitest is in scope. It is judged on whether it is correct and keeps the build and CI green, not on whether it fixes a bug. ## Why Six community pull requests against `v7` that changed the test runner and CI were closed as "not bug fixes or security updates" (prisma#29297, prisma#29142, prisma#28035, prisma#28122, prisma#28264, prisma#28269). The policy never meant to exclude this work. Prisma 7 has to stay buildable, testable and releasable for eighteen months after `8.0.0`, and every later fix is cheaper and safer to land when its tooling is healthy. Tooling changes do not change anything users run, so the question of whether a feature fits Prisma 7's design does not apply to them. Those pull requests have been reopened. ## What changes - `docs/oss/versioning.md`: the Prisma 7 paragraph says the line takes tooling work, and why. - `docs/oss/pr-triage.md`: the table of what each line accepts, and step 2's scope rule for Prisma 7, which also says not to close such work for not being a bug fix. - `skills-contrib/triage-contributor-pr/SKILL.md`: the same rule for the triage agent. - ADR 295 (new features do not land on Prisma 7) gets a dated amendment, and its two lines in the decision record index are updated to match. Agent: eeyore-69 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Documentation** * Clarified that Prisma 7 accepts corrections, improvements, and maintenance to build, test, CI, and release tooling, provided the work does not change what users run. * Updated versioning and contribution guidance to reflect this scope and its acceptance criteria. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Signed-off-by: willbot <w.a.madden+machine@gmail.com> Signed-off-by: Will Madden <madden@prisma.io> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Their test scripts passed --testTimeout 30000. Without the scripts, the timeout has to live in each package's vitest config, as it does for client-generator-js; buildGetWasmModule timed out at the 5s default. Signed-off-by: willbot <w.a.madden+machine@gmail.com> Signed-off-by: Will Madden <madden@prisma.io> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: willbot <w.a.madden+machine@gmail.com> Signed-off-by: Will Madden <madden@prisma.io>
wmadden-electric
left a comment
There was a problem hiding this comment.
Thank you. I merged v7 in (which had already taken several of these package migrations from your separate pull requests), kept v7's loadConfigFromFile tests, gave internals, client-generator-ts and credentials-store their own Vitest configs, and made the new Vitest job also run on query-plan-executor changes. It runs on Node 20, 22 and 24 in about five minutes.
Summary by CodeRabbit