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

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 (96) hide show
  1. package/dist/app/extend/agent.d.ts +33 -38
  2. package/dist/app/extend/agent.js +46 -5
  3. package/dist/app/extend/application.d.ts +171 -5
  4. package/dist/app/extend/application.js +445 -9
  5. package/dist/app/middleware/cluster_app_mock.d.ts +2 -5
  6. package/dist/app/middleware/cluster_app_mock.js +99 -96
  7. package/dist/app.d.ts +5 -9
  8. package/dist/app.js +18 -17
  9. package/dist/bootstrap.d.ts +5 -15
  10. package/dist/bootstrap.js +13 -29
  11. package/dist/index.d.ts +77 -10
  12. package/dist/index.js +90 -22
  13. package/dist/inject_mocha.d.ts +1 -1
  14. package/dist/inject_mocha.js +35 -23
  15. package/dist/lib/agent_handler.d.ts +3 -10
  16. package/dist/lib/agent_handler.js +24 -9
  17. package/dist/lib/app.d.ts +3 -6
  18. package/dist/lib/app.js +291 -14
  19. package/dist/lib/app_handler.d.ts +5 -6
  20. package/dist/lib/app_handler.js +69 -21
  21. package/dist/lib/cluster.d.ts +121 -6
  22. package/dist/lib/cluster.js +340 -7
  23. package/dist/lib/context.d.ts +1 -4
  24. package/dist/lib/context.js +11 -3
  25. package/dist/lib/format_options.d.ts +2 -7
  26. package/dist/lib/format_options.js +93 -4
  27. package/dist/lib/inject_context.d.ts +1 -4
  28. package/dist/lib/inject_context.js +126 -22
  29. package/dist/lib/mock_agent.d.ts +4 -8
  30. package/dist/lib/mock_agent.js +45 -3
  31. package/dist/lib/mock_custom_loader.d.ts +1 -4
  32. package/dist/lib/mock_custom_loader.js +34 -3
  33. package/dist/lib/mock_http_server.d.ts +2 -6
  34. package/dist/lib/mock_http_server.js +18 -3
  35. package/dist/lib/mock_httpclient.d.ts +36 -2
  36. package/dist/lib/mock_httpclient.js +146 -4
  37. package/dist/lib/parallel/agent.d.ts +20 -5
  38. package/dist/lib/parallel/agent.js +117 -8
  39. package/dist/lib/parallel/app.d.ts +19 -24
  40. package/dist/lib/parallel/app.js +111 -9
  41. package/dist/lib/parallel/util.d.ts +3 -2
  42. package/dist/lib/parallel/util.js +66 -4
  43. package/dist/lib/prerequire.d.ts +1 -1
  44. package/dist/lib/prerequire.js +25 -1
  45. package/dist/lib/request_call_function.d.ts +1 -1
  46. package/dist/lib/request_call_function.js +47 -34
  47. package/dist/lib/restore.d.ts +1 -2
  48. package/dist/lib/restore.js +13 -9
  49. package/dist/lib/start-cluster.d.ts +2 -1
  50. package/dist/lib/start-cluster.js +14 -15
  51. package/dist/lib/supertest.d.ts +11 -2
  52. package/dist/lib/supertest.js +40 -5
  53. package/dist/lib/tmp/empty.d.ts +1 -1
  54. package/dist/lib/tmp/empty.js +2 -1
  55. package/dist/lib/types.d.ts +72 -3
  56. package/dist/lib/types.js +2 -3
  57. package/dist/lib/utils.d.ts +8 -11
  58. package/dist/lib/utils.js +69 -3
  59. package/dist/register.d.ts +7 -11
  60. package/dist/register.js +41 -55
  61. package/package.json +7 -7
  62. package/dist/agent-BKYkjoCx.js +0 -111
  63. package/dist/agent-CHCe8tnW.d.ts +0 -24
  64. package/dist/agent-DZ_fHoxJ.js +0 -48
  65. package/dist/agent_handler-DeUtoRVT.js +0 -26
  66. package/dist/app-6Bn3F5Uw.js +0 -252
  67. package/dist/app-CoypamK1.js +0 -99
  68. package/dist/app-l47a-gqT.d.ts +0 -7
  69. package/dist/app_handler-CkiK6fyC.js +0 -55
  70. package/dist/app_handler-Gp5J9X-v.d.ts +0 -9
  71. package/dist/application-BPpvw5dg.d.ts +0 -175
  72. package/dist/application-LrKwuOKn.js +0 -385
  73. package/dist/cluster-CA_hr9eV.js +0 -283
  74. package/dist/cluster-RTfUwmUd.d.ts +0 -126
  75. package/dist/context-BIduDy1M.js +0 -10
  76. package/dist/format_options-LRnReKde.js +0 -65
  77. package/dist/index-BtBMDZg8.d.ts +0 -78
  78. package/dist/inject_context-BxpcF-ds.js +0 -106
  79. package/dist/inject_mocha-BVf8v6El.js +0 -38
  80. package/dist/inject_mocha-Daf1Aj8M.d.ts +0 -1
  81. package/dist/mock_agent-CxT7Q0_N.js +0 -45
  82. package/dist/mock_custom_loader-f_tHRojG.js +0 -35
  83. package/dist/mock_http_server-De0r07gr.js +0 -17
  84. package/dist/mock_httpclient-1EgQkMxi.d.ts +0 -40
  85. package/dist/mock_httpclient-B6UVI7GS.js +0 -110
  86. package/dist/restore-BL0cE0KG.d.ts +0 -4
  87. package/dist/restore-CVQYXquh.js +0 -16
  88. package/dist/src-D22EjdGo.js +0 -47
  89. package/dist/supertest-BIds28yL.d.ts +0 -16
  90. package/dist/supertest-Cg412Los.js +0 -39
  91. package/dist/types-CPNMyF89.js +0 -1
  92. package/dist/types-CjZ-JeCo.d.ts +0 -75
  93. package/dist/typings/index.d.ts +0 -1
  94. package/dist/util-1xYBaaoh.d.ts +0 -6
  95. package/dist/util-BpppqTXv.js +0 -59
  96. package/dist/utils-MhP_Krx1.js +0 -40
