@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.
Files changed (309) hide show
  1. package/README.md +35 -56
  2. package/README.zh_CN.md +30 -50
  3. package/dist/_virtual/rolldown_runtime.js +30 -0
  4. package/dist/app/extend/agent.d.ts +39 -0
  5. package/dist/app/extend/agent.js +48 -0
  6. package/dist/app/extend/application.d.ts +175 -0
  7. package/dist/app/extend/application.js +385 -0
  8. package/dist/app/middleware/cluster_app_mock.d.ts +6 -0
  9. package/dist/app/middleware/cluster_app_mock.js +97 -0
  10. package/dist/app.d.ts +10 -0
  11. package/dist/app.js +17 -0
  12. package/dist/bootstrap.d.ts +9 -0
  13. package/dist/bootstrap.js +14 -0
  14. package/dist/index.d.ts +81 -0
  15. package/dist/index.js +47 -0
  16. package/dist/inject_mocha.d.ts +1 -0
  17. package/dist/inject_mocha.js +35 -0
  18. package/dist/lib/agent_handler.d.ts +7 -0
  19. package/dist/lib/agent_handler.js +26 -0
  20. package/dist/lib/app.d.ts +7 -0
  21. package/dist/lib/app.js +251 -0
  22. package/dist/lib/app_handler.d.ts +9 -0
  23. package/dist/lib/app_handler.js +56 -0
  24. package/dist/lib/cluster.d.ts +126 -0
  25. package/dist/lib/cluster.js +283 -0
  26. package/dist/lib/context.d.ts +4 -0
  27. package/dist/lib/context.js +12 -0
  28. package/dist/lib/format_options.d.ts +10 -0
  29. package/dist/lib/format_options.js +65 -0
  30. package/dist/lib/inject_context.d.ts +9 -0
  31. package/dist/lib/inject_context.js +106 -0
  32. package/dist/lib/mock_agent.d.ts +9 -0
  33. package/dist/lib/mock_agent.js +45 -0
  34. package/dist/lib/mock_custom_loader.d.ts +4 -0
  35. package/dist/lib/mock_custom_loader.js +35 -0
  36. package/dist/lib/mock_http_server.d.ts +6 -0
  37. package/dist/lib/mock_http_server.js +17 -0
  38. package/dist/lib/mock_httpclient.d.ts +40 -0
  39. package/dist/lib/mock_httpclient.js +110 -0
  40. package/dist/lib/parallel/agent.d.ts +24 -0
  41. package/dist/lib/parallel/agent.js +111 -0
  42. package/dist/lib/parallel/app.d.ts +24 -0
  43. package/dist/lib/parallel/app.js +99 -0
  44. package/dist/lib/parallel/util.d.ts +6 -0
  45. package/dist/lib/parallel/util.js +59 -0
  46. package/dist/lib/prerequire.d.ts +1 -0
  47. package/dist/lib/prerequire.js +1 -0
  48. package/dist/lib/request_call_function.d.ts +1 -0
  49. package/dist/lib/request_call_function.js +37 -0
  50. package/dist/lib/restore.d.ts +4 -0
  51. package/dist/lib/restore.js +16 -0
  52. package/dist/lib/start-cluster.d.ts +1 -0
  53. package/dist/lib/start-cluster.js +19 -0
  54. package/dist/lib/supertest.d.ts +16 -0
  55. package/dist/lib/supertest.js +39 -0
  56. package/dist/lib/tmp/empty.d.ts +1 -0
  57. package/dist/lib/tmp/empty.js +1 -0
  58. package/{src/lib/types.ts → dist/lib/types.d.ts} +12 -29
  59. package/dist/lib/types.js +1 -0
  60. package/dist/lib/utils.d.ts +12 -0
  61. package/dist/lib/utils.js +40 -0
  62. package/dist/node_modules/.pnpm/ansi-styles@4.3.0/node_modules/ansi-styles/index.js +142 -0
  63. package/dist/node_modules/.pnpm/chalk@4.1.2/node_modules/chalk/source/index.js +157 -0
  64. package/dist/node_modules/.pnpm/chalk@4.1.2/node_modules/chalk/source/templates.js +97 -0
  65. package/dist/node_modules/.pnpm/chalk@4.1.2/node_modules/chalk/source/util.js +40 -0
  66. package/dist/node_modules/.pnpm/color-convert@2.0.1/node_modules/color-convert/conversions.js +814 -0
  67. package/dist/node_modules/.pnpm/color-convert@2.0.1/node_modules/color-convert/index.js +50 -0
  68. package/dist/node_modules/.pnpm/color-convert@2.0.1/node_modules/color-convert/route.js +68 -0
  69. package/dist/node_modules/.pnpm/color-name@1.1.4/node_modules/color-name/index.js +752 -0
  70. package/dist/node_modules/.pnpm/debug@4.4.3_supports-color@8.1.1/node_modules/debug/src/browser.js +203 -0
  71. package/dist/node_modules/.pnpm/debug@4.4.3_supports-color@8.1.1/node_modules/debug/src/common.js +209 -0
  72. package/dist/node_modules/.pnpm/debug@4.4.3_supports-color@8.1.1/node_modules/debug/src/index.js +18 -0
  73. package/dist/node_modules/.pnpm/debug@4.4.3_supports-color@8.1.1/node_modules/debug/src/node.js +215 -0
  74. package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/convert/dmp.js +24 -0
  75. package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/convert/xml.js +33 -0
  76. package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/diff/array.js +29 -0
  77. package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/diff/base.js +185 -0
  78. package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/diff/character.js +23 -0
  79. package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/diff/css.js +26 -0
  80. package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/diff/json.js +83 -0
  81. package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/diff/line.js +51 -0
  82. package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/diff/sentence.js +26 -0
  83. package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/diff/word.js +151 -0
  84. package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/index.js +178 -0
  85. package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/patch/apply.js +168 -0
  86. package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/patch/create.js +301 -0
  87. package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/patch/line-endings.js +137 -0
  88. package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/patch/merge.js +367 -0
  89. package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/patch/parse.js +91 -0
  90. package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/patch/reverse.js +99 -0
  91. package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/util/array.js +23 -0
  92. package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/util/distance-iterator.js +30 -0
  93. package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/util/params.js +22 -0
  94. package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/util/string.js +97 -0
  95. package/dist/node_modules/.pnpm/escape-string-regexp@4.0.0/node_modules/escape-string-regexp/index.js +14 -0
  96. package/dist/node_modules/.pnpm/has-flag@4.0.0/node_modules/has-flag/index.js +16 -0
  97. package/dist/node_modules/.pnpm/he@1.2.0/node_modules/he/he.js +4093 -0
  98. package/dist/node_modules/.pnpm/is-unicode-supported@0.1.0/node_modules/is-unicode-supported/index.js +14 -0
  99. package/dist/node_modules/.pnpm/log-symbols@4.1.0/node_modules/log-symbols/index.js +27 -0
  100. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/index.js +12 -0
  101. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/context.js +83 -0
  102. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/error-constants.js +35 -0
  103. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/errors.js +392 -0
  104. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/hook.js +86 -0
  105. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/interfaces/bdd.js +104 -0
  106. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/interfaces/common.js +99 -0
  107. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/interfaces/exports.js +65 -0
  108. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/interfaces/index.js +18 -0
  109. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/interfaces/qunit.js +95 -0
  110. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/interfaces/tdd.js +105 -0
  111. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/mocha.js +1037 -0
  112. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/mocharc.js +24 -0
  113. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/nodejs/buffered-worker-pool.js +152 -0
  114. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/nodejs/esm-utils.js +74 -0
  115. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/nodejs/file-unloader.js +22 -0
  116. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/nodejs/parallel-buffered-runner.js +329 -0
  117. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/nodejs/serializer.js +314 -0
  118. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/pending.js +22 -0
  119. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/base.js +417 -0
  120. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/doc.js +79 -0
  121. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/dot.js +75 -0
  122. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/html.js +283 -0
  123. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/index.js +40 -0
  124. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/json-stream.js +90 -0
  125. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/json.js +145 -0
  126. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/landing.js +107 -0
  127. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/list.js +77 -0
  128. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/markdown.js +106 -0
  129. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/min.js +57 -0
  130. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/nyan.js +233 -0
  131. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/progress.js +92 -0
  132. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/spec.js +91 -0
  133. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/tap.js +261 -0
  134. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/xunit.js +166 -0
  135. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/runnable.js +346 -0
  136. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/runner.js +922 -0
  137. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/stats-collector.js +72 -0
  138. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/suite.js +517 -0
  139. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/test.js +105 -0
  140. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/utils.js +505 -0
  141. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/package.js +225 -0
  142. package/dist/node_modules/.pnpm/ms@2.1.3/node_modules/ms/index.js +124 -0
  143. package/dist/node_modules/.pnpm/randombytes@2.1.0/node_modules/randombytes/index.js +11 -0
  144. package/dist/node_modules/.pnpm/serialize-javascript@6.0.2/node_modules/serialize-javascript/index.js +114 -0
  145. package/dist/node_modules/.pnpm/supports-color@7.2.0/node_modules/supports-color/index.js +76 -0
  146. package/dist/node_modules/.pnpm/supports-color@8.1.1/node_modules/supports-color/index.js +89 -0
  147. package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/Pool.js +366 -0
  148. package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/Promise.js +248 -0
  149. package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/WorkerHandler.js +419 -0
  150. package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/debug-port-allocator.js +27 -0
  151. package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/environment.js +18 -0
  152. package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/generated/embeddedWorker.js +16 -0
  153. package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/index.js +63 -0
  154. package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/transfer.js +21 -0
  155. package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/validateOptions.js +9 -0
  156. package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/worker.js +277 -0
  157. package/dist/register.d.ts +10 -0
  158. package/dist/register.js +40 -0
  159. package/dist/typings/index.d.ts +1 -0
  160. package/package.json +71 -98
  161. package/dist/commonjs/app/extend/agent.d.ts +0 -34
  162. package/dist/commonjs/app/extend/agent.js +0 -49
  163. package/dist/commonjs/app/extend/application.d.ts +0 -172
  164. package/dist/commonjs/app/extend/application.js +0 -450
  165. package/dist/commonjs/app/middleware/cluster_app_mock.d.ts +0 -3
  166. package/dist/commonjs/app/middleware/cluster_app_mock.js +0 -101
  167. package/dist/commonjs/app.d.ts +0 -6
  168. package/dist/commonjs/app.js +0 -20
  169. package/dist/commonjs/bootstrap.d.ts +0 -5
  170. package/dist/commonjs/bootstrap.js +0 -59
  171. package/dist/commonjs/index.d.ts +0 -77
  172. package/dist/commonjs/index.js +0 -114
  173. package/dist/commonjs/lib/agent_handler.d.ts +0 -3
  174. package/dist/commonjs/lib/agent_handler.js +0 -28
  175. package/dist/commonjs/lib/app.d.ts +0 -3
  176. package/dist/commonjs/lib/app.js +0 -301
  177. package/dist/commonjs/lib/app_handler.d.ts +0 -5
  178. package/dist/commonjs/lib/app_handler.js +0 -71
  179. package/dist/commonjs/lib/cluster.d.ts +0 -114
  180. package/dist/commonjs/lib/cluster.js +0 -337
  181. package/dist/commonjs/lib/context.d.ts +0 -1
  182. package/dist/commonjs/lib/context.js +0 -16
  183. package/dist/commonjs/lib/format_options.d.ts +0 -5
  184. package/dist/commonjs/lib/format_options.js +0 -100
  185. package/dist/commonjs/lib/inject_context.d.ts +0 -6
  186. package/dist/commonjs/lib/inject_context.js +0 -132
  187. package/dist/commonjs/lib/mock_agent.d.ts +0 -5
  188. package/dist/commonjs/lib/mock_agent.js +0 -49
  189. package/dist/commonjs/lib/mock_custom_loader.d.ts +0 -1
  190. package/dist/commonjs/lib/mock_custom_loader.js +0 -37
  191. package/dist/commonjs/lib/mock_http_server.d.ts +0 -2
  192. package/dist/commonjs/lib/mock_http_server.js +0 -24
  193. package/dist/commonjs/lib/mock_httpclient.d.ts +0 -36
  194. package/dist/commonjs/lib/mock_httpclient.js +0 -147
  195. package/dist/commonjs/lib/parallel/agent.d.ts +0 -20
  196. package/dist/commonjs/lib/parallel/agent.js +0 -125
  197. package/dist/commonjs/lib/parallel/app.d.ts +0 -20
  198. package/dist/commonjs/lib/parallel/app.js +0 -115
  199. package/dist/commonjs/lib/parallel/util.d.ts +0 -3
  200. package/dist/commonjs/lib/parallel/util.js +0 -77
  201. package/dist/commonjs/lib/prerequire.d.ts +0 -1
  202. package/dist/commonjs/lib/prerequire.js +0 -26
  203. package/dist/commonjs/lib/request_call_function.d.ts +0 -1
  204. package/dist/commonjs/lib/request_call_function.js +0 -52
  205. package/dist/commonjs/lib/restore.d.ts +0 -1
  206. package/dist/commonjs/lib/restore.js +0 -16
  207. package/dist/commonjs/lib/start-cluster.d.ts +0 -2
  208. package/dist/commonjs/lib/start-cluster.js +0 -23
  209. package/dist/commonjs/lib/supertest.d.ts +0 -11
  210. package/dist/commonjs/lib/supertest.js +0 -48
  211. package/dist/commonjs/lib/tmp/empty.d.ts +0 -1
  212. package/dist/commonjs/lib/tmp/empty.js +0 -3
  213. package/dist/commonjs/lib/types.d.ts +0 -68
  214. package/dist/commonjs/lib/types.js +0 -3
  215. package/dist/commonjs/lib/utils.d.ts +0 -9
  216. package/dist/commonjs/lib/utils.js +0 -80
  217. package/dist/commonjs/package.json +0 -3
  218. package/dist/commonjs/register.d.ts +0 -8
  219. package/dist/commonjs/register.js +0 -80
  220. package/dist/esm/app/extend/agent.d.ts +0 -34
  221. package/dist/esm/app/extend/agent.js +0 -46
  222. package/dist/esm/app/extend/application.d.ts +0 -172
  223. package/dist/esm/app/extend/application.js +0 -444
  224. package/dist/esm/app/middleware/cluster_app_mock.d.ts +0 -3
  225. package/dist/esm/app/middleware/cluster_app_mock.js +0 -99
  226. package/dist/esm/app.d.ts +0 -6
  227. package/dist/esm/app.js +0 -17
  228. package/dist/esm/bootstrap.d.ts +0 -5
  229. package/dist/esm/bootstrap.js +0 -15
  230. package/dist/esm/index.d.ts +0 -77
  231. package/dist/esm/index.js +0 -91
  232. package/dist/esm/lib/agent_handler.d.ts +0 -3
  233. package/dist/esm/lib/agent_handler.js +0 -24
  234. package/dist/esm/lib/app.d.ts +0 -3
  235. package/dist/esm/lib/app.js +0 -295
  236. package/dist/esm/lib/app_handler.d.ts +0 -5
  237. package/dist/esm/lib/app_handler.js +0 -65
  238. package/dist/esm/lib/cluster.d.ts +0 -114
  239. package/dist/esm/lib/cluster.js +0 -328
  240. package/dist/esm/lib/context.d.ts +0 -1
  241. package/dist/esm/lib/context.js +0 -13
  242. package/dist/esm/lib/format_options.d.ts +0 -5
  243. package/dist/esm/lib/format_options.js +0 -94
  244. package/dist/esm/lib/inject_context.d.ts +0 -6
  245. package/dist/esm/lib/inject_context.js +0 -126
  246. package/dist/esm/lib/mock_agent.d.ts +0 -5
  247. package/dist/esm/lib/mock_agent.js +0 -45
  248. package/dist/esm/lib/mock_custom_loader.d.ts +0 -1
  249. package/dist/esm/lib/mock_custom_loader.js +0 -34
  250. package/dist/esm/lib/mock_http_server.d.ts +0 -2
  251. package/dist/esm/lib/mock_http_server.js +0 -18
  252. package/dist/esm/lib/mock_httpclient.d.ts +0 -36
  253. package/dist/esm/lib/mock_httpclient.js +0 -144
  254. package/dist/esm/lib/parallel/agent.d.ts +0 -20
  255. package/dist/esm/lib/parallel/agent.js +0 -117
  256. package/dist/esm/lib/parallel/app.d.ts +0 -20
  257. package/dist/esm/lib/parallel/app.js +0 -110
  258. package/dist/esm/lib/parallel/util.d.ts +0 -3
  259. package/dist/esm/lib/parallel/util.js +0 -73
  260. package/dist/esm/lib/prerequire.d.ts +0 -1
  261. package/dist/esm/lib/prerequire.js +0 -25
  262. package/dist/esm/lib/request_call_function.d.ts +0 -1
  263. package/dist/esm/lib/request_call_function.js +0 -47
  264. package/dist/esm/lib/restore.d.ts +0 -1
  265. package/dist/esm/lib/restore.js +0 -13
  266. package/dist/esm/lib/start-cluster.d.ts +0 -2
  267. package/dist/esm/lib/start-cluster.js +0 -18
  268. package/dist/esm/lib/supertest.d.ts +0 -11
  269. package/dist/esm/lib/supertest.js +0 -40
  270. package/dist/esm/lib/tmp/empty.d.ts +0 -1
  271. package/dist/esm/lib/tmp/empty.js +0 -2
  272. package/dist/esm/lib/types.d.ts +0 -68
  273. package/dist/esm/lib/types.js +0 -2
  274. package/dist/esm/lib/utils.d.ts +0 -9
  275. package/dist/esm/lib/utils.js +0 -69
  276. package/dist/esm/package.json +0 -3
  277. package/dist/esm/register.d.ts +0 -8
  278. package/dist/esm/register.js +0 -75
  279. package/dist/package.json +0 -4
  280. package/src/app/extend/agent.ts +0 -57
  281. package/src/app/extend/application.ts +0 -512
  282. package/src/app/middleware/cluster_app_mock.ts +0 -102
  283. package/src/app.ts +0 -18
  284. package/src/bootstrap.ts +0 -25
  285. package/src/index.ts +0 -112
  286. package/src/lib/agent_handler.ts +0 -28
  287. package/src/lib/app.ts +0 -314
  288. package/src/lib/app_handler.ts +0 -77
  289. package/src/lib/cluster.ts +0 -363
  290. package/src/lib/context.ts +0 -14
  291. package/src/lib/format_options.ts +0 -103
  292. package/src/lib/inject_context.ts +0 -134
  293. package/src/lib/mock_agent.ts +0 -57
  294. package/src/lib/mock_custom_loader.ts +0 -36
  295. package/src/lib/mock_http_server.ts +0 -19
  296. package/src/lib/mock_httpclient.ts +0 -183
  297. package/src/lib/parallel/agent.ts +0 -128
  298. package/src/lib/parallel/app.ts +0 -123
  299. package/src/lib/parallel/util.ts +0 -66
  300. package/src/lib/prerequire.ts +0 -25
  301. package/src/lib/request_call_function.ts +0 -49
  302. package/src/lib/restore.ts +0 -14
  303. package/src/lib/start-cluster.ts +0 -23
  304. package/src/lib/supertest.ts +0 -45
  305. package/src/lib/tmp/.gitkeep +0 -0
  306. package/src/lib/tmp/empty.ts +0 -0
  307. package/src/lib/utils.ts +0 -82
  308. package/src/register.ts +0 -80
  309. package/src/typings/index.d.ts +0 -4
