@eggjs/mock 6.0.7 → 6.1.0-beta.10
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 +30 -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 +175 -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 +47 -0
- package/dist/inject_mocha.d.ts +1 -0
- package/dist/inject_mocha.js +35 -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 +12 -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 +99 -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/node_modules/.pnpm/ansi-styles@4.3.0/node_modules/ansi-styles/index.js +142 -0
- package/dist/node_modules/.pnpm/chalk@4.1.2/node_modules/chalk/source/index.js +157 -0
- package/dist/node_modules/.pnpm/chalk@4.1.2/node_modules/chalk/source/templates.js +97 -0
- package/dist/node_modules/.pnpm/chalk@4.1.2/node_modules/chalk/source/util.js +40 -0
- package/dist/node_modules/.pnpm/color-convert@2.0.1/node_modules/color-convert/conversions.js +814 -0
- package/dist/node_modules/.pnpm/color-convert@2.0.1/node_modules/color-convert/index.js +50 -0
- package/dist/node_modules/.pnpm/color-convert@2.0.1/node_modules/color-convert/route.js +68 -0
- package/dist/node_modules/.pnpm/color-name@1.1.4/node_modules/color-name/index.js +752 -0
- package/dist/node_modules/.pnpm/debug@4.4.3_supports-color@8.1.1/node_modules/debug/src/browser.js +203 -0
- package/dist/node_modules/.pnpm/debug@4.4.3_supports-color@8.1.1/node_modules/debug/src/common.js +209 -0
- package/dist/node_modules/.pnpm/debug@4.4.3_supports-color@8.1.1/node_modules/debug/src/index.js +18 -0
- package/dist/node_modules/.pnpm/debug@4.4.3_supports-color@8.1.1/node_modules/debug/src/node.js +215 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/convert/dmp.js +24 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/convert/xml.js +33 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/diff/array.js +29 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/diff/base.js +185 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/diff/character.js +23 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/diff/css.js +26 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/diff/json.js +83 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/diff/line.js +51 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/diff/sentence.js +26 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/diff/word.js +151 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/index.js +178 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/patch/apply.js +168 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/patch/create.js +301 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/patch/line-endings.js +137 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/patch/merge.js +367 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/patch/parse.js +91 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/patch/reverse.js +99 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/util/array.js +23 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/util/distance-iterator.js +30 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/util/params.js +22 -0
- package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/util/string.js +97 -0
- package/dist/node_modules/.pnpm/escape-string-regexp@4.0.0/node_modules/escape-string-regexp/index.js +14 -0
- package/dist/node_modules/.pnpm/has-flag@4.0.0/node_modules/has-flag/index.js +16 -0
- package/dist/node_modules/.pnpm/he@1.2.0/node_modules/he/he.js +4093 -0
- package/dist/node_modules/.pnpm/is-unicode-supported@0.1.0/node_modules/is-unicode-supported/index.js +14 -0
- package/dist/node_modules/.pnpm/log-symbols@4.1.0/node_modules/log-symbols/index.js +27 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/index.js +12 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/context.js +83 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/error-constants.js +35 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/errors.js +392 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/hook.js +86 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/interfaces/bdd.js +104 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/interfaces/common.js +99 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/interfaces/exports.js +65 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/interfaces/index.js +18 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/interfaces/qunit.js +95 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/interfaces/tdd.js +105 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/mocha.js +1037 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/mocharc.js +24 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/nodejs/buffered-worker-pool.js +152 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/nodejs/esm-utils.js +74 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/nodejs/file-unloader.js +22 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/nodejs/parallel-buffered-runner.js +329 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/nodejs/serializer.js +314 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/pending.js +22 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/base.js +417 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/doc.js +79 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/dot.js +75 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/html.js +283 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/index.js +40 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/json-stream.js +90 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/json.js +145 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/landing.js +107 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/list.js +77 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/markdown.js +106 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/min.js +57 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/nyan.js +233 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/progress.js +92 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/spec.js +91 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/tap.js +261 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/xunit.js +166 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/runnable.js +346 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/runner.js +922 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/stats-collector.js +72 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/suite.js +517 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/test.js +105 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/utils.js +505 -0
- package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/package.js +225 -0
- package/dist/node_modules/.pnpm/ms@2.1.3/node_modules/ms/index.js +124 -0
- package/dist/node_modules/.pnpm/randombytes@2.1.0/node_modules/randombytes/index.js +11 -0
- package/dist/node_modules/.pnpm/serialize-javascript@6.0.2/node_modules/serialize-javascript/index.js +114 -0
- package/dist/node_modules/.pnpm/supports-color@7.2.0/node_modules/supports-color/index.js +76 -0
- package/dist/node_modules/.pnpm/supports-color@8.1.1/node_modules/supports-color/index.js +89 -0
- package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/Pool.js +366 -0
- package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/Promise.js +248 -0
- package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/WorkerHandler.js +419 -0
- package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/debug-port-allocator.js +27 -0
- package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/environment.js +18 -0
- package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/generated/embeddedWorker.js +16 -0
- package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/index.js +63 -0
- package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/transfer.js +21 -0
- package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/validateOptions.js +9 -0
- package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/worker.js +277 -0
- package/dist/register.d.ts +10 -0
- package/dist/register.js +40 -0
- package/dist/typings/index.d.ts +1 -0
- package/package.json +71 -98
- 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
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { getMockAgent } from "./mock_agent.js";
|
|
2
|
+
import { mm } from "mm";
|
|
3
|
+
import { extend } from "@eggjs/extend2";
|
|
4
|
+
|
|
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
|
+
export { createMockHttpClient };
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
|
24
|
+
export { MockAgent, createAgent };
|
|
@@ -0,0 +1,111 @@
|
|
|
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";
|
|
11
|
+
|
|
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
|
+
export { MockAgent, createAgent };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { MockApplicationOptions, MockOptions } from "../types.js";
|
|
2
|
+
import { APP_INIT } from "./util.js";
|
|
3
|
+
import { Application } from "egg";
|
|
4
|
+
import { Base } from "sdk-base";
|
|
5
|
+
|
|
6
|
+
//#region src/lib/parallel/app.d.ts
|
|
7
|
+
declare class MockParallelApplication extends Base {
|
|
8
|
+
#private;
|
|
9
|
+
options: MockApplicationOptions;
|
|
10
|
+
baseDir: string;
|
|
11
|
+
[APP_INIT]: boolean;
|
|
12
|
+
_instance: Application;
|
|
13
|
+
constructor(options: MockApplicationOptions);
|
|
14
|
+
_init(): Promise<void>;
|
|
15
|
+
on(...args: any[]): this;
|
|
16
|
+
once(...args: any[]): this;
|
|
17
|
+
/**
|
|
18
|
+
* close app
|
|
19
|
+
*/
|
|
20
|
+
_close(): Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
declare function createApp(initOptions: MockOptions): any;
|
|
23
|
+
//#endregion
|
|
24
|
+
export { MockParallelApplication, createApp };
|
|
@@ -0,0 +1,99 @@
|
|
|
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";
|
|
11
|
+
|
|
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
|
+
export { MockParallelApplication, createApp };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { getProperty } from "../utils.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 };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import httpClient from "urllib";
|
|
2
|
+
|
|
3
|
+
//#region src/lib/request_call_function.ts
|
|
4
|
+
const { port, method, args, property, needResult } = JSON.parse(process.argv[2]);
|
|
5
|
+
const url = `http://127.0.0.1:${port}/__egg_mock_call_function`;
|
|
6
|
+
httpClient.request(url, {
|
|
7
|
+
method: "POST",
|
|
8
|
+
data: {
|
|
9
|
+
method,
|
|
10
|
+
args,
|
|
11
|
+
property,
|
|
12
|
+
needResult
|
|
13
|
+
},
|
|
14
|
+
contentType: "json",
|
|
15
|
+
dataType: "json"
|
|
16
|
+
}).then(({ data }) => {
|
|
17
|
+
if (!data.success) {
|
|
18
|
+
if (data.error) console.error(data.error);
|
|
19
|
+
else if (data.message) {
|
|
20
|
+
const err = new Error(data.message);
|
|
21
|
+
err.stack = data.stack;
|
|
22
|
+
console.error(err);
|
|
23
|
+
}
|
|
24
|
+
process.exit(2);
|
|
25
|
+
}
|
|
26
|
+
if (data.result) console.log("%j", data.result);
|
|
27
|
+
process.exit(0);
|
|
28
|
+
}).catch((err) => {
|
|
29
|
+
if (method === "mockRestore" && err.message.includes("ECONNREFUSED")) process.exit(0);
|
|
30
|
+
console.error("POST %s error, method: %s, args: %j", url, method, args);
|
|
31
|
+
console.error(err.stack);
|
|
32
|
+
if (method === "mockRestore") process.exit(0);
|
|
33
|
+
else process.exit(1);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
export { };
|
|
@@ -0,0 +1,16 @@
|
|
|
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";
|
|
5
|
+
|
|
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
|
+
export { restore };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import assert from "node:assert";
|
|
3
|
+
import { debuglog } from "node:util";
|
|
4
|
+
import { importModule } from "@eggjs/utils";
|
|
5
|
+
import { isAsyncFunction } from "is-type-of";
|
|
6
|
+
|
|
7
|
+
//#region src/lib/start-cluster.ts
|
|
8
|
+
const debug = debuglog("egg/mock/lib/start-cluster");
|
|
9
|
+
async function main() {
|
|
10
|
+
const options = JSON.parse(process.argv[2]);
|
|
11
|
+
debug("startCluster with options: %o", options);
|
|
12
|
+
const { startCluster } = await importModule(options.framework);
|
|
13
|
+
assert(isAsyncFunction(startCluster), `framework(${options.framework}) should export startCluster as an async function`);
|
|
14
|
+
await startCluster(options);
|
|
15
|
+
}
|
|
16
|
+
main();
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
export { };
|
|
@@ -0,0 +1,16 @@
|
|
|
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 };
|
|
@@ -0,0 +1,39 @@
|
|
|
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";
|
|
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 };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|