fix(core): recover schema-factory imports in single-mode mock writer - #3648
Conversation
…rval-labs#3627) single-mode.ts was the only writer missing the collectRecoveredSchemaFactoryImports + mergeGeneratorImports recovery pattern added to split/tags/split-tags in 66af3e2. On wide specs with faker schemas:true, shared-array import aggregation could strip get<X>Mock() factory imports, producing uncompilable single-mode mock output. Inline branch: added per-mockOutput finalization, recovery scan, and merge before importsMock. Also passes the finalized implementation to builder.importsMock (was passing raw mockOutput.implementation — matches the other three writers). De-inlined branch: reordered so finalization happens before importsMockForBuilder (was computed before, making recovery impossible), and added the same recovery + merge pipeline.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthrough
Changessingle-mode faker schema-factory import recovery
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/core/src/writers/single-mode.test.ts`:
- Around line 207-211: The test in single-mode.test.ts is only asserting that
getPetMock appears in the generated file, which can pass even if import recovery
is broken. Update the assertion in the relevant test case to verify the emitted
import statement from the recovered mock module instead, using the same
mockContent check in single-mode.test.ts so the test proves the import was
actually restored.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 889db170-1b9a-46a1-a1f5-b42730a304dd
📒 Files selected for processing (2)
packages/core/src/writers/single-mode.test.tspackages/core/src/writers/single-mode.ts
…ed test
toContain('getPetMock') passes trivially since the implementation
body already calls getPetMock(). Switch to a regex that matches
the import statement, proving the import was actually recovered.
Summary
single-mode.tswas the only writer missing thecollectRecoveredSchemaFactoryImports+mergeGeneratorImportsrecovery pattern thatsplit-mode,tags-mode, andsplit-tags-modeall use (#3607,66af3e25b). On wide specs withfaker schemas: true, shared-array import aggregation can stripget<X>Mock()factory imports frommockOutput.imports, producing uncompilable single-mode mock output.Changes
Both mock branches in
single-mode.tsare updated:Inline branch (
!shouldDeinlineMocks):finalizedMockImplementationcomputation,usesSchemaFactoriescheck, andcollectRecoveredSchemaFactoryImports+mergeGeneratorImportsbeforefilterLocalStrictMockTypeImportsbuilder.importsMockinstead of rawmockOutput.implementation(matches the other three writers; required for the recovery scan to seeas PetMockcasts added during finalization)De-inlined branch (
shouldDeinlineMocks):finalizedMockImplementationis computed beforeimportsMockForBuilder(was computed after, making recovery impossible)filterLocalStrictMockTypeImportspipelineTests
Two regression tests in
single-mode.test.ts:getPetMockappears inbuilder.importsMockimports when missing frommockOutput.imports.faker.tsfile containsgetPetMockCloses #3627
Summary by CodeRabbit