@@ -0,0 +1,14 @@
1
+ import { getEggOptions } from "./lib/utils.js";
2
+ import { getBootstrapApp, setupApp } from "./lib/app_handler.js";
3
+ import src_default, { mm as proxyMock } from "./index.js";
4
+ import { strict as assert } from "node:assert";
5
+ import path from "node:path";
6
+ import { readJSONSync } from "utility";
7
+
8
+ //#region src/bootstrap.ts
9
+ const options = getEggOptions();
10
+ if (readJSONSync(path.join(options.baseDir || process.cwd(), "package.json")).eggPlugin) throw new Error("DO NOT USE bootstrap to test plugin");
11
+ const app = setupApp();
12
+
13
+ //#endregion
14
+ export { app, assert, getBootstrapApp, src_default as mm, proxyMock as mock };
@@ -0,0 +1,81 @@
1
+ import { MockHttpClientMethod, MockResponseCallbackOptions, MockResultFunction, MockResultOptions, ResultObject } from "./lib/mock_httpclient.js";
2
+ import { MockAgent, MockApplicationOptions, MockClusterApplicationOptions, MockClusterOptions, MockOption, MockOptions } from "./lib/types.js";
3
+ import ApplicationUnittest from "./app/extend/application.js";
4
+ import { MockClusterApplication, createCluster } from "./lib/cluster.js";
5
+ import { createApp } from "./lib/app.js";
6
+ import { restore as restore$1 } from "./lib/restore.js";
7
+ import { setGetAppCallback } from "./lib/app_handler.js";
8
+ import * as mm0 from "mm";
9
+ import { mock } from "mm";
10
+
11
+ //#region src/index.d.ts
12
+ declare const mock$1: {
13
+ restore: typeof restore$1;
14
+ /**
15
+ * Create a egg mocked application
16
+ * @function mm#app
17
+ * @param {Object} [options]
18
+ * - {String} baseDir - The directory of the application
19
+ * - {Object} plugins - Custom you plugins
20
+ * - {String} framework - The directory of the egg framework
21
+ * - {Boolean} [true] cache - Cache application based on baseDir
22
+ * - {Boolean} [true] coverage - Switch on process coverage, but it'll be slower
23
+ * - {Boolean} [true] clean - Remove $baseDir/logs
24
+ * @return {App} return {@link Application}
25
+ * @example
26
+ * ```js
27
+ * const app = mm.app();
28
+ * ```
29
+ */
30
+ app: typeof createApp;
31
+ /**
32
+ * Create a egg mocked cluster application
33
+ * @function mm#cluster
34
+ * @see ClusterApplication
35
+ */
36
+ cluster: typeof createCluster;
37
+ /**
38
+ * mock the serverEnv of Egg
39
+ * @member {Function} mm#env
40
+ * @param {String} env - contain default, test, prod, local, unittest
41
+ * @see https://github.com/eggjs/egg-core/blob/master/lib/loader/egg_loader.js#L78
42
+ */
43
+ env(env: string): void;
44
+ /**
45
+ * mock console level
46
+ * @param {String} level - logger level
47
+ */
48
+ consoleLevel(level: string): void;
49
+ home(homePath?: string): void;
50
+ setGetAppCallback: typeof setGetAppCallback;
51
+ isMocked: typeof mm0.isMocked;
52
+ mock: typeof mock;
53
+ mm: typeof mock;
54
+ datas: typeof mm0.datas;
55
+ mockDatas: typeof mm0.datas;
56
+ data: typeof mm0.data;
57
+ mockData: typeof mm0.data;
58
+ dataWithAsyncDispose: typeof mm0.dataWithAsyncDispose;
59
+ empty: typeof mm0.empty;
60
+ mockEmpty: typeof mm0.empty;
61
+ error: typeof mm0.error;
62
+ mockError: typeof mm0.error;
63
+ spy: typeof mm0.spy;
64
+ errorOnce: typeof mm0.errorOnce;
65
+ syncError: typeof mm0.syncError;
66
+ syncEmpty: typeof mm0.syncEmpty;
67
+ syncData: typeof mm0.syncData;
68
+ http: {
69
+ request: (url: mm0.RequestURL, data: mm0.ResponseData, headers?: Record<string, any>, delay?: number) => void;
70
+ requestError: (url: mm0.RequestURL, reqError?: mm0.MockError, resError?: mm0.MockError, delay?: number) => void;
71
+ };
72
+ https: {
73
+ request: (url: mm0.RequestURL, data: mm0.ResponseData, headers?: Record<string, any>, delay?: number) => void;
74
+ requestError: (url: mm0.RequestURL, reqError?: mm0.MockError, resError?: mm0.MockError, delay?: number) => void;
75
+ };
76
+ spawn: typeof mm0.spawn;
77
+ classMethod: typeof mm0.classMethod;
78
+ };
79
+ declare const proxyMock: ((target: any, property: PropertyKey, value?: any) => void) & typeof mock$1;
80
+ //#endregion
81
+ export { MockAgent, type ApplicationUnittest as MockApplication, MockApplicationOptions, type MockClusterApplication, MockClusterApplicationOptions, MockClusterOptions, MockHttpClientMethod, MockOption, MockOptions, MockResponseCallbackOptions, MockResultFunction, MockResultOptions, ResultObject, createApp, createCluster, proxyMock as default, proxyMock as mm, proxyMock as mock, setGetAppCallback };
package/dist/index.js ADDED
@@ -0,0 +1,47 @@
1
+ import { createCluster } from "./lib/cluster.js";
2
+ import { createApp } from "./lib/app.js";
3
+ import { restore as restore$1 } from "./lib/restore.js";
4
+ import { setGetAppCallback } from "./lib/app_handler.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 { createApp, createCluster, src_default as default, proxyMock as mm, proxyMock as mock, setGetAppCallback };
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,35 @@
1
+ import { __require, __toESM } from "./_virtual/rolldown_runtime.js";
2
+ import { injectContext } from "./lib/inject_context.js";
3
+ import { require_mocha } from "./node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/index.js";
4
+ import { debuglog } from "node:util";
5
+ import { getRequire } from "@eggjs/utils";
6
+
7
+ //#region src/inject_mocha.ts
8
+ var import_mocha = /* @__PURE__ */ __toESM(require_mocha(), 1);
9
+ const debug = debuglog("egg/mock/inject_mocha");
10
+ /**
11
+ * Find active node mocha instances.
12
+ */
13
+ function findNodeJSMocha() {
14
+ let children;
15
+ if (typeof __require === "function") children = __require.cache || {};
16
+ else {
17
+ children = getRequire().cache || {};
18
+ debug("createRequire on esm");
19
+ }
20
+ return Object.keys(children).filter(function(child) {
21
+ const val = children[child].exports;
22
+ return typeof val === "function" && val.name === "Mocha";
23
+ }).map(function(child) {
24
+ return children[child].exports;
25
+ });
26
+ }
27
+ const modules = findNodeJSMocha();
28
+ debug("modules length: %s", modules.length);
29
+ for (const module of modules) {
30
+ if (!module) continue;
31
+ injectContext(module);
32
+ }
33
+
34
+ //#endregion
35
+ export { };
@@ -0,0 +1,7 @@
1
+ import { MockAgent } from "./parallel/agent.js";
2
+
3
+ //#region src/lib/agent_handler.d.ts
4
+ declare function setupAgent(): Promise<MockAgent>;
5
+ declare function closeAgent(): Promise<void>;
6
+ //#endregion
7
+ export { closeAgent, setupAgent };
@@ -0,0 +1,26 @@
1
+ import { getEggOptions } from "./utils.js";
2
+ import { createAgent } from "./parallel/agent.js";
3
+ import { debuglog } from "node:util";
4
+
5
+ //#region src/lib/agent_handler.ts
6
+ const debug = debuglog("egg/mock/lib/agent_handler");
7
+ let agent;
8
+ async function setupAgent() {
9
+ debug("setupAgent call, env.ENABLE_MOCHA_PARALLEL: %s, process.env.AUTO_AGENT: %s, agent: %s", process.env.ENABLE_MOCHA_PARALLEL, process.env.AUTO_AGENT, !!agent);
10
+ if (agent) {
11
+ await agent.ready();
12
+ return agent;
13
+ }
14
+ if (process.env.ENABLE_MOCHA_PARALLEL && process.env.AUTO_AGENT) {
15
+ agent = createAgent(getEggOptions());
16
+ await agent.ready();
17
+ }
18
+ return agent;
19
+ }
20
+ async function closeAgent() {
21
+ debug("setupAgent call, agent: %s", !!agent);
22
+ if (agent) await agent.close();
23
+ }
24
+
25
+ //#endregion
26
+ export { closeAgent, setupAgent };
@@ -0,0 +1,7 @@
1
+ import { MockOptions } from "./types.js";
2
+ import ApplicationUnittest from "../app/extend/application.js";
3
+
4
+ //#region src/lib/app.d.ts
5
+ declare function createApp(createOptions?: MockOptions): ApplicationUnittest;
6
+ //#endregion
7
+ export { createApp };
@@ -0,0 +1,251 @@
1
+ import { createServer } from "./mock_http_server.js";
2
+ import { getProperty, getSourceDirname, rimraf, 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/extend/application.js";
7
+ import "../app/extend/agent.js";
8
+ import { strict } from "node:assert";
9
+ import path from "node:path";
10
+ import { debuglog } from "node:util";
11
+ import os from "node:os";
12
+ import { importModule } from "@eggjs/utils";
13
+ import { Base } from "sdk-base";
14
+ import { detectPort } from "detect-port";
15
+
16
+ //#region src/lib/app.ts
17
+ const debug = debuglog("egg/mock/lib/app");
18
+ const apps = /* @__PURE__ */ new Map();
19
+ const APP_INIT = Symbol("appInit");
20
+ const MESSENGER = Symbol("messenger");
21
+ const MOCK_APP_METHOD = [
22
+ "ready",
23
+ "closed",
24
+ "isClosed",
25
+ "close",
26
+ "_agent",
27
+ "_app",
28
+ "on",
29
+ "once",
30
+ "then"
31
+ ];
32
+ var MockApplicationWorker = class extends Base {
33
+ _agent;
34
+ _app;
35
+ baseDir;
36
+ [APP_INIT] = false;
37
+ _initOnListeners;
38
+ _initOnceListeners;
39
+ constructor(options) {
40
+ super({
41
+ initMethod: "_init",
42
+ ...options
43
+ });
44
+ this.baseDir = options.baseDir;
45
+ this._initOnListeners = /* @__PURE__ */ new Set();
46
+ this._initOnceListeners = /* @__PURE__ */ new Set();
47
+ }
48
+ async _init() {
49
+ if (this.options.beforeInit) {
50
+ await this.options.beforeInit(this);
51
+ this.options.beforeInit = void 0;
52
+ }
53
+ if (this.options.clean !== false) {
54
+ const logDir = path.join(this.options.baseDir, "logs");
55
+ try {
56
+ if (os.platform() === "win32") await sleep(1e3);
57
+ await rimraf(logDir);
58
+ } catch (err) {
59
+ console.error(`remove log dir ${logDir} failed: ${err.stack}`);
60
+ }
61
+ const runDir = path.join(this.options.baseDir, "run");
62
+ try {
63
+ if (os.platform() === "win32") await sleep(1e3);
64
+ await rimraf(runDir);
65
+ } catch (err) {
66
+ console.error(`remove run dir ${runDir} failed: ${err.stack}`);
67
+ }
68
+ }
69
+ this.options.clusterPort = await detectPort();
70
+ debug("[init] options: %o", this.options);
71
+ const egg = await importModule(this.options.framework);
72
+ strict(egg.Agent, `should export Agent class from framework ${this.options.framework}`);
73
+ const Agent = egg.Agent;
74
+ const agent = this._agent = new Agent({ ...this.options });
75
+ debug("agent instantiate");
76
+ await agent.ready();
77
+ debug("agent ready");
78
+ const app = this._app = new (bindMessenger(egg.Application, agent))({ ...this.options });
79
+ app.agent = agent;
80
+ Reflect.set(agent, "app", app);
81
+ Object.assign(app.context, context);
82
+ debug("app instantiate");
83
+ this[APP_INIT] = true;
84
+ debug("this[APP_INIT] = true");
85
+ this.#bindEvent();
86
+ debug("http server instantiate");
87
+ createServer(app);
88
+ await app.ready();
89
+ setCustomLoader(app);
90
+ const msg = {
91
+ action: "egg-ready",
92
+ data: this.options
93
+ };
94
+ app.messenger.onMessage(msg);
95
+ agent.messenger.onMessage(msg);
96
+ debug("app ready");
97
+ }
98
+ #bindEvent() {
99
+ debug("bind cache events to app");
100
+ for (const args of this._initOnListeners) {
101
+ debug("on(%s), use cache and pass to app", args);
102
+ this._app.on(args[0], args[1]);
103
+ this.removeListener(args[0], args[1]);
104
+ }
105
+ for (const args of this._initOnceListeners) {
106
+ debug("once(%s), use cache and pass to app", args);
107
+ this._app.once(args[0], args[1]);
108
+ this.removeListener(args[0], args[1]);
109
+ }
110
+ }
111
+ on(...args) {
112
+ if (this[APP_INIT]) {
113
+ debug("on(%s), pass to app", args);
114
+ this._app.on(args[0], args[1]);
115
+ } else {
116
+ debug("on(%s), cache it because app has not init", args);
117
+ this._initOnListeners.add(args);
118
+ super.on(args[0], args[1]);
119
+ }
120
+ return this;
121
+ }
122
+ once(...args) {
123
+ if (this[APP_INIT]) {
124
+ debug("once(%s), pass to app", args);
125
+ this._app.once(args[0], args[1]);
126
+ } else {
127
+ debug("once(%s), cache it because app has not init", args);
128
+ this._initOnceListeners.add(args);
129
+ super.on(args[0], args[1]);
130
+ }
131
+ return this;
132
+ }
133
+ /**
134
+ * close app
135
+ */
136
+ async _close() {
137
+ const baseDir = this.baseDir;
138
+ if (this._app) await this._app.close();
139
+ else await sleep(200);
140
+ if (this._agent) await this._agent.close();
141
+ apps.delete(baseDir);
142
+ debug("delete app cache %s, remain %s", baseDir, [...apps.keys()]);
143
+ if (os.platform() === "win32") await sleep(1e3);
144
+ }
145
+ /**
146
+ * @deprecated please use isClosed instead, keep compatible with old version
147
+ */
148
+ get closed() {
149
+ return this.isClosed;
150
+ }
151
+ };
152
+ function createApp(createOptions) {
153
+ const options = formatOptions(createOptions);
154
+ debug("[createApp] options: %o", options);
155
+ if (options.cache && apps.has(options.baseDir)) {
156
+ const app = apps.get(options.baseDir);
157
+ if (app && !app.isClosed) {
158
+ debug("use cache app %s", options.baseDir);
159
+ return app;
160
+ }
161
+ apps.delete(options.baseDir);
162
+ }
163
+ const appWorker = new MockApplicationWorker(options);
164
+ const proxyApp = new Proxy(appWorker, {
165
+ get(target, prop) {
166
+ if (MOCK_APP_METHOD.includes(prop)) return getProperty(target, prop);
167
+ if (!target[APP_INIT]) throw new Error(`can't get ${prop} before ready`);
168
+ debug("proxy handler.get %s", prop);
169
+ return target._app[prop];
170
+ },
171
+ set(target, prop, value) {
172
+ if (MOCK_APP_METHOD.includes(prop)) return true;
173
+ if (!target[APP_INIT]) throw new Error(`can't set ${prop} before ready`);
174
+ debug("proxy handler.set %s", prop);
175
+ target._app[prop] = value;
176
+ return true;
177
+ },
178
+ defineProperty(target, prop, descriptor) {
179
+ if (MOCK_APP_METHOD.includes(prop)) return true;
180
+ if (!target[APP_INIT]) throw new Error(`can't defineProperty ${prop} before ready`);
181
+ debug("proxy handler.defineProperty %s", prop);
182
+ Object.defineProperty(target._app, prop, descriptor);
183
+ return true;
184
+ },
185
+ deleteProperty(target, prop) {
186
+ if (MOCK_APP_METHOD.includes(prop)) return true;
187
+ if (!target[APP_INIT]) throw new Error(`can't delete ${prop} before ready`);
188
+ debug("proxy handler.deleteProperty %s", prop);
189
+ delete target._app[prop];
190
+ return true;
191
+ },
192
+ getOwnPropertyDescriptor(target, prop) {
193
+ if (MOCK_APP_METHOD.includes(prop)) return Object.getOwnPropertyDescriptor(target, prop);
194
+ if (!target[APP_INIT]) throw new Error(`can't getOwnPropertyDescriptor ${prop} before ready`);
195
+ debug("proxy handler.getOwnPropertyDescriptor %s", prop);
196
+ return Object.getOwnPropertyDescriptor(target._app, prop);
197
+ },
198
+ getPrototypeOf(target) {
199
+ if (!target[APP_INIT]) throw new Error("can't getPrototypeOf before ready");
200
+ debug("proxy handler.getPrototypeOf %s");
201
+ return Object.getPrototypeOf(target._app);
202
+ }
203
+ });
204
+ apps.set(options.baseDir, proxyApp);
205
+ return proxyApp;
206
+ }
207
+ function bindMessenger(ApplicationClass, agent) {
208
+ const agentMessenger = agent.messenger;
209
+ return class MessengerApplication extends ApplicationClass {
210
+ [MESSENGER];
211
+ constructor(options) {
212
+ super(options);
213
+ this.messenger.sendRandom = (action, data) => {
214
+ this.messenger.sendToAgent(action, data);
215
+ };
216
+ agentMessenger.on("egg-ready", () => {
217
+ agentMessenger.sendRandom = (action, data) => {
218
+ agentMessenger.sendToApp(action, data);
219
+ return agentMessenger;
220
+ };
221
+ });
222
+ agentMessenger.send = new Proxy(agentMessenger.send, { apply: this._sendMessage.bind(this) });
223
+ }
224
+ _sendMessage(_target, _thisArg, [action, data, to]) {
225
+ const appMessenger = this.messenger;
226
+ setImmediate(() => {
227
+ if (to === "app") appMessenger.onMessage({
228
+ action,
229
+ data
230
+ });
231
+ else agentMessenger.onMessage({
232
+ action,
233
+ data
234
+ });
235
+ });
236
+ }
237
+ get messenger() {
238
+ return this[MESSENGER];
239
+ }
240
+ set messenger(m) {
241
+ m.send = new Proxy(m.send, { apply: this._sendMessage.bind(this) });
242
+ this[MESSENGER] = m;
243
+ }
244
+ get [Symbol.for("egg#eggPath")]() {
245
+ return path.join(getSourceDirname(), "lib/tmp");
246
+ }
247
+ };
248
+ }
249
+
250
+ //#endregion
251
+ export { createApp };
@@ -0,0 +1,9 @@
1
+ import ApplicationUnittest from "../app/extend/application.js";
2
+
3
+ //#region src/lib/app_handler.d.ts
4
+ declare function setupApp(): ApplicationUnittest;
5
+ declare function setGetAppCallback(cb: (suite: unknown, test?: unknown) => any): void;
6
+ declare function getApp(suite?: unknown, test?: unknown): Promise<any>;
7
+ declare function getBootstrapApp(): ApplicationUnittest;
8
+ //#endregion
9
+ export { getApp, getBootstrapApp, setGetAppCallback, setupApp };
@@ -0,0 +1,56 @@
1
+ import { getEggOptions } from "./utils.js";
2
+ import "../app/extend/application.js";
3
+ import { createApp as createApp$1 } from "./app.js";
4
+ import { restore } from "./restore.js";
5
+ import { createApp } from "./parallel/app.js";
6
+ import { setupAgent } from "./agent_handler.js";
7
+ import { debuglog } from "node:util";
8
+
9
+ //#region src/lib/app_handler.ts
10
+ const debug = debuglog("egg/mock/lib/app_handler");
11
+ globalThis.__eggMockAppInstance = null;
12
+ function setupApp() {
13
+ let app = globalThis.__eggMockAppInstance;
14
+ if (app) {
15
+ debug("return exists app");
16
+ return app;
17
+ }
18
+ const options = getEggOptions();
19
+ debug("env.ENABLE_MOCHA_PARALLEL: %s, process.env.AUTO_AGENT: %s", process.env.ENABLE_MOCHA_PARALLEL, process.env.AUTO_AGENT);
20
+ if (process.env.ENABLE_MOCHA_PARALLEL && process.env.AUTO_AGENT) {
21
+ app = createApp({
22
+ ...options,
23
+ beforeInit: async (parallelApp) => {
24
+ const agent = await setupAgent();
25
+ parallelApp.options.clusterPort = agent.options.clusterPort;
26
+ debug("mockParallelApp beforeInit get clusterPort: %s", parallelApp.options.clusterPort);
27
+ }
28
+ });
29
+ debug("mockParallelApp app: %s", !!app);
30
+ } else {
31
+ app = createApp$1(options);
32
+ if (typeof beforeAll === "function") beforeAll(() => app.ready());
33
+ if (typeof afterEach === "function") {
34
+ afterEach(() => app.backgroundTasksFinished());
35
+ afterEach(restore);
36
+ }
37
+ }
38
+ globalThis.__eggMockAppInstance = app;
39
+ return app;
40
+ }
41
+ let getAppCallback;
42
+ function setGetAppCallback(cb) {
43
+ getAppCallback = cb;
44
+ }
45
+ async function getApp(suite, test) {
46
+ if (getAppCallback) return getAppCallback(suite, test);
47
+ const app = globalThis.__eggMockAppInstance;
48
+ if (app) await app.ready();
49
+ return app;
50
+ }
51
+ function getBootstrapApp() {
52
+ return globalThis.__eggMockAppInstance;
53
+ }
54
+
55
+ //#endregion
56
+ export { getApp, getBootstrapApp, setGetAppCallback, setupApp };
@@ -0,0 +1,126 @@
1
+ import { EggTestRequest } from "./supertest.js";
2
+ import { MockClusterApplicationOptions, MockClusterOptions } from "./types.js";
3
+ import ApplicationUnittest from "../app/extend/application.js";
4
+ import { Coffee } from "coffee";
5
+
6
+ //#region src/lib/cluster.d.ts
7
+ declare global {
8
+ var eggMockMasterPort: number;
9
+ }
10
+ /**
11
+ * A cluster version of egg.Application, you can test with supertest
12
+ * @example
13
+ * ```js
14
+ * const mm = require('mm');
15
+ * const request = require('supertest');
16
+ *
17
+ * describe('ClusterApplication', () => {
18
+ * let app;
19
+ * before(function (done) {
20
+ * app = mm.cluster({ baseDir });
21
+ * app.ready(done);
22
+ * });
23
+ *
24
+ * after(function () {
25
+ * app.close();
26
+ * });
27
+ *
28
+ * it('should 200', function (done) {
29
+ * request(app.callback())
30
+ * .get('/')
31
+ * .expect(200, done);
32
+ * });
33
+ * });
34
+ */
35
+ declare class ClusterApplication extends Coffee {
36
+ [key: string | symbol]: any;
37
+ options: MockClusterApplicationOptions;
38
+ port: number;
39
+ baseDir: string;
40
+ closed: boolean;
41
+ private _address;
42
+ /**
43
+ * @class
44
+ * @param {Object} options
45
+ * - {String} baseDir - The directory of the application
46
+ * - {Object} plugins - Custom you plugins
47
+ * - {String} framework - The directory of the egg framework
48
+ * - {Boolean} [cache=true] - Cache application based on baseDir
49
+ * - {Boolean} [coverage=true] - Switch on process coverage, but it'll be slower
50
+ * - {Boolean} [clean=true] - Remove $baseDir/logs
51
+ * - {Object} [opt] - opt pass to coffee, such as { execArgv: ['--debug'] }
52
+ * ```
53
+ */
54
+ constructor(options: MockClusterApplicationOptions);
55
+ /**
56
+ * the process that forked
57
+ * @member {ChildProcess}
58
+ */
59
+ get process(): any;
60
+ /**
61
+ * Compatible API for supertest
62
+ */
63
+ callback(): this;
64
+ /**
65
+ * Compatible API for supertest
66
+ * @member {String} url
67
+ * @private
68
+ */
69
+ get url(): string;
70
+ /**
71
+ * Compatible API for supertest
72
+ */
73
+ address(): {
74
+ port: number;
75
+ address: string | undefined;
76
+ };
77
+ /**
78
+ * Compatible API for supertest
79
+ */
80
+ listen(): this;
81
+ /**
82
+ * kill the process
83
+ */
84
+ close(): Promise<void>;
85
+ get isClosed(): boolean;
86
+ get router(): {
87
+ pathFor(url: string): any;
88
+ };
89
+ /**
90
+ * get app[property] value in app worker
91
+ */
92
+ getAppInstanceProperty(property: string): any;
93
+ /**
94
+ * collection logger message, then can be use on `expectLog()`
95
+ * it's different from `app.expectLog()`, only support string params.
96
+ *
97
+ * @param {String} [logger] - logger instance name, default is `logger`
98
+ * @function ClusterApplication#expectLog
99
+ */
100
+ mockLog(logger?: string): void;
101
+ /**
102
+ * expect str in the logger
103
+ * it's different from `app.expectLog()`, only support string params.
104
+ *
105
+ * @param {String} str - test str
106
+ * @param {String} [logger] - logger instance name, default is `logger`
107
+ * @function ClusterApplication#expectLog
108
+ */
109
+ expectLog(str: string, logger?: string): void;
110
+ /**
111
+ * not expect str in the logger
112
+ * it's different from `app.notExpectLog()`, only support string params.
113
+ *
114
+ * @param {String} str - test str
115
+ * @param {String} [logger] - logger instance name, default is `logger`
116
+ * @function ClusterApplication#notExpectLog
117
+ */
118
+ notExpectLog(str: string, logger?: string): void;
119
+ httpRequest(): EggTestRequest;
120
+ _callFunctionOnAppWorker(method: string, args?: any[], property?: any, needResult?: boolean): any;
121
+ }
122
+ type MockClusterApplication = ClusterApplication & ApplicationUnittest;
123
+ declare function createCluster(initOptions?: MockClusterOptions): MockClusterApplication;
124
+ declare function restore(): Promise<void>;
125
+ //#endregion
126
+ export { ClusterApplication, MockClusterApplication, createCluster, restore };