@eggjs/mock 7.0.0-beta.19 → 7.0.0-beta.20

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.
Files changed (78) hide show
  1. package/dist/agent-BKYkjoCx.js +111 -0
  2. package/dist/agent-CHCe8tnW.d.ts +24 -0
  3. package/dist/agent-DZ_fHoxJ.js +48 -0
  4. package/dist/agent_handler-DeUtoRVT.js +26 -0
  5. package/dist/app/extend/agent.d.ts +1 -1
  6. package/dist/app/extend/agent.js +3 -46
  7. package/dist/app/extend/application.d.ts +4 -174
  8. package/dist/app/extend/application.js +7 -383
  9. package/dist/app-6Bn3F5Uw.js +252 -0
  10. package/dist/app-CoypamK1.js +99 -0
  11. package/dist/app-l47a-gqT.d.ts +7 -0
  12. package/dist/app_handler-CkiK6fyC.js +55 -0
  13. package/dist/app_handler-Gp5J9X-v.d.ts +9 -0
  14. package/dist/application-BPpvw5dg.d.ts +175 -0
  15. package/dist/application-LrKwuOKn.js +385 -0
  16. package/dist/bootstrap.d.ts +9 -3
  17. package/dist/bootstrap.js +20 -3
  18. package/dist/cluster-CA_hr9eV.js +283 -0
  19. package/dist/cluster-RTfUwmUd.d.ts +126 -0
  20. package/dist/context-BIduDy1M.js +10 -0
  21. package/dist/format_options-LRnReKde.js +65 -0
  22. package/dist/index-BtBMDZg8.d.ts +78 -0
  23. package/dist/index.d.ts +10 -81
  24. package/dist/index.js +20 -45
  25. package/dist/inject_context-BxpcF-ds.js +106 -0
  26. package/dist/inject_mocha-BVf8v6El.js +38 -0
  27. package/dist/inject_mocha-Daf1Aj8M.d.ts +1 -0
  28. package/dist/inject_mocha.d.ts +1 -1
  29. package/dist/inject_mocha.js +21 -32
  30. package/dist/lib/agent_handler.d.ts +4 -1
  31. package/dist/lib/agent_handler.js +7 -24
  32. package/dist/lib/app.d.ts +5 -6
  33. package/dist/lib/app.js +12 -252
  34. package/dist/lib/app_handler.d.ts +5 -8
  35. package/dist/lib/app_handler.js +19 -54
  36. package/dist/lib/cluster.d.ts +5 -125
  37. package/dist/lib/cluster.js +5 -281
  38. package/dist/lib/context.js +1 -8
  39. package/dist/lib/format_options.d.ts +2 -2
  40. package/dist/lib/format_options.js +2 -63
  41. package/dist/lib/inject_context.js +20 -104
  42. package/dist/lib/mock_agent.js +1 -43
  43. package/dist/lib/mock_custom_loader.js +1 -33
  44. package/dist/lib/mock_http_server.js +1 -15
  45. package/dist/lib/mock_httpclient.d.ts +1 -39
  46. package/dist/lib/mock_httpclient.js +2 -108
  47. package/dist/lib/parallel/agent.d.ts +4 -23
  48. package/dist/lib/parallel/agent.js +6 -109
  49. package/dist/lib/parallel/app.d.ts +3 -2
  50. package/dist/lib/parallel/app.js +7 -97
  51. package/dist/lib/parallel/util.d.ts +1 -5
  52. package/dist/lib/parallel/util.js +2 -57
  53. package/dist/lib/restore.d.ts +1 -3
  54. package/dist/lib/restore.js +7 -14
  55. package/dist/lib/supertest.d.ts +1 -15
  56. package/dist/lib/supertest.js +3 -37
  57. package/dist/lib/types.d.ts +3 -76
  58. package/dist/lib/types.js +2 -0
  59. package/dist/lib/utils.js +1 -38
  60. package/dist/mock_agent-CxT7Q0_N.js +45 -0
  61. package/dist/mock_custom_loader-f_tHRojG.js +35 -0
  62. package/dist/mock_http_server-De0r07gr.js +17 -0
  63. package/dist/mock_httpclient-1EgQkMxi.d.ts +40 -0
  64. package/dist/mock_httpclient-B6UVI7GS.js +110 -0
  65. package/dist/register.d.ts +2 -0
  66. package/dist/register.js +22 -4
  67. package/dist/restore-BL0cE0KG.d.ts +4 -0
  68. package/dist/restore-CVQYXquh.js +16 -0
  69. package/dist/src-D22EjdGo.js +47 -0
  70. package/dist/supertest-BIds28yL.d.ts +16 -0
  71. package/dist/supertest-Cg412Los.js +39 -0
  72. package/dist/types-CPNMyF89.js +1 -0
  73. package/dist/types-CjZ-JeCo.d.ts +75 -0
  74. package/dist/util-1xYBaaoh.d.ts +6 -0
  75. package/dist/util-BpppqTXv.js +59 -0
  76. package/dist/utils-MhP_Krx1.js +40 -0
  77. package/package.json +6 -7
  78. package/dist/_virtual/rolldown_runtime.js +0 -7
