@eggjs/mock 7.0.2-beta.1 → 7.0.2-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -29,10 +29,12 @@ function setupApp() {
29
29
  debug("mockParallelApp app: %s", !!app);
30
30
  } else {
31
31
  app = createApp(options);
32
- if (typeof beforeAll === "function") beforeAll(() => app.ready());
33
- if (typeof afterEach === "function") {
34
- afterEach(() => app.backgroundTasksFinished());
35
- afterEach(restore);
32
+ if (!globalThis.__eggMockVitestSetup) {
33
+ if (typeof beforeAll === "function") beforeAll(() => app.ready());
34
+ if (typeof afterEach === "function") {
35
+ afterEach(() => app.backgroundTasksFinished());
36
+ afterEach(restore);
37
+ }
36
38
  }
37
39
  }
38
40
  globalThis.__eggMockAppInstance = app;
@@ -7,11 +7,25 @@ if (!g.before) g.before = beforeAll;
7
7
  if (!g.after) g.after = afterAll;
8
8
  if (!g.beforeEach) g.beforeEach = beforeEach;
9
9
  if (!g.afterEach) g.afterEach = afterEach;
10
+ globalThis.__eggMockVitestSetup = true;
11
+ if (!globalThis.__teggVitestConfig) globalThis.__teggVitestConfig = {
12
+ restoreMocks: true,
13
+ getApp: async () => {
14
+ return (await import("./bootstrap.js"))?.app;
15
+ }
16
+ };
10
17
  let app;
18
+ let startupPromise;
11
19
  beforeAll(async () => {
12
- const { app: bootstrapApp } = await import("./bootstrap.js");
13
- app = bootstrapApp;
14
- await app.ready();
20
+ if (!startupPromise) {
21
+ startupPromise = (async () => {
22
+ const { app: bootstrapApp } = await import("./bootstrap.js");
23
+ app = bootstrapApp;
24
+ await app.ready();
25
+ })();
26
+ startupPromise.catch(() => {});
27
+ }
28
+ await startupPromise;
15
29
  });
16
30
  afterEach(async () => {
17
31
  if (app && typeof app.backgroundTasksFinished === "function") await app.backgroundTasksFinished();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eggjs/mock",
3
- "version": "7.0.2-beta.1",
3
+ "version": "7.0.2-beta.2",
4
4
  "description": "mock server plugin for egg",
5
5
  "keywords": [
6
6
  "egg",
@@ -72,20 +72,20 @@
72
72
  "sdk-base": "^5.0.1",
73
73
  "urllib": "^4.8.2",
74
74
  "utility": "^2.5.0",
75
- "@eggjs/extend2": "5.0.2-beta.1",
76
- "@eggjs/supertest": "9.0.2-beta.1",
77
- "@eggjs/utils": "5.0.2-beta.1"
75
+ "@eggjs/extend2": "5.0.2-beta.2",
76
+ "@eggjs/supertest": "9.0.2-beta.2",
77
+ "@eggjs/utils": "5.0.2-beta.2"
78
78
  },
79
79
  "devDependencies": {
80
80
  "@types/methods": "^1.1.4",
81
81
  "typescript": "^5.9.3",
82
- "@eggjs/errors": "3.0.2-beta.1",
83
- "@eggjs/tracer": "4.0.2-beta.1",
84
- "egg": "4.1.2-beta.1"
82
+ "@eggjs/errors": "3.0.2-beta.2",
83
+ "egg": "4.1.2-beta.2",
84
+ "@eggjs/tracer": "4.0.2-beta.2"
85
85
  },
86
86
  "peerDependencies": {
87
87
  "vitest": "^4.0.15",
88
- "egg": "4.1.2-beta.1"
88
+ "egg": "4.1.2-beta.2"
89
89
  },
90
90
  "peerDependenciesMeta": {
91
91
  "vitest": {