@eggjs/mock 6.0.7 → 6.1.0-beta.3
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/README.md +35 -56
- package/README.zh_CN.md +30 -50
- package/dist/_virtual/rolldown_runtime.js +7 -0
- package/dist/app/extend/agent.d.ts +39 -0
- package/dist/app/extend/agent.js +48 -0
- package/dist/app/extend/application.d.ts +176 -0
- package/dist/app/extend/application.js +385 -0
- package/dist/app/middleware/cluster_app_mock.d.ts +6 -0
- package/dist/app/middleware/cluster_app_mock.js +97 -0
- package/dist/app.d.ts +10 -0
- package/dist/app.js +17 -0
- package/dist/bootstrap.d.ts +9 -0
- package/dist/bootstrap.js +14 -0
- package/dist/index.d.ts +81 -0
- package/dist/index.js +48 -0
- package/dist/lib/agent_handler.d.ts +7 -0
- package/dist/lib/agent_handler.js +26 -0
- package/dist/lib/app.d.ts +7 -0
- package/dist/lib/app.js +251 -0
- package/dist/lib/app_handler.d.ts +9 -0
- package/dist/lib/app_handler.js +56 -0
- package/dist/lib/cluster.d.ts +126 -0
- package/dist/lib/cluster.js +283 -0
- package/dist/lib/context.d.ts +4 -0
- package/dist/lib/context.js +13 -0
- package/dist/lib/format_options.d.ts +10 -0
- package/dist/lib/format_options.js +65 -0
- package/dist/lib/inject_context.d.ts +9 -0
- package/dist/lib/inject_context.js +106 -0
- package/dist/lib/mock_agent.d.ts +9 -0
- package/dist/lib/mock_agent.js +45 -0
- package/dist/lib/mock_custom_loader.d.ts +4 -0
- package/dist/lib/mock_custom_loader.js +35 -0
- package/dist/lib/mock_http_server.d.ts +6 -0
- package/dist/lib/mock_http_server.js +17 -0
- package/dist/lib/mock_httpclient.d.ts +40 -0
- package/dist/lib/mock_httpclient.js +110 -0
- package/dist/lib/parallel/agent.d.ts +24 -0
- package/dist/lib/parallel/agent.js +111 -0
- package/dist/lib/parallel/app.d.ts +24 -0
- package/dist/lib/parallel/app.js +98 -0
- package/dist/lib/parallel/util.d.ts +6 -0
- package/dist/lib/parallel/util.js +59 -0
- package/dist/lib/prerequire.d.ts +1 -0
- package/dist/lib/prerequire.js +1 -0
- package/dist/lib/request_call_function.d.ts +1 -0
- package/dist/lib/request_call_function.js +37 -0
- package/dist/lib/restore.d.ts +4 -0
- package/dist/lib/restore.js +16 -0
- package/dist/lib/start-cluster.d.ts +1 -0
- package/dist/lib/start-cluster.js +19 -0
- package/dist/lib/supertest.d.ts +16 -0
- package/dist/lib/supertest.js +39 -0
- package/dist/lib/tmp/empty.d.ts +1 -0
- package/dist/lib/tmp/empty.js +1 -0
- package/{src/lib/types.ts → dist/lib/types.d.ts} +12 -29
- package/dist/lib/types.js +1 -0
- package/dist/lib/utils.d.ts +12 -0
- package/dist/lib/utils.js +40 -0
- package/dist/register.d.ts +12 -0
- package/dist/register.js +65 -0
- package/dist/typings/index.d.ts +1 -0
- package/package.json +68 -100
- package/dist/commonjs/app/extend/agent.d.ts +0 -34
- package/dist/commonjs/app/extend/agent.js +0 -49
- package/dist/commonjs/app/extend/application.d.ts +0 -172
- package/dist/commonjs/app/extend/application.js +0 -450
- package/dist/commonjs/app/middleware/cluster_app_mock.d.ts +0 -3
- package/dist/commonjs/app/middleware/cluster_app_mock.js +0 -101
- package/dist/commonjs/app.d.ts +0 -6
- package/dist/commonjs/app.js +0 -20
- package/dist/commonjs/bootstrap.d.ts +0 -5
- package/dist/commonjs/bootstrap.js +0 -59
- package/dist/commonjs/index.d.ts +0 -77
- package/dist/commonjs/index.js +0 -114
- package/dist/commonjs/lib/agent_handler.d.ts +0 -3
- package/dist/commonjs/lib/agent_handler.js +0 -28
- package/dist/commonjs/lib/app.d.ts +0 -3
- package/dist/commonjs/lib/app.js +0 -301
- package/dist/commonjs/lib/app_handler.d.ts +0 -5
- package/dist/commonjs/lib/app_handler.js +0 -71
- package/dist/commonjs/lib/cluster.d.ts +0 -114
- package/dist/commonjs/lib/cluster.js +0 -337
- package/dist/commonjs/lib/context.d.ts +0 -1
- package/dist/commonjs/lib/context.js +0 -16
- package/dist/commonjs/lib/format_options.d.ts +0 -5
- package/dist/commonjs/lib/format_options.js +0 -100
- package/dist/commonjs/lib/inject_context.d.ts +0 -6
- package/dist/commonjs/lib/inject_context.js +0 -132
- package/dist/commonjs/lib/mock_agent.d.ts +0 -5
- package/dist/commonjs/lib/mock_agent.js +0 -49
- package/dist/commonjs/lib/mock_custom_loader.d.ts +0 -1
- package/dist/commonjs/lib/mock_custom_loader.js +0 -37
- package/dist/commonjs/lib/mock_http_server.d.ts +0 -2
- package/dist/commonjs/lib/mock_http_server.js +0 -24
- package/dist/commonjs/lib/mock_httpclient.d.ts +0 -36
- package/dist/commonjs/lib/mock_httpclient.js +0 -147
- package/dist/commonjs/lib/parallel/agent.d.ts +0 -20
- package/dist/commonjs/lib/parallel/agent.js +0 -125
- package/dist/commonjs/lib/parallel/app.d.ts +0 -20
- package/dist/commonjs/lib/parallel/app.js +0 -115
- package/dist/commonjs/lib/parallel/util.d.ts +0 -3
- package/dist/commonjs/lib/parallel/util.js +0 -77
- package/dist/commonjs/lib/prerequire.d.ts +0 -1
- package/dist/commonjs/lib/prerequire.js +0 -26
- package/dist/commonjs/lib/request_call_function.d.ts +0 -1
- package/dist/commonjs/lib/request_call_function.js +0 -52
- package/dist/commonjs/lib/restore.d.ts +0 -1
- package/dist/commonjs/lib/restore.js +0 -16
- package/dist/commonjs/lib/start-cluster.d.ts +0 -2
- package/dist/commonjs/lib/start-cluster.js +0 -23
- package/dist/commonjs/lib/supertest.d.ts +0 -11
- package/dist/commonjs/lib/supertest.js +0 -48
- package/dist/commonjs/lib/tmp/empty.d.ts +0 -1
- package/dist/commonjs/lib/tmp/empty.js +0 -3
- package/dist/commonjs/lib/types.d.ts +0 -68
- package/dist/commonjs/lib/types.js +0 -3
- package/dist/commonjs/lib/utils.d.ts +0 -9
- package/dist/commonjs/lib/utils.js +0 -80
- package/dist/commonjs/package.json +0 -3
- package/dist/commonjs/register.d.ts +0 -8
- package/dist/commonjs/register.js +0 -80
- package/dist/esm/app/extend/agent.d.ts +0 -34
- package/dist/esm/app/extend/agent.js +0 -46
- package/dist/esm/app/extend/application.d.ts +0 -172
- package/dist/esm/app/extend/application.js +0 -444
- package/dist/esm/app/middleware/cluster_app_mock.d.ts +0 -3
- package/dist/esm/app/middleware/cluster_app_mock.js +0 -99
- package/dist/esm/app.d.ts +0 -6
- package/dist/esm/app.js +0 -17
- package/dist/esm/bootstrap.d.ts +0 -5
- package/dist/esm/bootstrap.js +0 -15
- package/dist/esm/index.d.ts +0 -77
- package/dist/esm/index.js +0 -91
- package/dist/esm/lib/agent_handler.d.ts +0 -3
- package/dist/esm/lib/agent_handler.js +0 -24
- package/dist/esm/lib/app.d.ts +0 -3
- package/dist/esm/lib/app.js +0 -295
- package/dist/esm/lib/app_handler.d.ts +0 -5
- package/dist/esm/lib/app_handler.js +0 -65
- package/dist/esm/lib/cluster.d.ts +0 -114
- package/dist/esm/lib/cluster.js +0 -328
- package/dist/esm/lib/context.d.ts +0 -1
- package/dist/esm/lib/context.js +0 -13
- package/dist/esm/lib/format_options.d.ts +0 -5
- package/dist/esm/lib/format_options.js +0 -94
- package/dist/esm/lib/inject_context.d.ts +0 -6
- package/dist/esm/lib/inject_context.js +0 -126
- package/dist/esm/lib/mock_agent.d.ts +0 -5
- package/dist/esm/lib/mock_agent.js +0 -45
- package/dist/esm/lib/mock_custom_loader.d.ts +0 -1
- package/dist/esm/lib/mock_custom_loader.js +0 -34
- package/dist/esm/lib/mock_http_server.d.ts +0 -2
- package/dist/esm/lib/mock_http_server.js +0 -18
- package/dist/esm/lib/mock_httpclient.d.ts +0 -36
- package/dist/esm/lib/mock_httpclient.js +0 -144
- package/dist/esm/lib/parallel/agent.d.ts +0 -20
- package/dist/esm/lib/parallel/agent.js +0 -117
- package/dist/esm/lib/parallel/app.d.ts +0 -20
- package/dist/esm/lib/parallel/app.js +0 -110
- package/dist/esm/lib/parallel/util.d.ts +0 -3
- package/dist/esm/lib/parallel/util.js +0 -73
- package/dist/esm/lib/prerequire.d.ts +0 -1
- package/dist/esm/lib/prerequire.js +0 -25
- package/dist/esm/lib/request_call_function.d.ts +0 -1
- package/dist/esm/lib/request_call_function.js +0 -47
- package/dist/esm/lib/restore.d.ts +0 -1
- package/dist/esm/lib/restore.js +0 -13
- package/dist/esm/lib/start-cluster.d.ts +0 -2
- package/dist/esm/lib/start-cluster.js +0 -18
- package/dist/esm/lib/supertest.d.ts +0 -11
- package/dist/esm/lib/supertest.js +0 -40
- package/dist/esm/lib/tmp/empty.d.ts +0 -1
- package/dist/esm/lib/tmp/empty.js +0 -2
- package/dist/esm/lib/types.d.ts +0 -68
- package/dist/esm/lib/types.js +0 -2
- package/dist/esm/lib/utils.d.ts +0 -9
- package/dist/esm/lib/utils.js +0 -69
- package/dist/esm/package.json +0 -3
- package/dist/esm/register.d.ts +0 -8
- package/dist/esm/register.js +0 -75
- package/dist/package.json +0 -4
- package/src/app/extend/agent.ts +0 -57
- package/src/app/extend/application.ts +0 -512
- package/src/app/middleware/cluster_app_mock.ts +0 -102
- package/src/app.ts +0 -18
- package/src/bootstrap.ts +0 -25
- package/src/index.ts +0 -112
- package/src/lib/agent_handler.ts +0 -28
- package/src/lib/app.ts +0 -314
- package/src/lib/app_handler.ts +0 -77
- package/src/lib/cluster.ts +0 -363
- package/src/lib/context.ts +0 -14
- package/src/lib/format_options.ts +0 -103
- package/src/lib/inject_context.ts +0 -134
- package/src/lib/mock_agent.ts +0 -57
- package/src/lib/mock_custom_loader.ts +0 -36
- package/src/lib/mock_http_server.ts +0 -19
- package/src/lib/mock_httpclient.ts +0 -183
- package/src/lib/parallel/agent.ts +0 -128
- package/src/lib/parallel/app.ts +0 -123
- package/src/lib/parallel/util.ts +0 -66
- package/src/lib/prerequire.ts +0 -25
- package/src/lib/request_call_function.ts +0 -49
- package/src/lib/restore.ts +0 -14
- package/src/lib/start-cluster.ts +0 -23
- package/src/lib/supertest.ts +0 -45
- package/src/lib/tmp/.gitkeep +0 -0
- package/src/lib/tmp/empty.ts +0 -0
- package/src/lib/utils.ts +0 -82
- package/src/register.ts +0 -80
- package/src/typings/index.d.ts +0 -4
|
@@ -1,55 +1,49 @@
|
|
|
1
|
-
|
|
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 {
|
|
2
6
|
/**
|
|
3
7
|
* The directory of the application
|
|
4
8
|
*/
|
|
5
9
|
baseDir?: string;
|
|
6
|
-
|
|
7
10
|
/**
|
|
8
11
|
* Custom you plugins
|
|
9
12
|
*/
|
|
10
13
|
plugins?: any;
|
|
11
|
-
|
|
12
14
|
/**
|
|
13
15
|
* The directory of the egg framework
|
|
14
16
|
*
|
|
15
17
|
* Set to `true` to use the current directory as framework directory
|
|
16
18
|
*/
|
|
17
19
|
framework?: string | boolean;
|
|
18
|
-
|
|
19
20
|
/**
|
|
20
21
|
* current test on plugin
|
|
21
22
|
*/
|
|
22
23
|
plugin?: boolean;
|
|
23
|
-
|
|
24
24
|
/**
|
|
25
|
-
* @deprecated please use framework instead
|
|
25
|
+
* @deprecated please use `framework` instead
|
|
26
26
|
*/
|
|
27
27
|
customEgg?: string | boolean;
|
|
28
|
-
|
|
29
28
|
/**
|
|
30
29
|
* Cache application based on baseDir
|
|
31
30
|
*/
|
|
32
31
|
cache?: boolean;
|
|
33
|
-
|
|
34
32
|
/**
|
|
35
33
|
* Switch on process coverage, but it'll be slower
|
|
36
34
|
*/
|
|
37
35
|
coverage?: boolean;
|
|
38
|
-
|
|
39
36
|
/**
|
|
40
37
|
* Remove $baseDir/logs and $baseDir/run before start, default is `true`
|
|
41
38
|
*/
|
|
42
39
|
clean?: boolean;
|
|
43
|
-
|
|
44
40
|
/**
|
|
45
41
|
* default options.mockCtxStorage value on each mockContext
|
|
46
42
|
*/
|
|
47
43
|
mockCtxStorage?: boolean;
|
|
48
|
-
|
|
49
44
|
beforeInit?: (app: any) => Promise<void>;
|
|
50
45
|
}
|
|
51
|
-
|
|
52
|
-
export interface MockClusterOptions extends MockOptions {
|
|
46
|
+
interface MockClusterOptions extends MockOptions {
|
|
53
47
|
workers?: number | string;
|
|
54
48
|
cache?: boolean;
|
|
55
49
|
port?: number;
|
|
@@ -59,31 +53,20 @@ export interface MockClusterOptions extends MockOptions {
|
|
|
59
53
|
opt?: object;
|
|
60
54
|
startMode?: 'process' | 'worker_threads';
|
|
61
55
|
}
|
|
62
|
-
|
|
63
56
|
/**
|
|
64
57
|
* @deprecated please use MockOptions instead
|
|
65
58
|
* keep this for compatible
|
|
66
59
|
*/
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
export interface MockApplicationOptions extends MockOptions {
|
|
60
|
+
type MockOption = MockOptions;
|
|
61
|
+
interface MockApplicationOptions extends MockOptions {
|
|
70
62
|
baseDir: string;
|
|
71
63
|
framework: string;
|
|
72
64
|
clusterPort?: number;
|
|
73
65
|
}
|
|
74
|
-
|
|
75
|
-
export interface MockClusterApplicationOptions extends MockClusterOptions {
|
|
66
|
+
interface MockClusterApplicationOptions extends MockClusterOptions {
|
|
76
67
|
baseDir: string;
|
|
77
68
|
framework: string;
|
|
78
69
|
port: number;
|
|
79
70
|
}
|
|
80
|
-
|
|
81
|
-
export type
|
|
82
|
-
MockResultOptions, ResultObject,
|
|
83
|
-
MockResponseCallbackOptions, MockResultFunction,
|
|
84
|
-
MockHttpClientMethod,
|
|
85
|
-
} from './mock_httpclient.js';
|
|
86
|
-
|
|
87
|
-
export type {
|
|
88
|
-
MockAgent,
|
|
89
|
-
} from 'urllib';
|
|
71
|
+
//#endregion
|
|
72
|
+
export { type MockAgent, MockApplicationOptions, MockClusterApplicationOptions, MockClusterOptions, type MockHttpClientMethod, MockOption, MockOptions, type MockResponseCallbackOptions, type MockResultFunction, type MockResultOptions, type ResultObject };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/lib/utils.d.ts
|
|
2
|
+
declare function getSourceDirname(): string;
|
|
3
|
+
declare function sleep(delay: number): Promise<void>;
|
|
4
|
+
declare function rimraf(filepath: string): Promise<void>;
|
|
5
|
+
declare function rimrafSync(filepath: string): void;
|
|
6
|
+
declare function getProperty(target: any, prop: PropertyKey): any;
|
|
7
|
+
declare function getEggOptions(): {
|
|
8
|
+
baseDir: string;
|
|
9
|
+
framework: string | undefined;
|
|
10
|
+
};
|
|
11
|
+
//#endregion
|
|
12
|
+
export { getEggOptions, getProperty, getSourceDirname, rimraf, rimrafSync, sleep };
|
|
@@ -0,0 +1,40 @@
|
|
|
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 };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import "mocha";
|
|
2
|
+
|
|
3
|
+
//#region src/register.d.ts
|
|
4
|
+
declare function mochaGlobalSetup(): Promise<void>;
|
|
5
|
+
declare function mochaGlobalTeardown(): Promise<void>;
|
|
6
|
+
declare const mochaHooks: {
|
|
7
|
+
beforeAll(): Promise<void>;
|
|
8
|
+
afterEach(): Promise<void>;
|
|
9
|
+
afterAll(): Promise<void>;
|
|
10
|
+
};
|
|
11
|
+
//#endregion
|
|
12
|
+
export { mochaGlobalSetup, mochaGlobalTeardown, mochaHooks };
|
package/dist/register.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { __require } from "./_virtual/rolldown_runtime.js";
|
|
2
|
+
import { closeAgent, setupAgent } from "./lib/agent_handler.js";
|
|
3
|
+
import { getApp } from "./lib/app_handler.js";
|
|
4
|
+
import { mm as proxyMock } from "./index.js";
|
|
5
|
+
import { injectContext } from "./lib/inject_context.js";
|
|
6
|
+
import { createRequire } from "node:module";
|
|
7
|
+
import { debuglog } from "node:util";
|
|
8
|
+
import "mocha";
|
|
9
|
+
|
|
10
|
+
//#region src/register.ts
|
|
11
|
+
const debug = debuglog("egg/mock/register");
|
|
12
|
+
async function mochaGlobalSetup() {
|
|
13
|
+
debug("mochaGlobalSetup, agent.setupAgent() start");
|
|
14
|
+
await setupAgent();
|
|
15
|
+
debug("mochaGlobalSetup, agent.setupAgent() end");
|
|
16
|
+
}
|
|
17
|
+
async function mochaGlobalTeardown() {
|
|
18
|
+
debug("mochaGlobalTeardown, agent.closeAgent() start");
|
|
19
|
+
await closeAgent();
|
|
20
|
+
debug("mochaGlobalTeardown, agent.closeAgent() end");
|
|
21
|
+
}
|
|
22
|
+
const mochaHooks = {
|
|
23
|
+
async beforeAll() {
|
|
24
|
+
const app = await getApp();
|
|
25
|
+
debug("mochaHooks.beforeAll call, _app: %s", app);
|
|
26
|
+
if (app) await app.ready();
|
|
27
|
+
},
|
|
28
|
+
async afterEach() {
|
|
29
|
+
const app = await getApp();
|
|
30
|
+
debug("mochaHooks.afterEach call, _app: %s", app);
|
|
31
|
+
if (app) await app.backgroundTasksFinished();
|
|
32
|
+
await proxyMock.restore();
|
|
33
|
+
},
|
|
34
|
+
async afterAll() {
|
|
35
|
+
if (process.env.ENABLE_MOCHA_PARALLEL) return;
|
|
36
|
+
const app = await getApp();
|
|
37
|
+
debug("mochaHooks.afterAll call, _app: %s", app);
|
|
38
|
+
if (app) await app.close();
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Find active node mocha instances.
|
|
43
|
+
*/
|
|
44
|
+
function findNodeJSMocha() {
|
|
45
|
+
let children;
|
|
46
|
+
if (typeof __require === "function") children = __require.cache || {};
|
|
47
|
+
else {
|
|
48
|
+
children = createRequire(process.cwd()).cache || {};
|
|
49
|
+
debug("createRequire on esm");
|
|
50
|
+
}
|
|
51
|
+
return Object.keys(children).filter(function(child) {
|
|
52
|
+
const val = children[child].exports;
|
|
53
|
+
return typeof val === "function" && val.name === "Mocha";
|
|
54
|
+
}).map(function(child) {
|
|
55
|
+
return children[child].exports;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
const modules = findNodeJSMocha();
|
|
59
|
+
for (const module of modules) {
|
|
60
|
+
if (!module) continue;
|
|
61
|
+
injectContext(module);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
//#endregion
|
|
65
|
+
export { mochaGlobalSetup, mochaGlobalTeardown, mochaHooks };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/package.json
CHANGED
|
@@ -1,21 +1,56 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eggjs/mock",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.1.0-beta.3",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
7
|
"eggPlugin": {
|
|
8
|
-
"name": "egg-mock"
|
|
9
|
-
"exports": {
|
|
10
|
-
"import": "./dist/esm",
|
|
11
|
-
"require": "./dist/commonjs"
|
|
12
|
-
}
|
|
8
|
+
"name": "egg-mock"
|
|
13
9
|
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"main": "./dist/index.js",
|
|
12
|
+
"module": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": "./dist/index.js",
|
|
16
|
+
"./app": "./dist/app.js",
|
|
17
|
+
"./app/extend/agent": "./dist/app/extend/agent.js",
|
|
18
|
+
"./app/extend/application": "./dist/app/extend/application.js",
|
|
19
|
+
"./app/middleware/cluster_app_mock": "./dist/app/middleware/cluster_app_mock.js",
|
|
20
|
+
"./bootstrap": "./dist/bootstrap.js",
|
|
21
|
+
"./lib/agent_handler": "./dist/lib/agent_handler.js",
|
|
22
|
+
"./lib/app": "./dist/lib/app.js",
|
|
23
|
+
"./lib/app_handler": "./dist/lib/app_handler.js",
|
|
24
|
+
"./lib/cluster": "./dist/lib/cluster.js",
|
|
25
|
+
"./lib/context": "./dist/lib/context.js",
|
|
26
|
+
"./lib/format_options": "./dist/lib/format_options.js",
|
|
27
|
+
"./lib/inject_context": "./dist/lib/inject_context.js",
|
|
28
|
+
"./lib/mock_agent": "./dist/lib/mock_agent.js",
|
|
29
|
+
"./lib/mock_custom_loader": "./dist/lib/mock_custom_loader.js",
|
|
30
|
+
"./lib/mock_http_server": "./dist/lib/mock_http_server.js",
|
|
31
|
+
"./lib/mock_httpclient": "./dist/lib/mock_httpclient.js",
|
|
32
|
+
"./lib/parallel/agent": "./dist/lib/parallel/agent.js",
|
|
33
|
+
"./lib/parallel/app": "./dist/lib/parallel/app.js",
|
|
34
|
+
"./lib/parallel/util": "./dist/lib/parallel/util.js",
|
|
35
|
+
"./lib/prerequire": "./dist/lib/prerequire.js",
|
|
36
|
+
"./lib/request_call_function": "./dist/lib/request_call_function.js",
|
|
37
|
+
"./lib/restore": "./dist/lib/restore.js",
|
|
38
|
+
"./lib/start-cluster": "./dist/lib/start-cluster.js",
|
|
39
|
+
"./lib/supertest": "./dist/lib/supertest.js",
|
|
40
|
+
"./lib/tmp/empty": "./dist/lib/tmp/empty.js",
|
|
41
|
+
"./lib/types": "./dist/lib/types.js",
|
|
42
|
+
"./lib/utils": "./dist/lib/utils.js",
|
|
43
|
+
"./register": "./dist/register.js",
|
|
44
|
+
"./package.json": "./package.json"
|
|
45
|
+
},
|
|
46
|
+
"files": [
|
|
47
|
+
"dist"
|
|
48
|
+
],
|
|
14
49
|
"description": "mock server plugin for egg",
|
|
15
|
-
"homepage": "https://github.com/eggjs/mock",
|
|
16
50
|
"repository": {
|
|
17
51
|
"type": "git",
|
|
18
|
-
"url": "git
|
|
52
|
+
"url": "git://github.com/eggjs/egg.git",
|
|
53
|
+
"directory": "packages/mock"
|
|
19
54
|
},
|
|
20
55
|
"bugs": {
|
|
21
56
|
"url": "https://github.com/eggjs/egg/issues"
|
|
@@ -26,111 +61,44 @@
|
|
|
26
61
|
],
|
|
27
62
|
"author": "popomore <sakura9515@gmail.com>",
|
|
28
63
|
"engines": {
|
|
29
|
-
"node": ">=
|
|
64
|
+
"node": ">= 20.19.0"
|
|
30
65
|
},
|
|
31
66
|
"dependencies": {
|
|
32
|
-
"@eggjs/
|
|
33
|
-
"
|
|
34
|
-
"@eggjs/utils": "^4.0.3",
|
|
35
|
-
"coffee": "^5.2.1",
|
|
67
|
+
"@eggjs/supertest": "",
|
|
68
|
+
"coffee": "5",
|
|
36
69
|
"detect-port": "^2.1.0",
|
|
37
70
|
"egg-logger": "^3.5.0",
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"globby": "^11.1.0",
|
|
71
|
+
"get-ready": "^3.1.0",
|
|
72
|
+
"globby": "^11.0.2",
|
|
41
73
|
"is-type-of": "^2.2.0",
|
|
42
74
|
"merge-descriptors": "^2.0.0",
|
|
43
|
-
"mm": "^4.0.
|
|
44
|
-
"sdk-base": "^5.0.
|
|
75
|
+
"mm": "^4.0.2",
|
|
76
|
+
"sdk-base": "^5.0.1",
|
|
45
77
|
"urllib": "^4.6.11",
|
|
46
|
-
"utility": "^2.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
"
|
|
78
|
+
"utility": "^2.5.0",
|
|
79
|
+
"@eggjs/core": "6.6.0-beta.3",
|
|
80
|
+
"@eggjs/utils": "4.5.0-beta.3",
|
|
81
|
+
"@eggjs/extend2": "4.1.0-beta.3"
|
|
50
82
|
},
|
|
51
83
|
"devDependencies": {
|
|
52
|
-
"@arethetypeswrong/cli": "^0.17.1",
|
|
53
|
-
"@eggjs/bin": "^7.0.0",
|
|
54
84
|
"@eggjs/tegg": "^3.2.2",
|
|
55
85
|
"@eggjs/tegg-config": "^3.2.2",
|
|
56
86
|
"@eggjs/tegg-controller-plugin": "^3.2.2",
|
|
57
87
|
"@eggjs/tegg-plugin": "^3.2.2",
|
|
58
|
-
"@eggjs/tsconfig": "1",
|
|
59
88
|
"@types/methods": "^1.1.4",
|
|
60
|
-
"@types/
|
|
61
|
-
"
|
|
62
|
-
"egg": "^
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"rimraf": "6",
|
|
70
|
-
"tsd": "^0.31.2",
|
|
71
|
-
"tshy": "3",
|
|
72
|
-
"tshy-after": "^1.3.1",
|
|
73
|
-
"typescript": "5"
|
|
89
|
+
"@types/node": "24",
|
|
90
|
+
"egg-errors": "^2.3.2",
|
|
91
|
+
"egg-tracer": "^2.1.0",
|
|
92
|
+
"pedding": "^2.0.1",
|
|
93
|
+
"tsd": "^0.33.0",
|
|
94
|
+
"tsdown": "^0.15.0",
|
|
95
|
+
"typescript": "5",
|
|
96
|
+
"egg": "4.1.0-beta.3",
|
|
97
|
+
"@eggjs/tsconfig": "3.1.0-beta.3"
|
|
74
98
|
},
|
|
75
99
|
"scripts": {
|
|
76
|
-
"
|
|
77
|
-
"lint": "
|
|
78
|
-
"
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
"test-local": "egg-bin test",
|
|
82
|
-
"preci": "npm run clean && npm run lint && npm run prepublishOnly",
|
|
83
|
-
"ci": "egg-bin test",
|
|
84
|
-
"postci": "npm run clean",
|
|
85
|
-
"prepublishOnly": "tshy && tshy-after && attw --pack --profile node16"
|
|
86
|
-
},
|
|
87
|
-
"type": "module",
|
|
88
|
-
"tshy": {
|
|
89
|
-
"exports": {
|
|
90
|
-
".": "./src/index.ts",
|
|
91
|
-
"./bootstrap": "./src/bootstrap.ts",
|
|
92
|
-
"./register": "./src/register.ts",
|
|
93
|
-
"./package.json": "./package.json"
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
"exports": {
|
|
97
|
-
".": {
|
|
98
|
-
"import": {
|
|
99
|
-
"types": "./dist/esm/index.d.ts",
|
|
100
|
-
"default": "./dist/esm/index.js"
|
|
101
|
-
},
|
|
102
|
-
"require": {
|
|
103
|
-
"types": "./dist/commonjs/index.d.ts",
|
|
104
|
-
"default": "./dist/commonjs/index.js"
|
|
105
|
-
}
|
|
106
|
-
},
|
|
107
|
-
"./bootstrap": {
|
|
108
|
-
"import": {
|
|
109
|
-
"types": "./dist/esm/bootstrap.d.ts",
|
|
110
|
-
"default": "./dist/esm/bootstrap.js"
|
|
111
|
-
},
|
|
112
|
-
"require": {
|
|
113
|
-
"types": "./dist/commonjs/bootstrap.d.ts",
|
|
114
|
-
"default": "./dist/commonjs/bootstrap.js"
|
|
115
|
-
}
|
|
116
|
-
},
|
|
117
|
-
"./register": {
|
|
118
|
-
"import": {
|
|
119
|
-
"types": "./dist/esm/register.d.ts",
|
|
120
|
-
"default": "./dist/esm/register.js"
|
|
121
|
-
},
|
|
122
|
-
"require": {
|
|
123
|
-
"types": "./dist/commonjs/register.d.ts",
|
|
124
|
-
"default": "./dist/commonjs/register.js"
|
|
125
|
-
}
|
|
126
|
-
},
|
|
127
|
-
"./package.json": "./package.json"
|
|
128
|
-
},
|
|
129
|
-
"files": [
|
|
130
|
-
"dist",
|
|
131
|
-
"src"
|
|
132
|
-
],
|
|
133
|
-
"types": "./dist/commonjs/index.d.ts",
|
|
134
|
-
"main": "./dist/commonjs/index.js",
|
|
135
|
-
"module": "./dist/esm/index.js"
|
|
136
|
-
}
|
|
100
|
+
"build": "tsdown",
|
|
101
|
+
"lint": "oxlint",
|
|
102
|
+
"test": "vitest run"
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { mock, restore } from 'mm';
|
|
2
|
-
import { EggCore } from '@eggjs/core';
|
|
3
|
-
import { MockResultFunction, MockResultOptions, MockHttpClientMethod } from '../../lib/mock_httpclient.js';
|
|
4
|
-
export default abstract class AgentUnittest extends EggCore {
|
|
5
|
-
[key: string]: any;
|
|
6
|
-
_mockHttpClient: MockHttpClientMethod;
|
|
7
|
-
/**
|
|
8
|
-
* mock httpclient
|
|
9
|
-
* @alias mockHttpClient
|
|
10
|
-
* @function App#mockHttpclient
|
|
11
|
-
*/
|
|
12
|
-
mockHttpclient(mockUrl: string | RegExp, mockMethod: string | string[] | MockResultOptions | MockResultFunction, mockResult?: MockResultOptions | MockResultFunction | string): void;
|
|
13
|
-
/**
|
|
14
|
-
* mock httpclient
|
|
15
|
-
* @function App#mockHttpClient
|
|
16
|
-
*/
|
|
17
|
-
mockHttpClient(mockUrl: string | RegExp, mockMethod: string | string[] | MockResultOptions | MockResultFunction, mockResult?: MockResultOptions | MockResultFunction | string): void;
|
|
18
|
-
/**
|
|
19
|
-
* get mock httpclient agent
|
|
20
|
-
* @function Agent#mockHttpclientAgent
|
|
21
|
-
*/
|
|
22
|
-
mockAgent(): import("urllib").MockAgent<import("urllib").MockAgent.Options>;
|
|
23
|
-
mockAgentRestore(): Promise<void>;
|
|
24
|
-
/**
|
|
25
|
-
* @see mm#restore
|
|
26
|
-
* @function Agent#mockRestore
|
|
27
|
-
*/
|
|
28
|
-
mockRestore: typeof restore;
|
|
29
|
-
/**
|
|
30
|
-
* @see mm
|
|
31
|
-
* @function Agent#mm
|
|
32
|
-
*/
|
|
33
|
-
mm: typeof mock;
|
|
34
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const mm_1 = require("mm");
|
|
4
|
-
const core_1 = require("@eggjs/core");
|
|
5
|
-
const mock_httpclient_js_1 = require("../../lib/mock_httpclient.js");
|
|
6
|
-
const mock_agent_js_1 = require("../../lib/mock_agent.js");
|
|
7
|
-
class AgentUnittest extends core_1.EggCore {
|
|
8
|
-
_mockHttpClient;
|
|
9
|
-
/**
|
|
10
|
-
* mock httpclient
|
|
11
|
-
* @alias mockHttpClient
|
|
12
|
-
* @function App#mockHttpclient
|
|
13
|
-
*/
|
|
14
|
-
mockHttpclient(mockUrl, mockMethod, mockResult) {
|
|
15
|
-
return this.mockHttpClient(mockUrl, mockMethod, mockResult);
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* mock httpclient
|
|
19
|
-
* @function App#mockHttpClient
|
|
20
|
-
*/
|
|
21
|
-
mockHttpClient(mockUrl, mockMethod, mockResult) {
|
|
22
|
-
if (!this._mockHttpClient) {
|
|
23
|
-
this._mockHttpClient = (0, mock_httpclient_js_1.createMockHttpClient)(this);
|
|
24
|
-
}
|
|
25
|
-
return this._mockHttpClient(mockUrl, mockMethod, mockResult);
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* get mock httpclient agent
|
|
29
|
-
* @function Agent#mockHttpclientAgent
|
|
30
|
-
*/
|
|
31
|
-
mockAgent() {
|
|
32
|
-
return (0, mock_agent_js_1.getMockAgent)(this);
|
|
33
|
-
}
|
|
34
|
-
async mockAgentRestore() {
|
|
35
|
-
await (0, mock_agent_js_1.restoreMockAgent)();
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* @see mm#restore
|
|
39
|
-
* @function Agent#mockRestore
|
|
40
|
-
*/
|
|
41
|
-
mockRestore = mm_1.restore;
|
|
42
|
-
/**
|
|
43
|
-
* @see mm
|
|
44
|
-
* @function Agent#mm
|
|
45
|
-
*/
|
|
46
|
-
mm = mm_1.mock;
|
|
47
|
-
}
|
|
48
|
-
exports.default = AgentUnittest;
|
|
49
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWdlbnQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9zcmMvYXBwL2V4dGVuZC9hZ2VudC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDJCQUFtQztBQUNuQyxzQ0FBc0M7QUFDdEMscUVBSXNDO0FBQ3RDLDJEQUF5RTtBQUV6RSxNQUE4QixhQUFjLFNBQVEsY0FBTztJQUV6RCxlQUFlLENBQXVCO0lBRXRDOzs7O09BSUc7SUFDSCxjQUFjLENBQUMsT0FBd0IsRUFBRSxVQUFzRSxFQUFFLFVBQTREO1FBQzNLLE9BQU8sSUFBSSxDQUFDLGNBQWMsQ0FBQyxPQUFPLEVBQUUsVUFBVSxFQUFFLFVBQVUsQ0FBQyxDQUFDO0lBQzlELENBQUM7SUFFRDs7O09BR0c7SUFDSCxjQUFjLENBQUMsT0FBd0IsRUFBRSxVQUFzRSxFQUFFLFVBQTREO1FBQzNLLElBQUksQ0FBQyxJQUFJLENBQUMsZUFBZSxFQUFFLENBQUM7WUFDMUIsSUFBSSxDQUFDLGVBQWUsR0FBRyxJQUFBLHlDQUFvQixFQUFDLElBQUksQ0FBQyxDQUFDO1FBQ3BELENBQUM7UUFDRCxPQUFPLElBQUksQ0FBQyxlQUFlLENBQUMsT0FBTyxFQUFFLFVBQVUsRUFBRSxVQUFVLENBQUMsQ0FBQztJQUMvRCxDQUFDO0lBRUQ7OztPQUdHO0lBQ0gsU0FBUztRQUNQLE9BQU8sSUFBQSw0QkFBWSxFQUFDLElBQVcsQ0FBQyxDQUFDO0lBQ25DLENBQUM7SUFFRCxLQUFLLENBQUMsZ0JBQWdCO1FBQ3BCLE1BQU0sSUFBQSxnQ0FBZ0IsR0FBRSxDQUFDO0lBQzNCLENBQUM7SUFFRDs7O09BR0c7SUFDSCxXQUFXLEdBQUcsWUFBTyxDQUFDO0lBRXRCOzs7T0FHRztJQUNILEVBQUUsR0FBRyxTQUFJLENBQUM7Q0FDWDtBQS9DRCxnQ0ErQ0MifQ==
|