@@ -1,110 +1,4 @@
1
- import { getMockAgent } from "./mock_agent.js";
2
- import { mm } from "mm";
3
- import { extend } from "@eggjs/extend2";
1
+ import "../mock_agent-CxT7Q0_N.js";
2
+ import { createMockHttpClient } from "../mock_httpclient-B6UVI7GS.js";
4
3
 
5
- //#region src/lib/mock_httpclient.ts
6
- function normalizeResult(result) {
7
- if (typeof result === "string") result = { data: result };
8
- if (!result.status) result.status = 200;
9
- result.data = result.data || "";
10
- if (Buffer.isBuffer(result.data)) {} else if (typeof result.data === "object") result.data = Buffer.from(JSON.stringify(result.data));
11
- else if (typeof result.data === "string") result.data = Buffer.from(result.data);
12
- else throw new Error("`mockResult.data` must be buffer, string or json");
13
- result.headers = result.headers ?? {};
14
- return result;
15
- }
16
- const MOCK_CONFIGS = Symbol("MOCK_CONFIGS");
17
- const MOCK_CONFIG_INDEX = Symbol("MOCK_CONFIG_INDEX");
18
- function createMockHttpClient(app) {
19
- /**
20
- * mock httpclient
21
- * @function mockHttpclient
22
- * @param {String} mockUrl - url
23
- * @param {String|Array} mockMethod - http method, default is '*'
24
- * @param {Object|Function} mockResult - you data
25
- * - data - buffer / string / json
26
- * - status - http status
27
- * - headers - response header
28
- * - delay - delay the associated reply by a set amount in ms.
29
- * - persist - any matching request will always reply with the defined response indefinitely, default is true
30
- * - repeats - number, any matching request will reply with the defined response a fixed amount of times
31
- */
32
- return function mockHttpClient(mockUrl, mockMethod, mockResult) {
33
- let mockMethods = mockMethod;
34
- if (!mockResult) {
35
- mockResult = mockMethod;
36
- mockMethods = ["*"];
37
- }
38
- if (!Array.isArray(mockMethods)) mockMethods = [mockMethods];
39
- mockMethods = mockMethods.map((method) => (method || "GET").toUpperCase());
40
- let mockConfigs = app[MOCK_CONFIGS];
41
- if (!mockConfigs) {
42
- mockConfigs = [];
43
- mm(app, MOCK_CONFIGS, mockConfigs);
44
- }
45
- let mockConfigIndex = -1;
46
- let origin = mockUrl;
47
- let originMethod;
48
- const pathname = mockUrl;
49
- let pathMethod;
50
- if (typeof mockUrl === "string") {
51
- const urlObject = new URL(mockUrl);
52
- origin = urlObject.origin;
53
- const originalPathname = urlObject.pathname;
54
- pathMethod = (path) => {
55
- if (path === originalPathname) return true;
56
- if (path.includes("?")) return path.startsWith(originalPathname);
57
- return false;
58
- };
59
- } else if (mockUrl instanceof RegExp) {
60
- let requestOrigin = "";
61
- originMethod = (value) => {
62
- requestOrigin = value;
63
- return true;
64
- };
65
- pathMethod = (path) => {
66
- for (const config of mockConfigs) if (config.mockUrl.test(`${requestOrigin}${path}`)) {
67
- mm(app, MOCK_CONFIG_INDEX, config.mockConfigIndex);
68
- return true;
69
- }
70
- return false;
71
- };
72
- mockConfigIndex = mockConfigs.length;
73
- mockConfigs.push({
74
- mockUrl,
75
- mockResult,
76
- mockConfigIndex
77
- });
78
- }
79
- const mockPool = originMethod ? getMockAgent(app).get(originMethod) : getMockAgent(app).get(originMethod ?? origin);
80
- let persist = true;
81
- if (typeof mockResult === "object" && typeof mockResult.persist === "boolean") persist = mockResult.persist;
82
- mockMethods.forEach(function(method) {
83
- const mockScope = mockPool.intercept({
84
- path: pathMethod ?? pathname,
85
- method: method === "*" ? () => true : method
86
- }).reply((options) => {
87
- const requestUrl = `${options.origin}${options.path}`;
88
- let mockRequestResult;
89
- if (mockConfigIndex >= 0) {
90
- mockResult = mockConfigs[app[MOCK_CONFIG_INDEX]].mockResult;
91
- mockRequestResult = typeof mockResult === "function" ? mockResult(requestUrl, options) : mockResult;
92
- } else mockRequestResult = typeof mockResult === "function" ? mockResult(requestUrl, options) : mockResult;
93
- const result = extend(true, {}, normalizeResult(mockRequestResult));
94
- return {
95
- statusCode: result.status,
96
- data: result.data,
97
- responseOptions: { headers: result.headers }
98
- };
99
- });
100
- if (typeof mockResult === "object") {
101
- if (mockResult.delay && mockResult.delay > 0) mockScope.delay(mockResult.delay);
102
- }
103
- if (persist) mockScope.persist();
104
- else if (typeof mockResult === "object" && mockResult.repeats && mockResult.repeats > 0) mockScope.times(mockResult.repeats);
105
- });
106
- };
107
- }
108
-
109
- //#endregion
110
4
  export { createMockHttpClient };
