Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tegg/core/loader/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eggjs/tegg-loader",
"version": "4.0.2-beta.20",
"version": "4.0.2-beta.21",
"description": "tegg default loader implement",
"keywords": [
"egg",
Expand Down
2 changes: 1 addition & 1 deletion tegg/core/vitest/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eggjs/tegg-vitest",
"version": "4.0.2-beta.20",
"version": "4.0.2-beta.21",
"description": "Vitest adapter for tegg context injection",
"keywords": [
"adapter",
Expand Down
6 changes: 6 additions & 0 deletions tegg/core/vitest/src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ export default class TeggVitestRunner extends VitestTestRunner {

constructor(config: ConstructorParameters<typeof VitestTestRunner>[0]) {
super(config);
// TEGG discovers prototype files while the Egg app is booting. Route those
// imports through Vitest's module graph so application loading and test
// imports resolve to the same class instances.
// `setup` imports intentionally invalidate Vitest's module cache. Use the
// regular collection path here so an already imported prototype is reused.
globalThis.__EGG_MODULE_IMPORTER__ = async (filepath: string) => super.importFile(filepath, 'collect');
Comment thread
elrrrrrrr marked this conversation as resolved.
Outdated
Comment thread
elrrrrrrr marked this conversation as resolved.
Outdated
Comment thread
elrrrrrrr marked this conversation as resolved.
Outdated
Comment thread
elrrrrrrr marked this conversation as resolved.
Outdated
// When isolate: false, all test files share the same worker and module cache.
// The app must not be closed between files — only after all files finish.
this.sharedMode = !config.isolate;
Expand Down
5 changes: 5 additions & 0 deletions tegg/core/vitest/test/fixture_app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ describe('fixture demo app', () => {
});

it('injects ctx and getEggObject', async () => {
const loadedModule = (await globalThis.__EGG_MODULE_IMPORTER__?.(
path.join(__dirname, 'fixtures/apps/demo-app/modules/demo-module/HelloService.ts'),
)) as { HelloService: typeof HelloService };
assert.strictEqual(loadedModule.HelloService, HelloService);
Comment thread
elrrrrrrr marked this conversation as resolved.
Comment thread
elrrrrrrr marked this conversation as resolved.
Comment thread
elrrrrrrr marked this conversation as resolved.

const ctx = app.ctxStorage.getStore();
assert(ctx);
const helloService = (await ctx.getEggObject(HelloService)) as any;
Expand Down
Loading