Skip to content

Commit

Permalink
fix: set bootstrap app to global
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Dec 29, 2024
1 parent 8f70532 commit ab2cb9c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/lib/app_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ import ApplicationUnittest from '../app/extend/application.js';

const debug = debuglog('@eggjs/mock/lib/app_handler');

let app: ApplicationUnittest;
declare namespace globalThis {
let __eggMockAppInstance: ApplicationUnittest | null;
}

globalThis.__eggMockAppInstance = null;

export function setupApp() {
let app = globalThis.__eggMockAppInstance!;

Check warning on line 18 in src/lib/app_handler.ts

View check run for this annotation

Codecov / codecov/patch

src/lib/app_handler.ts#L18

Added line #L18 was not covered by tests
if (app) {
debug('return exists app');
return app;
Expand Down Expand Up @@ -46,6 +51,7 @@ export function setupApp() {
afterEach(restore);
}
}
globalThis.__eggMockAppInstance = app;

Check warning on line 54 in src/lib/app_handler.ts

View check run for this annotation

Codecov / codecov/patch

src/lib/app_handler.ts#L54

Added line #L54 was not covered by tests
return app;
}

Expand All @@ -59,12 +65,13 @@ export async function getApp(suite?: unknown, test?: unknown) {
if (getAppCallback) {
return getAppCallback(suite, test);
}
const app = globalThis.__eggMockAppInstance!;

Check warning on line 68 in src/lib/app_handler.ts

View check run for this annotation

Codecov / codecov/patch

src/lib/app_handler.ts#L68

Added line #L68 was not covered by tests
if (app) {
await app.ready();
}
return app;
}

export function getBootstrapApp() {
return app;
return globalThis.__eggMockAppInstance!;

Check warning on line 76 in src/lib/app_handler.ts

View check run for this annotation

Codecov / codecov/patch

src/lib/app_handler.ts#L76

Added line #L76 was not covered by tests
}

0 comments on commit ab2cb9c

Please sign in to comment.