@@ -1,24 +1,5 @@
1
- import { MockApplicationOptions, MockOptions } from "../types.js";
2
- import { APP_INIT } from "./util.js";
3
- import { Agent } from "egg";
4
- import { Base } from "sdk-base";
5
-
6
- //#region src/lib/parallel/agent.d.ts
7
- declare class MockAgent extends Base {
8
- #private;
9
- options: MockApplicationOptions;
10
- baseDir: string;
11
- [APP_INIT]: boolean;
12
- _instance: Agent;
13
- constructor(options: MockApplicationOptions);
14
- _init(): Promise<void>;
15
- on(...args: any[]): this;
16
- once(...args: any[]): this;
17
- /**
18
- * close agent
19
- */
20
- _close(): Promise<void>;
21
- }
22
- declare function createAgent(options: MockOptions): MockAgent;
23
- //#endregion
1
+ import "../../mock_httpclient-1EgQkMxi.js";
2
+ import "../../types-CjZ-JeCo.js";
3
+ import "../../util-1xYBaaoh.js";
4
+ import { MockAgent, createAgent } from "../../agent-CHCe8tnW.js";
24
5
  export { MockAgent, createAgent };
@@ -1,111 +1,8 @@
1
- import { rimraf, sleep } from "../utils.js";
2
- import { formatOptions } from "../format_options.js";
3
- import { context } from "../context.js";
4
- import { setCustomLoader } from "../mock_custom_loader.js";
5
- import { APP_INIT } from "./util.js";
6
- import path from "node:path";
7
- import { debuglog } from "node:util";
8
- import { importModule } from "@eggjs/utils";
9
- import { Base } from "sdk-base";
10
- import { detectPort } from "detect-port";
1
+ import "../../utils-MhP_Krx1.js";
2
+ import "../../format_options-LRnReKde.js";
3
+ import "../../context-BIduDy1M.js";
4
+ import "../../mock_custom_loader-f_tHRojG.js";
5
+ import "../../util-BpppqTXv.js";
6
+ import { MockAgent, createAgent } from "../../agent-BKYkjoCx.js";
11
7
 
