@eggjs/mock 7.0.0-beta.34 → 7.0.0-beta.36
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.
- package/dist/_virtual/rolldown_runtime.js +7 -0
- package/dist/app/extend/agent.d.ts +38 -34
- package/dist/app/extend/agent.js +48 -46
- package/dist/app/extend/application.d.ts +171 -167
- package/dist/app/extend/application.js +382 -442
- package/dist/app/middleware/cluster_app_mock.d.ts +5 -2
- package/dist/app/middleware/cluster_app_mock.js +95 -100
- package/dist/app.d.ts +9 -5
- package/dist/app.js +17 -18
- package/dist/bootstrap.d.ts +9 -5
- package/dist/bootstrap.js +11 -12
- package/dist/index.d.ts +20 -17
- package/dist/index.js +39 -78
- package/dist/inject_mocha.d.ts +1 -1
- package/dist/inject_mocha.js +27 -28
- package/dist/lib/agent_handler.d.ts +7 -3
- package/dist/lib/agent_handler.js +22 -20
- package/dist/lib/app.d.ts +7 -3
- package/dist/lib/app.js +246 -287
- package/dist/lib/app_handler.d.ts +9 -5
- package/dist/lib/app_handler.js +48 -61
- package/dist/lib/cluster.d.ts +122 -118
- package/dist/lib/cluster.js +278 -335
- package/dist/lib/context.d.ts +4 -1
- package/dist/lib/context.js +10 -11
- package/dist/lib/format_options.d.ts +9 -4
- package/dist/lib/format_options.js +60 -88
- package/dist/lib/inject_context.d.ts +8 -5
- package/dist/lib/inject_context.js +103 -123
- package/dist/lib/mock_agent.d.ts +8 -4
- package/dist/lib/mock_agent.js +42 -42
- package/dist/lib/mock_custom_loader.d.ts +4 -1
- package/dist/lib/mock_custom_loader.js +34 -33
- package/dist/lib/mock_http_server.d.ts +6 -2
- package/dist/lib/mock_http_server.js +16 -17
- package/dist/lib/mock_httpclient.d.ts +38 -34
- package/dist/lib/mock_httpclient.js +106 -142
- package/dist/lib/parallel/agent.d.ts +22 -18
- package/dist/lib/parallel/agent.js +106 -112
- package/dist/lib/parallel/app.d.ts +23 -19
- package/dist/lib/parallel/app.js +93 -106
- package/dist/lib/parallel/util.d.ts +5 -2
- package/dist/lib/parallel/util.js +56 -63
- package/dist/lib/prerequire.d.ts +1 -1
- package/dist/lib/prerequire.js +1 -25
- package/dist/lib/request_call_function.d.ts +1 -1
- package/dist/lib/request_call_function.js +34 -47
- package/dist/lib/restore.d.ts +4 -1
- package/dist/lib/restore.js +14 -11
- package/dist/lib/start-cluster.d.ts +1 -2
- package/dist/lib/start-cluster.js +15 -14
- package/dist/lib/supertest.d.ts +14 -9
- package/dist/lib/supertest.js +32 -36
- package/dist/lib/tmp/empty.d.ts +1 -1
- package/dist/lib/tmp/empty.js +1 -2
- package/dist/lib/types.d.ts +71 -67
- package/dist/lib/types.js +1 -2
- package/dist/lib/utils.d.ts +11 -8
- package/dist/lib/utils.js +34 -63
- package/dist/register.d.ts +11 -7
- package/dist/register.js +36 -40
- package/dist/typings/index.d.ts +1 -0
- package/package.json +36 -39
|
@@ -1,101 +1,96 @@
|
|
|
1
|
-
import { debuglog } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
catch (err) {
|
|
96
|
-
ctx.status = 500;
|
|
97
|
-
ctx.body = { success: false, error: err.message };
|
|
98
|
-
}
|
|
99
|
-
};
|
|
1
|
+
import { debuglog } from "node:util";
|
|
2
|
+
|
|
3
|
+
//#region src/app/middleware/cluster_app_mock.ts
|
|
4
|
+
const debug = debuglog("egg/mock/app/middleware/cluster_app_mock");
|
|
5
|
+
var cluster_app_mock_default = () => {
|
|
6
|
+
return async function clusterAppMock(ctx, next) {
|
|
7
|
+
if (ctx.originalUrl !== "/__egg_mock_call_function") return next();
|
|
8
|
+
const body = ctx.request.body;
|
|
9
|
+
debug("%s %s, body: %j", ctx.method, ctx.url, body);
|
|
10
|
+
const { method, property, args, needResult } = body;
|
|
11
|
+
if (!method) {
|
|
12
|
+
ctx.status = 422;
|
|
13
|
+
ctx.body = {
|
|
14
|
+
success: false,
|
|
15
|
+
error: "Missing method"
|
|
16
|
+
};
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (args && !Array.isArray(args)) {
|
|
20
|
+
ctx.status = 422;
|
|
21
|
+
ctx.body = {
|
|
22
|
+
success: false,
|
|
23
|
+
error: "args should be an Array instance"
|
|
24
|
+
};
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (property) {
|
|
28
|
+
if (method === "__getter__") {
|
|
29
|
+
if (!ctx.app[property]) {
|
|
30
|
+
debug("property %s not exists on app", property);
|
|
31
|
+
ctx.status = 422;
|
|
32
|
+
ctx.body = {
|
|
33
|
+
success: false,
|
|
34
|
+
error: `property "${property}" not exists on app`
|
|
35
|
+
};
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
ctx.body = {
|
|
39
|
+
success: true,
|
|
40
|
+
result: ctx.app[property]
|
|
41
|
+
};
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (!ctx.app[property] || typeof ctx.app[property][method] !== "function") {
|
|
45
|
+
debug("property %s.%s not exists on app", property, method);
|
|
46
|
+
ctx.status = 422;
|
|
47
|
+
ctx.body = {
|
|
48
|
+
success: false,
|
|
49
|
+
error: `method "${method}" not exists on app.${property}`
|
|
50
|
+
};
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
} else if (typeof ctx.app[method] !== "function") {
|
|
54
|
+
debug("method %s not exists on app", method);
|
|
55
|
+
ctx.status = 422;
|
|
56
|
+
ctx.body = {
|
|
57
|
+
success: false,
|
|
58
|
+
error: `method "${method}" not exists on app`
|
|
59
|
+
};
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
debug("call %s with %j", method, args);
|
|
63
|
+
for (let i = 0; i < args.length; i++) {
|
|
64
|
+
const arg = args[i];
|
|
65
|
+
if (arg && typeof arg === "object") {
|
|
66
|
+
if (arg.__egg_mock_type === "function") args[i] = eval(`(function() { return ${arg.value} })()`);
|
|
67
|
+
else if (arg.__egg_mock_type === "error") {
|
|
68
|
+
const err = new Error(arg.message);
|
|
69
|
+
err.name = arg.name;
|
|
70
|
+
err.stack = arg.stack;
|
|
71
|
+
for (const key in arg) if (key !== "name" && key !== "message" && key !== "stack" && key !== "__egg_mock_type") err[key] = arg[key];
|
|
72
|
+
args[i] = err;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const target = property ? ctx.app[property] : ctx.app;
|
|
77
|
+
const fn = target[method];
|
|
78
|
+
try {
|
|
79
|
+
Promise.resolve(fn.call(target, ...args)).then((result) => {
|
|
80
|
+
ctx.body = needResult ? {
|
|
81
|
+
success: true,
|
|
82
|
+
result
|
|
83
|
+
} : { success: true };
|
|
84
|
+
});
|
|
85
|
+
} catch (err) {
|
|
86
|
+
ctx.status = 500;
|
|
87
|
+
ctx.body = {
|
|
88
|
+
success: false,
|
|
89
|
+
error: err.message
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
};
|
|
100
93
|
};
|
|
101
|
-
|
|
94
|
+
|
|
95
|
+
//#endregion
|
|
96
|
+
export { cluster_app_mock_default as default };
|
package/dist/app.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { Application, ILifecycleBoot } from "egg";
|
|
2
|
+
|
|
3
|
+
//#region src/app.d.ts
|
|
4
|
+
declare class Boot implements ILifecycleBoot {
|
|
5
|
+
#private;
|
|
6
|
+
constructor(app: Application);
|
|
7
|
+
configWillLoad(): void;
|
|
6
8
|
}
|
|
9
|
+
//#endregion
|
|
10
|
+
export { Boot as default };
|
package/dist/app.js
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
import { Application } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXBwLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL2FwcC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQXVCLFdBQVcsRUFBRSxNQUFNLEtBQUssQ0FBQztBQUV2RCxNQUFNLENBQUMsT0FBTyxPQUFPLElBQUk7SUFDdkIsSUFBSSxDQUFjO0lBQ2xCLFlBQVksR0FBZ0I7UUFDMUIsSUFBSSxDQUFDLElBQUksR0FBRyxHQUFHLENBQUM7SUFDbEIsQ0FBQztJQUVELGNBQWM7UUFDWixzREFBc0Q7UUFDdEQsTUFBTSxLQUFLLEdBQUcsSUFBSSxDQUFDLElBQUksQ0FBQyxNQUFNLENBQUMsY0FBYyxDQUFDLE9BQU8sQ0FBQyxZQUFZLENBQUMsQ0FBQztRQUNwRSxJQUFJLEtBQUssSUFBSSxDQUFDLEVBQUUsQ0FBQztZQUNmLElBQUksQ0FBQyxJQUFJLENBQUMsTUFBTSxDQUFDLGNBQWMsQ0FBQyxNQUFNLENBQUMsS0FBSyxFQUFFLENBQUMsRUFBRSxnQkFBZ0IsQ0FBQyxDQUFDO1FBQ3JFLENBQUM7YUFBTSxDQUFDO1lBQ04sSUFBSSxDQUFDLElBQUksQ0FBQyxNQUFNLENBQUMsY0FBYyxDQUFDLElBQUksQ0FBQyxnQkFBZ0IsQ0FBQyxDQUFDO1FBQ3pELENBQUM7SUFDSCxDQUFDO0NBQ0YifQ==
|
|
1
|
+
import { Application } from "egg";
|
|
2
|
+
|
|
3
|
+
//#region src/app.ts
|
|
4
|
+
var Boot = class {
|
|
5
|
+
#app;
|
|
6
|
+
constructor(app) {
|
|
7
|
+
this.#app = app;
|
|
8
|
+
}
|
|
9
|
+
configWillLoad() {
|
|
10
|
+
const index = this.#app.config.coreMiddleware.indexOf("securities");
|
|
11
|
+
if (index >= 0) this.#app.config.coreMiddleware.splice(index, 0, "clusterAppMock");
|
|
12
|
+
else this.#app.config.coreMiddleware.push("clusterAppMock");
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
export { Boot as default };
|
package/dist/bootstrap.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import ApplicationUnittest from "./app/extend/application.js";
|
|
2
|
+
import { getBootstrapApp } from "./lib/app_handler.js";
|
|
3
|
+
import proxyMock from "./index.js";
|
|
4
|
+
import { strict as assert } from "node:assert";
|
|
5
|
+
|
|
6
|
+
//#region src/bootstrap.d.ts
|
|
7
|
+
declare const app: ApplicationUnittest;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { type ApplicationUnittest as MockApplication, app, assert, getBootstrapApp, proxyMock as mm, proxyMock as mock };
|
package/dist/bootstrap.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import { strict as assert } from 'node:assert';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { readJSONSync } from 'utility';
|
|
4
|
-
import mm, { mock } from "./index.js";
|
|
5
|
-
import { getBootstrapApp, setupApp } from "./lib/app_handler.js";
|
|
6
1
|
import { getEggOptions } from "./lib/utils.js";
|
|
2
|
+
import { getBootstrapApp, setupApp } from "./lib/app_handler.js";
|
|
3
|
+
import src_default, { mm as proxyMock } from "./index.js";
|
|
4
|
+
import { strict as assert } from "node:assert";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { readJSONSync } from "utility";
|
|
7
|
+
|
|
8
|
+
//#region src/bootstrap.ts
|
|
7
9
|
const options = getEggOptions();
|
|
8
|
-
|
|
9
|
-
const pkgInfo = readJSONSync(path.join(options.baseDir || process.cwd(), 'package.json'));
|
|
10
|
-
if (pkgInfo.eggPlugin) {
|
|
11
|
-
throw new Error('DO NOT USE bootstrap to test plugin');
|
|
12
|
-
}
|
|
10
|
+
if (readJSONSync(path.join(options.baseDir || process.cwd(), "package.json")).eggPlugin) throw new Error("DO NOT USE bootstrap to test plugin");
|
|
13
11
|
const app = setupApp();
|
|
14
|
-
|
|
15
|
-
//#
|
|
12
|
+
|
|
13
|
+
//#endregion
|
|
14
|
+
export { app, assert, getBootstrapApp, src_default as mm, proxyMock as mock };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,19 +1,22 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import { setGetAppCallback } from
|
|
6
|
-
import
|
|
7
|
-
|
|
1
|
+
import { MockHttpClientMethod, MockResponseCallbackOptions, MockResultFunction, MockResultOptions, ResultObject } from "./lib/mock_httpclient.js";
|
|
2
|
+
import { MockAgent, MockApplicationOptions, MockClusterApplicationOptions, MockClusterOptions, MockOption, MockOptions } from "./lib/types.js";
|
|
3
|
+
import ApplicationUnittest from "./app/extend/application.js";
|
|
4
|
+
import { createApp } from "./lib/app.js";
|
|
5
|
+
import { setGetAppCallback } from "./lib/app_handler.js";
|
|
6
|
+
import { MockClusterApplication, createCluster } from "./lib/cluster.js";
|
|
7
|
+
import { restore as restore$1 } from "./lib/restore.js";
|
|
8
|
+
import mm$1 from "mm";
|
|
9
|
+
|
|
10
|
+
//#region src/index.d.ts
|
|
8
11
|
interface ExtendedMock {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
restore: typeof restore$1;
|
|
13
|
+
app: typeof createApp;
|
|
14
|
+
cluster: typeof createCluster;
|
|
15
|
+
env: (env: string) => void;
|
|
16
|
+
consoleLevel: (level: string) => void;
|
|
17
|
+
home: (homePath?: string) => void;
|
|
18
|
+
setGetAppCallback: typeof setGetAppCallback;
|
|
16
19
|
}
|
|
17
|
-
declare const proxyMock: ((target: any, property: PropertyKey, value?: any) => void) & ExtendedMock & typeof mm;
|
|
18
|
-
|
|
19
|
-
export {
|
|
20
|
+
declare const proxyMock: ((target: any, property: PropertyKey, value?: any) => void) & ExtendedMock & typeof mm$1;
|
|
21
|
+
//#endregion
|
|
22
|
+
export { MockAgent, type ApplicationUnittest as MockApplication, MockApplicationOptions, type MockClusterApplication, MockClusterApplicationOptions, MockClusterOptions, MockHttpClientMethod, MockOption, MockOptions, MockResponseCallbackOptions, MockResultFunction, MockResultOptions, ResultObject, createApp, createCluster, proxyMock as default, proxyMock as mm, proxyMock as mock, setGetAppCallback };
|
package/dist/index.js
CHANGED
|
@@ -1,86 +1,47 @@
|
|
|
1
|
-
import mm from 'mm';
|
|
2
|
-
import { mock as _mock } from 'mm';
|
|
3
|
-
import { createCluster } from "./lib/cluster.js";
|
|
4
1
|
import { createApp } from "./lib/app.js";
|
|
5
|
-
|
|
6
|
-
import { restore } from "./lib/restore.js";
|
|
2
|
+
import { createCluster } from "./lib/cluster.js";
|
|
3
|
+
import { restore as restore$1 } from "./lib/restore.js";
|
|
7
4
|
import { setGetAppCallback } from "./lib/app_handler.js";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
*/
|
|
29
|
-
app: createApp,
|
|
30
|
-
/**
|
|
31
|
-
* Create a egg mocked cluster application
|
|
32
|
-
* @function mm#cluster
|
|
33
|
-
* @see ClusterApplication
|
|
34
|
-
*/
|
|
35
|
-
cluster: createCluster,
|
|
36
|
-
/**
|
|
37
|
-
* mock the serverEnv of Egg
|
|
38
|
-
* @member {Function} mm#env
|
|
39
|
-
* @param {String} env - contain default, test, prod, local, unittest
|
|
40
|
-
* @see https://github.com/eggjs/egg-core/blob/master/lib/loader/egg_loader.js#L78
|
|
41
|
-
*/
|
|
42
|
-
env(env) {
|
|
43
|
-
_mock(process.env, 'EGG_MOCK_SERVER_ENV', env);
|
|
44
|
-
_mock(process.env, 'EGG_SERVER_ENV', env);
|
|
45
|
-
},
|
|
46
|
-
/**
|
|
47
|
-
* mock console level
|
|
48
|
-
* @param {String} level - logger level
|
|
49
|
-
*/
|
|
50
|
-
consoleLevel(level) {
|
|
51
|
-
level = (level || '').toUpperCase();
|
|
52
|
-
_mock(process.env, 'EGG_LOG', level);
|
|
53
|
-
},
|
|
54
|
-
home(homePath) {
|
|
55
|
-
if (homePath) {
|
|
56
|
-
_mock(process.env, 'EGG_HOME', homePath);
|
|
57
|
-
}
|
|
58
|
-
},
|
|
59
|
-
setGetAppCallback,
|
|
5
|
+
import mm$1, { mock } from "mm";
|
|
6
|
+
|
|
7
|
+
//#region src/index.ts
|
|
8
|
+
const mock$1 = {
|
|
9
|
+
...mm$1,
|
|
10
|
+
restore: restore$1,
|
|
11
|
+
app: createApp,
|
|
12
|
+
cluster: createCluster,
|
|
13
|
+
env(env) {
|
|
14
|
+
mock(process.env, "EGG_MOCK_SERVER_ENV", env);
|
|
15
|
+
mock(process.env, "EGG_SERVER_ENV", env);
|
|
16
|
+
},
|
|
17
|
+
consoleLevel(level) {
|
|
18
|
+
level = (level || "").toUpperCase();
|
|
19
|
+
mock(process.env, "EGG_LOG", level);
|
|
20
|
+
},
|
|
21
|
+
home(homePath) {
|
|
22
|
+
if (homePath) mock(process.env, "EGG_HOME", homePath);
|
|
23
|
+
},
|
|
24
|
+
setGetAppCallback
|
|
60
25
|
};
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
// mm.isMocked(foo, 'bar')
|
|
69
|
-
return Reflect.get(mock, property, receiver);
|
|
70
|
-
},
|
|
26
|
+
const proxyMock = new Proxy(mock, {
|
|
27
|
+
apply(target, _, args) {
|
|
28
|
+
return target(args[0], args[1], args[2]);
|
|
29
|
+
},
|
|
30
|
+
get(_target, property, receiver) {
|
|
31
|
+
return Reflect.get(mock$1, property, receiver);
|
|
32
|
+
}
|
|
71
33
|
});
|
|
72
|
-
|
|
73
|
-
export { proxyMock as mock,
|
|
74
|
-
// alias to mm
|
|
75
|
-
proxyMock as mm, setGetAppCallback, createApp, createCluster, };
|
|
34
|
+
var src_default = proxyMock;
|
|
76
35
|
process.setMaxListeners(100);
|
|
77
|
-
process.once(
|
|
78
|
-
|
|
36
|
+
process.once("SIGQUIT", () => {
|
|
37
|
+
process.exit(0);
|
|
79
38
|
});
|
|
80
|
-
process.once(
|
|
81
|
-
|
|
39
|
+
process.once("SIGTERM", () => {
|
|
40
|
+
process.exit(0);
|
|
82
41
|
});
|
|
83
|
-
process.once(
|
|
84
|
-
|
|
42
|
+
process.once("SIGINT", () => {
|
|
43
|
+
process.exit(0);
|
|
85
44
|
});
|
|
86
|
-
|
|
45
|
+
|
|
46
|
+
//#endregion
|
|
47
|
+
export { createApp, createCluster, src_default as default, proxyMock as mm, proxyMock as mock, setGetAppCallback };
|
package/dist/inject_mocha.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "mocha";
|
package/dist/inject_mocha.js
CHANGED
|
@@ -1,35 +1,34 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { getRequire } from '@eggjs/utils';
|
|
1
|
+
import { __require } from "./_virtual/rolldown_runtime.js";
|
|
3
2
|
import { injectContext } from "./lib/inject_context.js";
|
|
4
|
-
|
|
3
|
+
import { debuglog } from "node:util";
|
|
4
|
+
import { getRequire } from "@eggjs/utils";
|
|
5
|
+
import "mocha";
|
|
6
|
+
|
|
7
|
+
//#region src/inject_mocha.ts
|
|
8
|
+
const debug = debuglog("egg/mock/inject_mocha");
|
|
5
9
|
/**
|
|
6
|
-
|
|
7
|
-
|
|
10
|
+
* Find active node mocha instances.
|
|
11
|
+
*/
|
|
8
12
|
function findNodeJSMocha() {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return typeof val === 'function' && val.name === 'Mocha';
|
|
22
|
-
})
|
|
23
|
-
.map(function (child) {
|
|
24
|
-
return children[child].exports;
|
|
25
|
-
});
|
|
13
|
+
let children;
|
|
14
|
+
if (typeof __require === "function") children = __require.cache || {};
|
|
15
|
+
else {
|
|
16
|
+
children = getRequire().cache || {};
|
|
17
|
+
debug("createRequire on esm");
|
|
18
|
+
}
|
|
19
|
+
return Object.keys(children).filter(function(child) {
|
|
20
|
+
const val = children[child].exports;
|
|
21
|
+
return typeof val === "function" && val.name === "Mocha";
|
|
22
|
+
}).map(function(child) {
|
|
23
|
+
return children[child].exports;
|
|
24
|
+
});
|
|
26
25
|
}
|
|
27
|
-
import 'mocha';
|
|
28
26
|
const modules = findNodeJSMocha();
|
|
29
|
-
debug(
|
|
27
|
+
debug("modules length: %s", modules.length);
|
|
30
28
|
for (const module of modules) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
injectContext(module);
|
|
29
|
+
if (!module) continue;
|
|
30
|
+
injectContext(module);
|
|
34
31
|
}
|
|
35
|
-
|
|
32
|
+
|
|
33
|
+
//#endregion
|
|
34
|
+
export { };
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
import { MockAgent } from
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { MockAgent } from "./parallel/agent.js";
|
|
2
|
+
|
|
3
|
+
//#region src/lib/agent_handler.d.ts
|
|
4
|
+
declare function setupAgent(): Promise<MockAgent>;
|
|
5
|
+
declare function closeAgent(): Promise<void>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { closeAgent, setupAgent };
|
|
@@ -1,24 +1,26 @@
|
|
|
1
|
-
import { debuglog } from 'node:util';
|
|
2
|
-
import { createAgent, MockAgent } from "./parallel/agent.js";
|
|
3
1
|
import { getEggOptions } from "./utils.js";
|
|
4
|
-
|
|
2
|
+
import { createAgent } from "./parallel/agent.js";
|
|
3
|
+
import { debuglog } from "node:util";
|
|
4
|
+
|
|
5
|
+
//#region src/lib/agent_handler.ts
|
|
6
|
+
const debug = debuglog("egg/mock/lib/agent_handler");
|
|
5
7
|
let agent;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
8
|
+
async function setupAgent() {
|
|
9
|
+
debug("setupAgent call, env.ENABLE_MOCHA_PARALLEL: %s, process.env.AUTO_AGENT: %s, agent: %s", process.env.ENABLE_MOCHA_PARALLEL, process.env.AUTO_AGENT, !!agent);
|
|
10
|
+
if (agent) {
|
|
11
|
+
await agent.ready();
|
|
12
|
+
return agent;
|
|
13
|
+
}
|
|
14
|
+
if (process.env.ENABLE_MOCHA_PARALLEL && process.env.AUTO_AGENT) {
|
|
15
|
+
agent = createAgent(getEggOptions());
|
|
16
|
+
await agent.ready();
|
|
17
|
+
}
|
|
18
|
+
return agent;
|
|
17
19
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
await agent.close();
|
|
22
|
-
}
|
|
20
|
+
async function closeAgent() {
|
|
21
|
+
debug("setupAgent call, agent: %s", !!agent);
|
|
22
|
+
if (agent) await agent.close();
|
|
23
23
|
}
|
|
24
|
-
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
export { closeAgent, setupAgent };
|