fix(tegg-vitest): reuse runner module graph for prototypes#6029
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughVitest gains a published setup module that defines a global ESM/CommonJS-aware module importer. Vitest configuration and ChangesVitest importer integration
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant FixtureTest
participant EggModuleImporter
participant TargetModule
FixtureTest->>EggModuleImporter: Call __EGG_MODULE_IMPORTER__(filePath)
EggModuleImporter->>EggModuleImporter: Detect ESM or CommonJS format
EggModuleImporter->>TargetModule: import() or require()
TargetModule-->>FixtureTest: Return HelloService module
FixtureTest->>FixtureTest: Compare dynamic and static HelloService references
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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.
Code Review
This pull request bumps package versions to 4.0.2-beta.21 and introduces a global module importer (globalThis.EGG_MODULE_IMPORTER) in TeggVitestRunner to route prototype file imports through Vitest's module graph, ensuring consistent class instances between application loading and test imports. The feedback suggests casting globalThis to any to prevent potential TypeScript compilation errors, and adding an assertion in the test suite to verify the importer is defined before invocation, preventing a potential TypeError.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## next #6029 +/- ##
=======================================
Coverage 82.17% 82.17%
=======================================
Files 678 678
Lines 20838 20842 +4
Branches 4154 4155 +1
=======================================
+ Hits 17123 17127 +4
Misses 3207 3207
Partials 508 508 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR updates the @eggjs/tegg-vitest runner to install a default globalThis.__EGG_MODULE_IMPORTER__ that routes prototype discovery through Vitest’s module graph, ensuring loader-time imports and test-time imports share identical class references (avoiding duplicate prototype registration).
Changes:
- Install a default
__EGG_MODULE_IMPORTER__in the custom Vitest runner using Vitest’simportFile(..., 'collect'). - Add a fixture assertion verifying loader-side imports reuse the exact
HelloServiceclass reference imported by the test. - Bump
@eggjs/tegg-vitestand@eggjs/tegg-loaderversions to4.0.2-beta.21.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tegg/core/vitest/test/fixture_app.test.ts | Adds a regression assertion to confirm module/class identity is reused via the importer. |
| tegg/core/vitest/src/runner.ts | Installs a default global module importer that reuses Vitest’s module graph during collection. |
| tegg/core/vitest/package.json | Version bump for @eggjs/tegg-vitest to 4.0.2-beta.21. |
| tegg/core/loader/package.json | Version bump for @eggjs/tegg-loader to 4.0.2-beta.21. |
|
Dependency limit exceeded — report not shown. This pull request scan exceeded the 10,000-dependency limit applied to this scan, so the results are incomplete and may be inaccurate. To avoid reporting false positives, Socket has not posted a report. Upgrade your plan to raise the dependency limit and get complete reports, or view the partial scan in the dashboard. Socket is always free for open source. If this is a non-commercial open source project, contact us to request a free Team account. |
Summary
__EGG_MODULE_IMPORTER__in the TEGG Vitest runnerRoot cause
TEGG discovers modules during Egg boot. Without a runner-provided importer, application loading can evaluate a prototype through Node while Vitest evaluates the same file in its own module graph. The two class identities then produce duplicate prototype registration in larger applications.
The runner now uses the normal collection import path. Vitest
setupimports are intentionally avoided because they invalidate the evaluated-module cache.Validation
tegg/core/vitest: fixture app test passedtegg/core/vitest: hook tests passed when run independentlytegg/core/vitest:ut run typechecktegg/core/loader: 14 loader tests passed@eggjs/tegg-loader@4.0.2-beta.21,@eggjs/tegg-vitest@4.0.2-beta.21Summary by CodeRabbit
New Features
Bug Fixes
Tests