12
- //#region src/lib/parallel/agent.ts
13
- const debug = debuglog("egg/mock/lib/parallel/agent");
14
- var MockAgent = class extends Base {
15
- baseDir;
16
- [APP_INIT] = false;
17
- #initOnListeners = /* @__PURE__ */ new Set();
18
- #initOnceListeners = /* @__PURE__ */ new Set();
19
- _instance;
20
- constructor(options) {
21
- super({ initMethod: "_init" });
22
- this.options = options;
23
- this.baseDir = this.options.baseDir;
24
- }
25
- async _init() {
26
- if (this.options.beforeInit) {
27
- await this.options.beforeInit(this);
28
- delete this.options.beforeInit;
29
- }
30
- if (this.options.clean !== false) {
31
- const logDir = path.join(this.options.baseDir, "logs");
32
- try {
33
- await rimraf(logDir);
34
- } catch (err) {
35
- console.error(`remove log dir ${logDir} failed: ${err.stack}`);
36
- }
37
- const runDir = path.join(this.options.baseDir, "run");
38
- try {
39
- await rimraf(runDir);
40
- } catch (err) {
41
- console.error(`remove run dir ${runDir} failed: ${err.stack}`);
42
- }
43
- }
44
- this.options.clusterPort = await detectPort();
45
- process.env.CLUSTER_PORT = String(this.options.clusterPort);
46
- debug("get clusterPort %s", this.options.clusterPort);
47
- const { Agent } = await importModule(this.options.framework);
48
- const agent = this._instance = new Agent({ ...this.options });
49
- Object.assign(agent.context, context);
50
- setCustomLoader(agent);
51
- debug("agent instantiate");
52
- this[APP_INIT] = true;
53
- debug("this[APP_INIT] = true");
54
- this.#bindEvents();
55
- await agent.ready();
56
- const msg = {
57
- action: "egg-ready",
58
- data: this.options
59
- };
60
- agent.messenger.onMessage(msg);
61
- debug("agent ready");
62
- }
63
- #bindEvents() {
64
- debug("bind cache events to agent");
65
- for (const args of this.#initOnListeners) {
66
- debug("on(%s), use cache and pass to agent", args);
67
- this._instance.on(args[0], args[1]);
68
- this.removeListener(args[0], args[1]);
69
- }
70
- for (const args of this.#initOnceListeners) {
71
- debug("once(%s), use cache and pass to agent", args);
72
- this._instance.once(args[0], args[1]);
73
- this.removeListener(args[0], args[1]);
74
- }
75
- }
76
- on(...args) {
77
- if (this[APP_INIT]) {
78
- debug("on(%s), pass to agent", args);
79
- this._instance.on(args[0], args[1]);
80
- } else {
81
- debug("on(%s), cache it because agent has not init", args);
82
- this.#initOnListeners.add(args);
83
- super.on(args[0], args[1]);
84
- }
85
- return this;
86
- }
87
- once(...args) {
88
- if (this[APP_INIT]) {
89
- debug("once(%s), pass to agent", args);
90
- this._instance.once(args[0], args[1]);
91
- } else {
92
- debug("once(%s), cache it because agent has not init", args);
93
- this.#initOnceListeners.add(args);
94
- super.on(args[0], args[1]);
95
- }
96
- return this;
97
- }
98
- /**
99
- * close agent
100
- */
101
- async _close() {
102
- if (this._instance) await this._instance.close();
103
- else await sleep(200);
104
- }
105
- };
106
- function createAgent(options) {
107
- return new MockAgent(formatOptions(options));
108
- }
109
-
110
- //#endregion
111
8
  export { MockAgent, createAgent };
@@ -1,5 +1,6 @@
1
- import { MockApplicationOptions, MockOptions } from "../types.js";
2
- import { APP_INIT } from "./util.js";
1
+ import "../../mock_httpclient-1EgQkMxi.js";
2
+ import { MockApplicationOptions, MockOptions } from "../../types-CjZ-JeCo.js";
3
+ import { APP_INIT } from "../../util-1xYBaaoh.js";
3
4
  import { Application } from "egg";
