π generate the database client before any project's tests - #691
Merged
Conversation
Only the opencrane project declared db:generate as a dependency of its test and lint targets, but libraries across the workspace import generated Prisma enums and error classes at module scope. Whether the client existed when a library's tests ran therefore depended on what else the affected graph happened to select and in what order β a race, not a contract. When it lost, the client's exports read as undefined and the failure looked nothing like its cause: "Cannot read properties of undefined (reading 'Preparing')" at module init, or "Right-hand side of 'instanceof' is not an object" from a repository comparing against Prisma.PrismaClientKnownRequestError. Whole suites failed in files the change under test never touched. Making generation a dependency of the test and lint defaults fixes every project at once, and fixes a fresh clone too: running one library's tests now generates the client first instead of failing in a way that reads like a code defect. Verified by removing the generated client entirely and running one library's tests: Nx runs opencrane:db:generate first, then 22 files and 141 tests pass. Before, the same command left 12 suites failing at import.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What broke
#688 failed the
testjob with 64 failures across suites it does not touch:ToolInvocationState.PreparingandPrisma.PrismaClientKnownRequestErrorare both generated Prisma exports. Both read asundefined, so the generated client was missing in that job.Cause
db:generatewas declared as a dependency oftestandlintonly on the opencrane project. Libraries across the workspace import generated enums and error classes at module scope but declared no such dependency, so whether the client existed when a library's tests ran depended on which projects the affected graph selected and in what order.That is a race, and it fails in a way that reads like a code defect rather than a missing build step β whole suites break at import, in files the change never touched. It also means a fresh clone cannot run one library's tests successfully.
What changed
db:generateis now a dependency of thetestandlinttarget defaults, so it holds for every project rather than one.Verification
Removed the generated client entirely, then ran a single library's tests:
The same command before this change left 12 suites failing at import. No workflow edit is needed β fixing the graph fixes CI and local runs together.
Merge order
Merge this before #688; that PR is red only because of this race and needs no change of its own.
Review order
Single PR, no stack.