@@ -1,16 +0,0 @@
1
- import { restore as restore$1 } from "./cluster-CA_hr9eV.js";
2
- import { restoreMockAgent } from "./mock_agent-CxT7Q0_N.js";
3
- import { restore } from "mm";
4
- import { debuglog } from "node:util";
5
-
6
- //#region src/lib/restore.ts
7
- const debug = debuglog("egg/mock/lib/restore");
8
- async function restore$2() {
9
- restore();
10
- await restore$1();
11
- await restoreMockAgent();
12
- debug("restore all");
13
- }
14
-
15
- //#endregion
16
- export { restore$2 as restore };
@@ -1,47 +0,0 @@
1
- import { createCluster } from "./cluster-CA_hr9eV.js";
2
- import { createApp } from "./app-6Bn3F5Uw.js";
3
- import { restore as restore$1 } from "./restore-CVQYXquh.js";
4
- import { setGetAppCallback } from "./app_handler-CkiK6fyC.js";
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
25
- };
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
- }
33
- });
34
- var src_default = proxyMock;
35
- process.setMaxListeners(100);
36
- process.once("SIGQUIT", () => {
37
- process.exit(0);
38
- });
39
- process.once("SIGTERM", () => {
40
- process.exit(0);
41
- });
42
- process.once("SIGINT", () => {
43
- process.exit(0);
44
- });
45
-
46
- //#endregion
47
- export { proxyMock, src_default };
@@ -1,16 +0,0 @@
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
16
- export { EggTestRequest, request };
@@ -1,39 +0,0 @@
1
- import { createServer } from "./mock_http_server-De0r07gr.js";
2
- import { getSourceDirname } from "./utils-MhP_Krx1.js";
3
- import path from "node:path";
4
- import { readJSONSync } from "utility";
5
- import { Request, Test } from "@eggjs/supertest";
6
-
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
- export { EggTestRequest, request };
@@ -1 +0,0 @@
1
- export { };
@@ -1,75 +0,0 @@
1
- import { MockAgent as MockAgent$1 } from "urllib";
2
-
3
- //#region src/lib/types.d.ts
4
- interface MockOptions {
5
- /**
6
- * The mode of the application
7
- */
8
- mode?: 'all-in-one-process' | 'cluster' | 'single';
9
- /**
10
- * The directory of the application
11
- */
12
- baseDir?: string;
13
- /**
14
- * Custom you plugins
15
- */
16
- plugins?: any;
17
- /**
18
- * The directory of the egg framework
19
- *
20
- * Set to `true` to use the current directory as framework directory
21
- */
22
- framework?: string | boolean;
23
- /**
24
- * current test on plugin
25
- */
26
- plugin?: boolean;
27
- /**
28
- * @deprecated please use `framework` instead
29
- */
30
- customEgg?: string | boolean;
31
- /**
32
- * Cache application based on baseDir
33
- */
34
- cache?: boolean;
35
- /**
36
- * Switch on process coverage, but it'll be slower
37
- */
38
- coverage?: boolean;
39
- /**
40
- * Remove $baseDir/logs and $baseDir/run before start, default is `true`
41
- */
42
- clean?: boolean;
43
- /**
44
- * default options.mockCtxStorage value on each mockContext
45
- */
46
- mockCtxStorage?: boolean;
47
- beforeInit?: (app: any) => Promise<void>;
48
- }
49
- interface MockClusterOptions extends MockOptions {
50
- workers?: number | string;
51
- cache?: boolean;
52
- port?: number;
53
- /**
54
- * opt pass to coffee, such as { execArgv: ['--debug'] }
55
- */
56
- opt?: object;
57
- startMode?: 'process' | 'worker_threads';
58
- }
59
- /**
60
- * @deprecated please use MockOptions instead
61
- * keep this for compatible
62
- */
63
- type MockOption = MockOptions;
64
- interface MockApplicationOptions extends MockOptions {
65
- baseDir: string;
66
- framework: string;
67
- clusterPort?: number;
68
- }
69
- interface MockClusterApplicationOptions extends MockClusterOptions {
70
- baseDir: string;
71
- framework: string;
72
- port: number;
73
- }
74
- //#endregion
75
- export { type MockAgent$1 as MockAgent, MockApplicationOptions, MockClusterApplicationOptions, MockClusterOptions, MockOption, MockOptions };
@@ -1 +0,0 @@
1
- import "egg";
@@ -1,6 +0,0 @@
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
6
- export { APP_INIT, MOCK_APP_METHOD, proxyApp };
@@ -1,59 +0,0 @@
1
- import { getProperty } from "./utils-MhP_Krx1.js";
2
- import { debuglog } from "node:util";
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
- export { APP_INIT, MOCK_APP_METHOD, proxyApp };
@@ -1,40 +0,0 @@
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";
6
-
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
- export { getEggOptions, getProperty, getSourceDirname, rimraf, rimrafSync, sleep };