4
5
  import { Base } from "sdk-base";
5
6
 
@@ -1,99 +1,9 @@
1
- import { createServer } from "../mock_http_server.js";
2
- import { sleep } from "../utils.js";
3
- import { formatOptions } from "../format_options.js";
4
- import { context } from "../context.js";
5
- import { setCustomLoader } from "../mock_custom_loader.js";
6
- import { APP_INIT, proxyApp } from "./util.js";
7
- import { Application } from "egg";
8
- import { debuglog } from "node:util";
9
- import { importModule } from "@eggjs/utils";
10
- import { Base } from "sdk-base";
1
+ import "../../mock_http_server-De0r07gr.js";
2
+ import "../../utils-MhP_Krx1.js";
3
+ import "../../format_options-LRnReKde.js";
4
+ import "../../context-BIduDy1M.js";
5
+ import "../../mock_custom_loader-f_tHRojG.js";
6
+ import "../../util-BpppqTXv.js";
7
+ import { MockParallelApplication, createApp } from "../../app-CoypamK1.js";
11
8
 
12
- //#region src/lib/parallel/app.ts
13
- const debug = debuglog("egg/mock/lib/parallel/app");
14
- var MockParallelApplication = class extends Base {
15
- baseDir;
16
- [APP_INIT] = false;
17
- #initOnListeners = /* @__PURE__ */ new Set();
18
- #initOnceListeners = /* @__PURE__ */ new Set();
19
- _instance;
20
- constructor(options) {
21
- super({ initMethod: "_init" });
22
- this.options = options;
23
- this.baseDir = options.baseDir;
24
- }
25
- async _init() {
26
- if (this.options.beforeInit) {
27
- await this.options.beforeInit(this);
28
- delete this.options.beforeInit;
29
- }
30
- if (!this.options.clusterPort) this.options.clusterPort = parseInt(process.env.CLUSTER_PORT);
31
- if (!this.options.clusterPort) throw new Error("cannot get env.CLUSTER_PORT, parallel run fail");
32
- debug("get clusterPort %s", this.options.clusterPort);
33
- const { Application: Application$1 } = await importModule(this.options.framework);
34
- const app = this._instance = new Application$1({ ...this.options });
35
- Object.assign(app.context, context);
36
- setCustomLoader(app);
37
- debug("app instantiate");
38
- this[APP_INIT] = true;
39
- debug("this[APP_INIT] = true");
40
- this.#bindEvents();
41
- debug("http server instantiate");
42
- createServer(app);
43
- await app.ready();
44
- const msg = {
45
- action: "egg-ready",
46
- data: this.options
47
- };
48
- app.messenger.onMessage(msg);
49
- debug("app ready");
50
- }
51
- #bindEvents() {
52
- for (const args of this.#initOnListeners) {
53
- debug("on(%s), use cache and pass to app", args);
54
- this._instance.on(args[0], args[1]);
55
- this.removeListener(args[0], args[1]);
56
- }
57
- for (const args of this.#initOnceListeners) {
58
- debug("once(%s), use cache and pass to app", args);
59
- this._instance.once(args[0], args[1]);
60
- this.removeListener(args[0], args[1]);
61
- }
62
- }
63
- on(...args) {
64
- if (this[APP_INIT]) {
65
- debug("on(%s), pass to app", args);
66
- this._instance.on(args[0], args[1]);
67
- } else {
68
- debug("on(%s), cache it because app has not init", args);
69
- if (this.#initOnListeners) this.#initOnListeners.add(args);
70
- super.on(args[0], args[1]);
71
- }
72
- return this;
73
- }
74
- once(...args) {
75
- if (this[APP_INIT]) {
76
- debug("once(%s), pass to app", args);
77
- this._instance.once(args[0], args[1]);
78
- } else {
79
- debug("once(%s), cache it because app has not init", args);
80
- if (this.#initOnceListeners) this.#initOnceListeners.add(args);
81
- super.on(args[0], args[1]);
82
- }
83
- return this;
84
- }
85
- /**
86
- * close app
87
- */
88
- async _close() {
89
- if (this._instance) await this._instance.close();
90
- else await sleep(200);
91
- }
92
- };
93
- function createApp(initOptions) {
94
- const app = new MockParallelApplication(formatOptions(initOptions));
95
- return proxyApp(app);
96
- }
97
-
98
- //#endregion
99
9
  export { MockParallelApplication, createApp };
@@ -1,6 +1,2 @@
1
- //#region src/lib/parallel/util.d.ts
2
- declare const MOCK_APP_METHOD: string[];
3
- declare const APP_INIT: unique symbol;
4
- declare function proxyApp(app: any): any;
5
- //#endregion
1
+ import { APP_INIT, MOCK_APP_METHOD, proxyApp } from "../../util-1xYBaaoh.js";
6
2
  export { APP_INIT, MOCK_APP_METHOD, proxyApp };
@@ -1,59 +1,4 @@
1
- import { getProperty } from "../utils.js";
2
- import { debuglog } from "node:util";
1
+ import "../../utils-MhP_Krx1.js";
2
+ import { APP_INIT, MOCK_APP_METHOD, proxyApp } from "../../util-BpppqTXv.js";
3
3
 
4
- //#region src/lib/parallel/util.ts
5
- const debug = debuglog("egg/mock/lib/parallel/util");
6
- const MOCK_APP_METHOD = [
7
- "ready",
8
- "isClosed",
9
- "closed",
10
- "close",
11
- "on",
12
- "once"
13
- ];
14
- const APP_INIT = Symbol("appInit");
15
- function proxyApp(app) {
16
- return new Proxy(app, {
17
- get(target, prop) {
18
- if (MOCK_APP_METHOD.includes(prop)) return getProperty(target, prop);
19
- if (!target[APP_INIT]) throw new Error(`can't get ${prop} before ready`);
20
- debug("proxy handler.get %s", prop);
21
- return target._instance[prop];
22
- },
23
- set(target, prop, value) {
24
- if (MOCK_APP_METHOD.includes(prop)) return true;
25
- if (!target[APP_INIT]) throw new Error(`can't set ${prop} before ready`);
26
- debug("proxy handler.set %s", prop);
27
- target._instance[prop] = value;
28
- return true;
29
- },
30
- defineProperty(target, prop, descriptor) {
31
- if (MOCK_APP_METHOD.includes(prop)) return true;
32
- if (!target[APP_INIT]) throw new Error(`can't defineProperty ${prop} before ready`);
33
- debug("proxy handler.defineProperty %s", prop);
34
- Object.defineProperty(target._instance, prop, descriptor);
35
- return true;
36
- },
37
- deleteProperty(target, prop) {
38
- if (MOCK_APP_METHOD.includes(prop)) return true;
39
- if (!target[APP_INIT]) throw new Error(`can't delete ${prop} before ready`);
40
- debug("proxy handler.deleteProperty %s", prop);
41
- delete target._instance[prop];
42
- return true;
43
- },
44
- getOwnPropertyDescriptor(target, prop) {
45
- if (MOCK_APP_METHOD.includes(prop)) return Object.getOwnPropertyDescriptor(target, prop);
46
- if (!target[APP_INIT]) throw new Error(`can't getOwnPropertyDescriptor ${prop} before ready`);
47
- debug("proxy handler.getOwnPropertyDescriptor %s", prop);
48
- return Object.getOwnPropertyDescriptor(target._instance, prop);
49
- },
50
- getPrototypeOf(target) {
51
- if (!target[APP_INIT]) throw new Error("can't getPrototypeOf before ready");
52
- debug("proxy handler.getPrototypeOf %s");
53
- return Object.getPrototypeOf(target._instance);
54
- }
55
- });
56
- }
57
-
58
- //#endregion
59
4
  export { APP_INIT, MOCK_APP_METHOD, proxyApp };
@@ -1,4 +1,2 @@
1
- //#region src/lib/restore.d.ts
2
- declare function restore(): Promise<void>;
3
- //#endregion
1
+ import { restore } from "../restore-BL0cE0KG.js";
4
2
  export { restore };
@@ -1,16 +1,9 @@
1
- import { restore as restore$2 } from "./cluster.js";
2
- import { restoreMockAgent } from "./mock_agent.js";
3
- import { restore as restore$1 } from "mm";
4
- import { debuglog } from "node:util";
1
+ import "../mock_http_server-De0r07gr.js";
2
+ import "../utils-MhP_Krx1.js";
3
+ import "../supertest-Cg412Los.js";
4
+ import "../format_options-LRnReKde.js";
5
+ import "../cluster-CA_hr9eV.js";
6
+ import "../mock_agent-CxT7Q0_N.js";
7
+ import { restore } from "../restore-CVQYXquh.js";
5
8
 
6
- //#region src/lib/restore.ts
7
- const debug = debuglog("egg/mock/lib/restore");
8
- async function restore() {
9
- restore$1();
10
- await restore$2();
11
- await restoreMockAgent();
12
- debug("restore all");
13
- }
14
-
15
- //#endregion
16
9
  export { restore };
@@ -1,16 +1,2 @@
1
- import { Request, Test } from "@eggjs/supertest";
2
-
3
- //#region src/lib/supertest.d.ts
4
-
5
- /**
6
- * Test against the given `app`,
7
- * returning a new `Test`.
8
- */
9
- declare class EggTestRequest extends Request {
10
- #private;
11
- constructor(app: any);
12
- protected _testRequest(method: string, url: string): Test;
13
- }
14
- declare function request(app: any): EggTestRequest;
15
- //#endregion
1
+ import { EggTestRequest, request } from "../supertest-BIds28yL.js";
16
2
  export { EggTestRequest, request };
@@ -1,39 +1,5 @@
1
- import { createServer } from "./mock_http_server.js";
2
- import { getSourceDirname } from "./utils.js";
3
- import path from "node:path";
4
- import { readJSONSync } from "utility";
5
- import { Request, Test } from "@eggjs/supertest";
1
+ import "../mock_http_server-De0r07gr.js";
2
+ import "../utils-MhP_Krx1.js";
3
+ import { EggTestRequest, request } from "../supertest-Cg412Los.js";
6
4
 
7
- //#region src/lib/supertest.ts
8
- let pkgVersion = "";
9
- /**
10
- * Test against the given `app`,
11
- * returning a new `Test`.
12
- */
13
- var EggTestRequest = class extends Request {
14
- #app;
15
- constructor(app) {
16
- super(createServer(app));
17
- this.#app = app;
18
- }
19
- _testRequest(method, url) {
20
- if (url[0] !== "/") {
21
- const realUrl = this.#app.router.pathFor(url);
22
- if (!realUrl) throw new Error(`Can't find router:${url}, please check your 'app/router.js'`);
23
- url = realUrl;
24
- }
25
- const test = super._testRequest(method, url);
26
- if (!pkgVersion) {
27
- const pkgFile = path.join(getSourceDirname(), "../package.json");
28
- pkgVersion = readJSONSync(pkgFile).version;
29
- }
30
- test.set("User-Agent", `@eggjs/mock/${pkgVersion} Node.js/${process.version}`);
31
- return test;
32
- }
33
- };
34
- function request(app) {
35
- return new EggTestRequest(app);
36
- }
37
-
38
- //#endregion
39
5
  export { EggTestRequest, request };
@@ -1,76 +1,3 @@
1
- import { MockHttpClientMethod, MockResponseCallbackOptions, MockResultFunction, MockResultOptions, ResultObject } from "./mock_httpclient.js";
2
- import { MockAgent } from "urllib";
3
-
4
- //#region src/lib/types.d.ts
5
- interface MockOptions {
6
- /**
7
- * The mode of the application
8
- */
9
- mode?: 'all-in-one-process' | 'cluster' | 'single';
10
- /**
11
- * The directory of the application
12
- */
13
- baseDir?: string;
14
- /**
15
- * Custom you plugins
16
- */
17
- plugins?: any;
18
- /**
19
- * The directory of the egg framework
20
- *
21
- * Set to `true` to use the current directory as framework directory
22
- */
23
- framework?: string | boolean;
24
- /**
25
- * current test on plugin
26
- */
27
- plugin?: boolean;
28
- /**
29
- * @deprecated please use `framework` instead
30
- */
31
- customEgg?: string | boolean;
32
- /**
33
- * Cache application based on baseDir
34
- */
35
- cache?: boolean;
36
- /**
37
- * Switch on process coverage, but it'll be slower
38
- */
39
- coverage?: boolean;
40
- /**
41
- * Remove $baseDir/logs and $baseDir/run before start, default is `true`
42
- */
43
- clean?: boolean;
44
- /**
45
- * default options.mockCtxStorage value on each mockContext
46
- */
47
- mockCtxStorage?: boolean;
48
- beforeInit?: (app: any) => Promise<void>;
49
- }
50
- interface MockClusterOptions extends MockOptions {
51
- workers?: number | string;
52
- cache?: boolean;
53
- port?: number;
54
- /**
55
- * opt pass to coffee, such as { execArgv: ['--debug'] }
56
- */
57
- opt?: object;
58
- startMode?: 'process' | 'worker_threads';
59
- }
60
- /**
61
- * @deprecated please use MockOptions instead
62
- * keep this for compatible
63
- */
64
- type MockOption = MockOptions;
65
- interface MockApplicationOptions extends MockOptions {
66
- baseDir: string;
67
- framework: string;
68
- clusterPort?: number;
69
- }
70
- interface MockClusterApplicationOptions extends MockClusterOptions {
71
- baseDir: string;
72
- framework: string;
73
- port: number;
74
- }
75
- //#endregion
76
- export { type MockAgent, MockApplicationOptions, MockClusterApplicationOptions, MockClusterOptions, type MockHttpClientMethod, MockOption, MockOptions, type MockResponseCallbackOptions, type MockResultFunction, type MockResultOptions, type ResultObject };
1
+ import { MockHttpClientMethod, MockResponseCallbackOptions, MockResultFunction, MockResultOptions, ResultObject } from "../mock_httpclient-1EgQkMxi.js";
2
+ import { MockAgent, MockApplicationOptions, MockClusterApplicationOptions, MockClusterOptions, MockOption, MockOptions } from "../types-CjZ-JeCo.js";
3
+ export { MockAgent, MockApplicationOptions, MockClusterApplicationOptions, MockClusterOptions, MockHttpClientMethod, MockOption, MockOptions, MockResponseCallbackOptions, MockResultFunction, MockResultOptions, ResultObject };
package/dist/lib/types.js CHANGED
@@ -1 +1,3 @@
1
+ import "../types-CPNMyF89.js";
2
+
1
3
  export { };
package/dist/lib/utils.js CHANGED
@@ -1,40 +1,3 @@
1
- import path from "node:path";
2
- import { rmSync } from "node:fs";
3
- import { rm } from "node:fs/promises";
4
- import { fileURLToPath } from "node:url";
5
- import { scheduler } from "node:timers/promises";
1
+ import { getEggOptions, getProperty, getSourceDirname, rimraf, rimrafSync, sleep } from "../utils-MhP_Krx1.js";
6
2
 
7
- //#region src/lib/utils.ts
8
- function getSourceDirname() {
9
- if (typeof __dirname !== "undefined") return path.dirname(__dirname);
10
- return path.dirname(path.dirname(fileURLToPath(import.meta.url)));
11
- }
12
- async function sleep(delay) {
13
- await scheduler.wait(delay);
14
- }
15
- async function rimraf(filepath) {
16
- await rm(filepath, {
17
- force: true,
18
- recursive: true
19
- });
20
- }
21
- function rimrafSync(filepath) {
22
- rmSync(filepath, {
23
- force: true,
24
- recursive: true
25
- });
26
- }
27
- function getProperty(target, prop) {
28
- const member = target[prop];
29
- if (typeof member === "function") return member.bind(target);
30
- return member;
31
- }
32
- function getEggOptions() {
33
- return {
34
- baseDir: process.env.EGG_BASE_DIR ?? process.cwd(),
35
- framework: process.env.EGG_FRAMEWORK
36
- };
37
- }
38
-
39
- //#endregion
40
3
  export { getEggOptions, getProperty, getSourceDirname, rimraf, rimrafSync, sleep };