@eggjs/mock 6.0.6 → 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 -171
- 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 -171
- 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 -510
- 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,505 @@
|
|
|
1
|
+
import { __commonJS, __require } from "../../../../../../_virtual/rolldown_runtime.js";
|
|
2
|
+
import { require_he } from "../../../../he@1.2.0/node_modules/he/he.js";
|
|
3
|
+
|
|
4
|
+
//#region ../../node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/utils.js
|
|
5
|
+
var require_utils = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/utils.js": ((exports) => {
|
|
6
|
+
/**
|
|
7
|
+
* Various utility functions used throughout Mocha's codebase.
|
|
8
|
+
* @module utils
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Module dependencies.
|
|
12
|
+
*/
|
|
13
|
+
var path = __require("node:path");
|
|
14
|
+
var util = __require("node:util");
|
|
15
|
+
var he = require_he();
|
|
16
|
+
const MOCHA_ID_PROP_NAME = "__mocha_id__";
|
|
17
|
+
/**
|
|
18
|
+
* Inherit the prototype methods from one constructor into another.
|
|
19
|
+
*
|
|
20
|
+
* @param {function} ctor - Constructor function which needs to inherit the
|
|
21
|
+
* prototype.
|
|
22
|
+
* @param {function} superCtor - Constructor function to inherit prototype from.
|
|
23
|
+
* @throws {TypeError} if either constructor is null, or if super constructor
|
|
24
|
+
* lacks a prototype.
|
|
25
|
+
*/
|
|
26
|
+
exports.inherits = util.inherits;
|
|
27
|
+
/**
|
|
28
|
+
* Escape special characters in the given string of html.
|
|
29
|
+
*
|
|
30
|
+
* @private
|
|
31
|
+
* @param {string} html
|
|
32
|
+
* @return {string}
|
|
33
|
+
*/
|
|
34
|
+
exports.escape = function(html) {
|
|
35
|
+
return he.encode(String(html), { useNamedReferences: false });
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Test if the given obj is type of string.
|
|
39
|
+
*
|
|
40
|
+
* @private
|
|
41
|
+
* @param {Object} obj
|
|
42
|
+
* @return {boolean}
|
|
43
|
+
*/
|
|
44
|
+
exports.isString = function(obj) {
|
|
45
|
+
return typeof obj === "string";
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Compute a slug from the given `str`.
|
|
49
|
+
*
|
|
50
|
+
* @private
|
|
51
|
+
* @param {string} str
|
|
52
|
+
* @return {string}
|
|
53
|
+
*/
|
|
54
|
+
exports.slug = function(str) {
|
|
55
|
+
return str.toLowerCase().replace(/\s+/g, "-").replace(/[^-\w]/g, "").replace(/-{2,}/g, "-");
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Strip the function definition from `str`, and re-indent for pre whitespace.
|
|
59
|
+
*
|
|
60
|
+
* @param {string} str
|
|
61
|
+
* @return {string}
|
|
62
|
+
*/
|
|
63
|
+
exports.clean = function(str) {
|
|
64
|
+
str = str.replace(/\r\n?|[\n\u2028\u2029]/g, "\n").replace(/^\uFEFF/, "").replace(/^function(?:\s*|\s[^(]*)\([^)]*\)\s*\{((?:.|\n)*?)\}$|^\([^)]*\)\s*=>\s*(?:\{((?:.|\n)*?)\}|((?:.|\n)*))$/, "$1$2$3");
|
|
65
|
+
var spaces = str.match(/^\n?( *)/)[1].length;
|
|
66
|
+
var tabs = str.match(/^\n?(\t*)/)[1].length;
|
|
67
|
+
var re = new RegExp("^\n?" + (tabs ? " " : " ") + "{" + (tabs || spaces) + "}", "gm");
|
|
68
|
+
str = str.replace(re, "");
|
|
69
|
+
return str.trim();
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* If a value could have properties, and has none, this function is called,
|
|
73
|
+
* which returns a string representation of the empty value.
|
|
74
|
+
*
|
|
75
|
+
* Functions w/ no properties return `'[Function]'`
|
|
76
|
+
* Arrays w/ length === 0 return `'[]'`
|
|
77
|
+
* Objects w/ no properties return `'{}'`
|
|
78
|
+
* All else: return result of `value.toString()`
|
|
79
|
+
*
|
|
80
|
+
* @private
|
|
81
|
+
* @param {*} value The value to inspect.
|
|
82
|
+
* @param {string} typeHint The type of the value
|
|
83
|
+
* @returns {string}
|
|
84
|
+
*/
|
|
85
|
+
function emptyRepresentation(value, typeHint) {
|
|
86
|
+
switch (typeHint) {
|
|
87
|
+
case "function": return "[Function]";
|
|
88
|
+
case "object": return "{}";
|
|
89
|
+
case "array": return "[]";
|
|
90
|
+
default: return value.toString();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Takes some variable and asks `Object.prototype.toString()` what it thinks it
|
|
95
|
+
* is.
|
|
96
|
+
*
|
|
97
|
+
* @private
|
|
98
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString
|
|
99
|
+
* @param {*} value The value to test.
|
|
100
|
+
* @returns {string} Computed type
|
|
101
|
+
* @example
|
|
102
|
+
* canonicalType({}) // 'object'
|
|
103
|
+
* canonicalType([]) // 'array'
|
|
104
|
+
* canonicalType(1) // 'number'
|
|
105
|
+
* canonicalType(false) // 'boolean'
|
|
106
|
+
* canonicalType(Infinity) // 'number'
|
|
107
|
+
* canonicalType(null) // 'null'
|
|
108
|
+
* canonicalType(new Date()) // 'date'
|
|
109
|
+
* canonicalType(/foo/) // 'regexp'
|
|
110
|
+
* canonicalType('type') // 'string'
|
|
111
|
+
* canonicalType(global) // 'global'
|
|
112
|
+
* canonicalType(new String('foo') // 'object'
|
|
113
|
+
* canonicalType(async function() {}) // 'asyncfunction'
|
|
114
|
+
* canonicalType(Object.create(null)) // 'null-prototype'
|
|
115
|
+
*/
|
|
116
|
+
var canonicalType = exports.canonicalType = function canonicalType$1(value) {
|
|
117
|
+
if (value === void 0) return "undefined";
|
|
118
|
+
else if (value === null) return "null";
|
|
119
|
+
else if (Buffer.isBuffer(value)) return "buffer";
|
|
120
|
+
else if (Object.getPrototypeOf(value) === null) return "null-prototype";
|
|
121
|
+
return Object.prototype.toString.call(value).replace(/^\[.+\s(.+?)]$/, "$1").toLowerCase();
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
*
|
|
125
|
+
* Returns a general type or data structure of a variable
|
|
126
|
+
* @private
|
|
127
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures
|
|
128
|
+
* @param {*} value The value to test.
|
|
129
|
+
* @returns {string} One of undefined, boolean, number, string, bigint, symbol, object
|
|
130
|
+
* @example
|
|
131
|
+
* type({}) // 'object'
|
|
132
|
+
* type([]) // 'array'
|
|
133
|
+
* type(1) // 'number'
|
|
134
|
+
* type(false) // 'boolean'
|
|
135
|
+
* type(Infinity) // 'number'
|
|
136
|
+
* type(null) // 'null'
|
|
137
|
+
* type(new Date()) // 'object'
|
|
138
|
+
* type(/foo/) // 'object'
|
|
139
|
+
* type('type') // 'string'
|
|
140
|
+
* type(global) // 'object'
|
|
141
|
+
* type(new String('foo') // 'string'
|
|
142
|
+
*/
|
|
143
|
+
exports.type = function type(value) {
|
|
144
|
+
if (value === null) return "null";
|
|
145
|
+
const primitives = new Set([
|
|
146
|
+
"undefined",
|
|
147
|
+
"boolean",
|
|
148
|
+
"number",
|
|
149
|
+
"string",
|
|
150
|
+
"bigint",
|
|
151
|
+
"symbol"
|
|
152
|
+
]);
|
|
153
|
+
const _type = typeof value;
|
|
154
|
+
if (_type === "function") return _type;
|
|
155
|
+
if (primitives.has(_type)) return _type;
|
|
156
|
+
if (value instanceof String) return "string";
|
|
157
|
+
if (value instanceof Error) return "error";
|
|
158
|
+
if (Array.isArray(value)) return "array";
|
|
159
|
+
return _type;
|
|
160
|
+
};
|
|
161
|
+
/**
|
|
162
|
+
* Stringify `value`. Different behavior depending on type of value:
|
|
163
|
+
*
|
|
164
|
+
* - If `value` is undefined or null, return `'[undefined]'` or `'[null]'`, respectively.
|
|
165
|
+
* - If `value` is not an object, function or array, return result of `value.toString()` wrapped in double-quotes.
|
|
166
|
+
* - If `value` is an *empty* object, function, or array, return result of function
|
|
167
|
+
* {@link emptyRepresentation}.
|
|
168
|
+
* - If `value` has properties, call {@link exports.canonicalize} on it, then return result of
|
|
169
|
+
* JSON.stringify().
|
|
170
|
+
*
|
|
171
|
+
* @private
|
|
172
|
+
* @see exports.type
|
|
173
|
+
* @param {*} value
|
|
174
|
+
* @return {string}
|
|
175
|
+
*/
|
|
176
|
+
exports.stringify = function(value) {
|
|
177
|
+
var typeHint = canonicalType(value);
|
|
178
|
+
if (!~[
|
|
179
|
+
"object",
|
|
180
|
+
"array",
|
|
181
|
+
"function",
|
|
182
|
+
"null-prototype"
|
|
183
|
+
].indexOf(typeHint)) {
|
|
184
|
+
if (typeHint === "buffer") {
|
|
185
|
+
var json = Buffer.prototype.toJSON.call(value);
|
|
186
|
+
return jsonStringify(json.data && json.type ? json.data : json, 2).replace(/,(\n|$)/g, "$1");
|
|
187
|
+
}
|
|
188
|
+
if (typeHint === "string" && typeof value === "object") {
|
|
189
|
+
value = value.split("").reduce(function(acc, char, idx) {
|
|
190
|
+
acc[idx] = char;
|
|
191
|
+
return acc;
|
|
192
|
+
}, {});
|
|
193
|
+
typeHint = "object";
|
|
194
|
+
} else return jsonStringify(value);
|
|
195
|
+
}
|
|
196
|
+
for (var prop in value) if (Object.prototype.hasOwnProperty.call(value, prop)) return jsonStringify(exports.canonicalize(value, null, typeHint), 2).replace(/,(\n|$)/g, "$1");
|
|
197
|
+
return emptyRepresentation(value, typeHint);
|
|
198
|
+
};
|
|
199
|
+
/**
|
|
200
|
+
* like JSON.stringify but more sense.
|
|
201
|
+
*
|
|
202
|
+
* @private
|
|
203
|
+
* @param {Object} object
|
|
204
|
+
* @param {number=} spaces
|
|
205
|
+
* @param {number=} depth
|
|
206
|
+
* @returns {*}
|
|
207
|
+
*/
|
|
208
|
+
function jsonStringify(object, spaces, depth) {
|
|
209
|
+
if (typeof spaces === "undefined") return _stringify(object);
|
|
210
|
+
depth = depth || 1;
|
|
211
|
+
var space = spaces * depth;
|
|
212
|
+
var str = Array.isArray(object) ? "[" : "{";
|
|
213
|
+
var end = Array.isArray(object) ? "]" : "}";
|
|
214
|
+
var length = typeof object.length === "number" ? object.length : Object.keys(object).length;
|
|
215
|
+
function repeat(s, n) {
|
|
216
|
+
return new Array(n).join(s);
|
|
217
|
+
}
|
|
218
|
+
function _stringify(val) {
|
|
219
|
+
switch (canonicalType(val)) {
|
|
220
|
+
case "null":
|
|
221
|
+
case "undefined":
|
|
222
|
+
val = "[" + val + "]";
|
|
223
|
+
break;
|
|
224
|
+
case "array":
|
|
225
|
+
case "object":
|
|
226
|
+
val = jsonStringify(val, spaces, depth + 1);
|
|
227
|
+
break;
|
|
228
|
+
case "boolean":
|
|
229
|
+
case "regexp":
|
|
230
|
+
case "symbol":
|
|
231
|
+
case "number":
|
|
232
|
+
val = val === 0 && 1 / val === -Infinity ? "-0" : val.toString();
|
|
233
|
+
break;
|
|
234
|
+
case "bigint":
|
|
235
|
+
val = val.toString() + "n";
|
|
236
|
+
break;
|
|
237
|
+
case "date":
|
|
238
|
+
val = "[Date: " + (isNaN(val.getTime()) ? val.toString() : val.toISOString()) + "]";
|
|
239
|
+
break;
|
|
240
|
+
case "buffer":
|
|
241
|
+
var json = val.toJSON();
|
|
242
|
+
json = json.data && json.type ? json.data : json;
|
|
243
|
+
val = "[Buffer: " + jsonStringify(json, 2, depth + 1) + "]";
|
|
244
|
+
break;
|
|
245
|
+
default: val = val === "[Function]" || val === "[Circular]" ? val : JSON.stringify(val);
|
|
246
|
+
}
|
|
247
|
+
return val;
|
|
248
|
+
}
|
|
249
|
+
for (var i in object) {
|
|
250
|
+
if (!Object.prototype.hasOwnProperty.call(object, i)) continue;
|
|
251
|
+
--length;
|
|
252
|
+
str += "\n " + repeat(" ", space) + (Array.isArray(object) ? "" : "\"" + i + "\": ") + _stringify(object[i]) + (length ? "," : "");
|
|
253
|
+
}
|
|
254
|
+
return str + (str.length !== 1 ? "\n" + repeat(" ", --space) + end : end);
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Return a new Thing that has the keys in sorted order. Recursive.
|
|
258
|
+
*
|
|
259
|
+
* If the Thing...
|
|
260
|
+
* - has already been seen, return string `'[Circular]'`
|
|
261
|
+
* - is `undefined`, return string `'[undefined]'`
|
|
262
|
+
* - is `null`, return value `null`
|
|
263
|
+
* - is some other primitive, return the value
|
|
264
|
+
* - is not a primitive or an `Array`, `Object`, or `Function`, return the value of the Thing's `toString()` method
|
|
265
|
+
* - is a non-empty `Array`, `Object`, or `Function`, return the result of calling this function again.
|
|
266
|
+
* - is an empty `Array`, `Object`, or `Function`, return the result of calling `emptyRepresentation()`
|
|
267
|
+
*
|
|
268
|
+
* @private
|
|
269
|
+
* @see {@link exports.stringify}
|
|
270
|
+
* @param {*} value Thing to inspect. May or may not have properties.
|
|
271
|
+
* @param {Array} [stack=[]] Stack of seen values
|
|
272
|
+
* @param {string} [typeHint] Type hint
|
|
273
|
+
* @return {(Object|Array|Function|string|undefined)}
|
|
274
|
+
*/
|
|
275
|
+
exports.canonicalize = function canonicalize(value, stack, typeHint) {
|
|
276
|
+
var canonicalizedObj;
|
|
277
|
+
var prop;
|
|
278
|
+
typeHint = typeHint || canonicalType(value);
|
|
279
|
+
function withStack(value$1, fn) {
|
|
280
|
+
stack.push(value$1);
|
|
281
|
+
fn();
|
|
282
|
+
stack.pop();
|
|
283
|
+
}
|
|
284
|
+
stack = stack || [];
|
|
285
|
+
if (stack.indexOf(value) !== -1) return "[Circular]";
|
|
286
|
+
switch (typeHint) {
|
|
287
|
+
case "undefined":
|
|
288
|
+
case "buffer":
|
|
289
|
+
case "null":
|
|
290
|
+
canonicalizedObj = value;
|
|
291
|
+
break;
|
|
292
|
+
case "array":
|
|
293
|
+
withStack(value, function() {
|
|
294
|
+
canonicalizedObj = value.map(function(item) {
|
|
295
|
+
return exports.canonicalize(item, stack);
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
break;
|
|
299
|
+
case "function":
|
|
300
|
+
for (prop in value) {
|
|
301
|
+
canonicalizedObj = {};
|
|
302
|
+
break;
|
|
303
|
+
}
|
|
304
|
+
if (!canonicalizedObj) {
|
|
305
|
+
canonicalizedObj = emptyRepresentation(value, typeHint);
|
|
306
|
+
break;
|
|
307
|
+
}
|
|
308
|
+
case "null-prototype":
|
|
309
|
+
case "object":
|
|
310
|
+
canonicalizedObj = canonicalizedObj || {};
|
|
311
|
+
if (typeHint === "null-prototype" && Symbol.toStringTag in value) canonicalizedObj["[Symbol.toStringTag]"] = value[Symbol.toStringTag];
|
|
312
|
+
withStack(value, function() {
|
|
313
|
+
Object.keys(value).sort().forEach(function(key) {
|
|
314
|
+
canonicalizedObj[key] = exports.canonicalize(value[key], stack);
|
|
315
|
+
});
|
|
316
|
+
});
|
|
317
|
+
break;
|
|
318
|
+
case "date":
|
|
319
|
+
case "number":
|
|
320
|
+
case "regexp":
|
|
321
|
+
case "boolean":
|
|
322
|
+
case "symbol":
|
|
323
|
+
canonicalizedObj = value;
|
|
324
|
+
break;
|
|
325
|
+
default: canonicalizedObj = value + "";
|
|
326
|
+
}
|
|
327
|
+
return canonicalizedObj;
|
|
328
|
+
};
|
|
329
|
+
/**
|
|
330
|
+
* @summary
|
|
331
|
+
* This Filter based on `mocha-clean` module.(see: `github.com/rstacruz/mocha-clean`)
|
|
332
|
+
* @description
|
|
333
|
+
* When invoking this function you get a filter function that get the Error.stack as an input,
|
|
334
|
+
* and return a prettify output.
|
|
335
|
+
* (i.e: strip Mocha and internal node functions from stack trace).
|
|
336
|
+
* @returns {Function}
|
|
337
|
+
*/
|
|
338
|
+
exports.stackTraceFilter = function() {
|
|
339
|
+
var is = typeof document === "undefined" ? { node: true } : { browser: true };
|
|
340
|
+
var slash = path.sep;
|
|
341
|
+
var cwd;
|
|
342
|
+
if (is.node) cwd = exports.cwd() + slash;
|
|
343
|
+
else {
|
|
344
|
+
cwd = (typeof location === "undefined" ? window.location : location).href.replace(/\/[^/]*$/, "/");
|
|
345
|
+
slash = "/";
|
|
346
|
+
}
|
|
347
|
+
function isMochaInternal(line) {
|
|
348
|
+
return ~line.indexOf("node_modules" + slash + "mocha" + slash) || ~line.indexOf(slash + "mocha.js") || ~line.indexOf(slash + "mocha.min.js");
|
|
349
|
+
}
|
|
350
|
+
function isNodeInternal(line) {
|
|
351
|
+
return ~line.indexOf("(timers.js:") || ~line.indexOf("(events.js:") || ~line.indexOf("(node.js:") || ~line.indexOf("(module.js:") || ~line.indexOf("GeneratorFunctionPrototype.next (native)") || false;
|
|
352
|
+
}
|
|
353
|
+
return function(stack) {
|
|
354
|
+
stack = stack.split("\n");
|
|
355
|
+
stack = stack.reduce(function(list, line) {
|
|
356
|
+
if (isMochaInternal(line)) return list;
|
|
357
|
+
if (is.node && isNodeInternal(line)) return list;
|
|
358
|
+
if (/:\d+:\d+\)?$/.test(line)) line = line.replace("(" + cwd, "(");
|
|
359
|
+
list.push(line);
|
|
360
|
+
return list;
|
|
361
|
+
}, []);
|
|
362
|
+
return stack.join("\n");
|
|
363
|
+
};
|
|
364
|
+
};
|
|
365
|
+
/**
|
|
366
|
+
* Crude, but effective.
|
|
367
|
+
* @public
|
|
368
|
+
* @param {*} value
|
|
369
|
+
* @returns {boolean} Whether or not `value` is a Promise
|
|
370
|
+
*/
|
|
371
|
+
exports.isPromise = function isPromise(value) {
|
|
372
|
+
return typeof value === "object" && value !== null && typeof value.then === "function";
|
|
373
|
+
};
|
|
374
|
+
/**
|
|
375
|
+
* Clamps a numeric value to an inclusive range.
|
|
376
|
+
*
|
|
377
|
+
* @param {number} value - Value to be clamped.
|
|
378
|
+
* @param {number[]} range - Two element array specifying [min, max] range.
|
|
379
|
+
* @returns {number} clamped value
|
|
380
|
+
*/
|
|
381
|
+
exports.clamp = function clamp(value, range) {
|
|
382
|
+
return Math.min(Math.max(value, range[0]), range[1]);
|
|
383
|
+
};
|
|
384
|
+
/**
|
|
385
|
+
* It's a noop.
|
|
386
|
+
* @public
|
|
387
|
+
*/
|
|
388
|
+
exports.noop = function() {};
|
|
389
|
+
/**
|
|
390
|
+
* Creates a map-like object.
|
|
391
|
+
*
|
|
392
|
+
* @description
|
|
393
|
+
* A "map" is an object with no prototype, for our purposes. In some cases
|
|
394
|
+
* this would be more appropriate than a `Map`, especially if your environment
|
|
395
|
+
* doesn't support it. Recommended for use in Mocha's public APIs.
|
|
396
|
+
*
|
|
397
|
+
* @public
|
|
398
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map#Custom_and_Null_objects|MDN:Map}
|
|
399
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create#Custom_and_Null_objects|MDN:Object.create - Custom objects}
|
|
400
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign#Custom_and_Null_objects|MDN:Object.assign}
|
|
401
|
+
* @param {...*} [obj] - Arguments to `Object.assign()`.
|
|
402
|
+
* @returns {Object} An object with no prototype, having `...obj` properties
|
|
403
|
+
*/
|
|
404
|
+
exports.createMap = function() {
|
|
405
|
+
return Object.assign.apply(null, [Object.create(null)].concat(Array.prototype.slice.call(arguments)));
|
|
406
|
+
};
|
|
407
|
+
/**
|
|
408
|
+
* Creates a read-only map-like object.
|
|
409
|
+
*
|
|
410
|
+
* @description
|
|
411
|
+
* This differs from {@link module:utils.createMap createMap} only in that
|
|
412
|
+
* the argument must be non-empty, because the result is frozen.
|
|
413
|
+
*
|
|
414
|
+
* @see {@link module:utils.createMap createMap}
|
|
415
|
+
* @param {...*} [obj] - Arguments to `Object.assign()`.
|
|
416
|
+
* @returns {Object} A frozen object with no prototype, having `...obj` properties
|
|
417
|
+
* @throws {TypeError} if argument is not a non-empty object.
|
|
418
|
+
*/
|
|
419
|
+
exports.defineConstants = function(obj) {
|
|
420
|
+
if (canonicalType(obj) !== "object" || !Object.keys(obj).length) throw new TypeError("Invalid argument; expected a non-empty object");
|
|
421
|
+
return Object.freeze(exports.createMap(obj));
|
|
422
|
+
};
|
|
423
|
+
/**
|
|
424
|
+
* Returns current working directory
|
|
425
|
+
*
|
|
426
|
+
* Wrapper around `process.cwd()` for isolation
|
|
427
|
+
* @private
|
|
428
|
+
*/
|
|
429
|
+
exports.cwd = function cwd() {
|
|
430
|
+
return process.cwd();
|
|
431
|
+
};
|
|
432
|
+
/**
|
|
433
|
+
* Returns `true` if Mocha is running in a browser.
|
|
434
|
+
* Checks for `process.browser`.
|
|
435
|
+
* @returns {boolean}
|
|
436
|
+
* @private
|
|
437
|
+
*/
|
|
438
|
+
exports.isBrowser = function isBrowser() {
|
|
439
|
+
return Boolean(process.browser);
|
|
440
|
+
};
|
|
441
|
+
exports.castArray = function castArray(value) {
|
|
442
|
+
if (value === void 0) return [];
|
|
443
|
+
if (value === null) return [null];
|
|
444
|
+
if (typeof value === "object" && (typeof value[Symbol.iterator] === "function" || value.length !== void 0)) return Array.from(value);
|
|
445
|
+
return [value];
|
|
446
|
+
};
|
|
447
|
+
exports.constants = exports.defineConstants({ MOCHA_ID_PROP_NAME });
|
|
448
|
+
const uniqueIDBase = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_";
|
|
449
|
+
/**
|
|
450
|
+
* Creates a new unique identifier
|
|
451
|
+
* Does not create cryptographically safe ids.
|
|
452
|
+
* Trivial copy of nanoid/non-secure
|
|
453
|
+
* @returns {string} Unique identifier
|
|
454
|
+
*/
|
|
455
|
+
exports.uniqueID = () => {
|
|
456
|
+
let id = "";
|
|
457
|
+
for (let i = 0; i < 21; i++) id += uniqueIDBase[Math.random() * 64 | 0];
|
|
458
|
+
return id;
|
|
459
|
+
};
|
|
460
|
+
exports.assignNewMochaID = (obj) => {
|
|
461
|
+
const id = exports.uniqueID();
|
|
462
|
+
Object.defineProperty(obj, MOCHA_ID_PROP_NAME, { get() {
|
|
463
|
+
return id;
|
|
464
|
+
} });
|
|
465
|
+
return obj;
|
|
466
|
+
};
|
|
467
|
+
/**
|
|
468
|
+
* Retrieves a Mocha ID from an object, if present.
|
|
469
|
+
* @param {*} [obj] - Object
|
|
470
|
+
* @returns {string|void}
|
|
471
|
+
*/
|
|
472
|
+
exports.getMochaID = (obj) => obj && typeof obj === "object" ? obj[MOCHA_ID_PROP_NAME] : void 0;
|
|
473
|
+
/**
|
|
474
|
+
* Replaces any detected circular dependency with the string '[Circular]'
|
|
475
|
+
* Mutates original object
|
|
476
|
+
* @param inputObj {*}
|
|
477
|
+
* @returns {*}
|
|
478
|
+
*/
|
|
479
|
+
exports.breakCircularDeps = (inputObj) => {
|
|
480
|
+
const seen = /* @__PURE__ */ new Set();
|
|
481
|
+
function _breakCircularDeps(obj) {
|
|
482
|
+
if (obj && typeof obj !== "object") return obj;
|
|
483
|
+
if (seen.has(obj)) return "[Circular]";
|
|
484
|
+
seen.add(obj);
|
|
485
|
+
for (const k in obj) {
|
|
486
|
+
const descriptor = Object.getOwnPropertyDescriptor(obj, k);
|
|
487
|
+
if (descriptor && descriptor.writable) obj[k] = _breakCircularDeps(obj[k], k);
|
|
488
|
+
}
|
|
489
|
+
seen.delete(obj);
|
|
490
|
+
return obj;
|
|
491
|
+
}
|
|
492
|
+
return _breakCircularDeps(inputObj);
|
|
493
|
+
};
|
|
494
|
+
/**
|
|
495
|
+
* Checks if provided input can be parsed as a JavaScript Number.
|
|
496
|
+
*/
|
|
497
|
+
exports.isNumeric = (input) => {
|
|
498
|
+
return !isNaN(parseFloat(input));
|
|
499
|
+
};
|
|
500
|
+
}) });
|
|
501
|
+
|
|
502
|
+
//#endregion
|
|
503
|
+
export default require_utils();
|
|
504
|
+
|
|
505
|
+
export { require_utils };
|