rahad-all-downloader 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- package/.cache/nix/binary-cache-v6.sqlite +0 -0
- package/.cache/nix/binary-cache-v6.sqlite-journal +0 -0
- package/.cache/replit/__replit_disk_meta.json +1 -0
- package/.cache/replit/modules/nodejs-20.res +1 -0
- package/.cache/replit/modules/replit.res +1 -0
- package/.cache/replit/modules.stamp +0 -0
- package/.cache/replit/nix/env.json +1 -0
- package/.cache/typescript/5.0/node_modules/.package-lock.json +12 -0
- package/.cache/typescript/5.0/node_modules/types-registry/README.md +2 -0
- package/.cache/typescript/5.0/node_modules/types-registry/index.json +1 -0
- package/.cache/typescript/5.0/node_modules/types-registry/package.json +20 -0
- package/.cache/typescript/5.0/package-lock.json +17 -0
- package/.cache/typescript/5.0/package.json +1 -0
- package/.cache/typescript/5.3/node_modules/.package-lock.json +99 -0
- package/.cache/typescript/5.3/node_modules/@types/node/LICENSE +21 -0
- package/.cache/typescript/5.3/node_modules/@types/node/README.md +15 -0
- package/.cache/typescript/5.3/node_modules/@types/node/assert/strict.d.ts +8 -0
- package/.cache/typescript/5.3/node_modules/@types/node/assert.d.ts +996 -0
- package/.cache/typescript/5.3/node_modules/@types/node/async_hooks.d.ts +539 -0
- package/.cache/typescript/5.3/node_modules/@types/node/buffer.d.ts +2362 -0
- package/.cache/typescript/5.3/node_modules/@types/node/child_process.d.ts +1540 -0
- package/.cache/typescript/5.3/node_modules/@types/node/cluster.d.ts +432 -0
- package/.cache/typescript/5.3/node_modules/@types/node/console.d.ts +415 -0
- package/.cache/typescript/5.3/node_modules/@types/node/constants.d.ts +19 -0
- package/.cache/typescript/5.3/node_modules/@types/node/crypto.d.ts +4456 -0
- package/.cache/typescript/5.3/node_modules/@types/node/dgram.d.ts +586 -0
- package/.cache/typescript/5.3/node_modules/@types/node/diagnostics_channel.d.ts +191 -0
- package/.cache/typescript/5.3/node_modules/@types/node/dns/promises.d.ts +425 -0
- package/.cache/typescript/5.3/node_modules/@types/node/dns.d.ts +809 -0
- package/.cache/typescript/5.3/node_modules/@types/node/dom-events.d.ts +122 -0
- package/.cache/typescript/5.3/node_modules/@types/node/domain.d.ts +170 -0
- package/.cache/typescript/5.3/node_modules/@types/node/events.d.ts +879 -0
- package/.cache/typescript/5.3/node_modules/@types/node/fs/promises.d.ts +1239 -0
- package/.cache/typescript/5.3/node_modules/@types/node/fs.d.ts +4291 -0
- package/.cache/typescript/5.3/node_modules/@types/node/globals.d.ts +385 -0
- package/.cache/typescript/5.3/node_modules/@types/node/globals.global.d.ts +1 -0
- package/.cache/typescript/5.3/node_modules/@types/node/http.d.ts +1888 -0
- package/.cache/typescript/5.3/node_modules/@types/node/http2.d.ts +2382 -0
- package/.cache/typescript/5.3/node_modules/@types/node/https.d.ts +550 -0
- package/.cache/typescript/5.3/node_modules/@types/node/index.d.ts +88 -0
- package/.cache/typescript/5.3/node_modules/@types/node/inspector.d.ts +2747 -0
- package/.cache/typescript/5.3/node_modules/@types/node/module.d.ts +301 -0
- package/.cache/typescript/5.3/node_modules/@types/node/net.d.ts +949 -0
- package/.cache/typescript/5.3/node_modules/@types/node/os.d.ts +478 -0
- package/.cache/typescript/5.3/node_modules/@types/node/package.json +230 -0
- package/.cache/typescript/5.3/node_modules/@types/node/path.d.ts +191 -0
- package/.cache/typescript/5.3/node_modules/@types/node/perf_hooks.d.ts +639 -0
- package/.cache/typescript/5.3/node_modules/@types/node/process.d.ts +1539 -0
- package/.cache/typescript/5.3/node_modules/@types/node/punycode.d.ts +117 -0
- package/.cache/typescript/5.3/node_modules/@types/node/querystring.d.ts +141 -0
- package/.cache/typescript/5.3/node_modules/@types/node/readline/promises.d.ts +150 -0
- package/.cache/typescript/5.3/node_modules/@types/node/readline.d.ts +539 -0
- package/.cache/typescript/5.3/node_modules/@types/node/repl.d.ts +430 -0
- package/.cache/typescript/5.3/node_modules/@types/node/stream/consumers.d.ts +12 -0
- package/.cache/typescript/5.3/node_modules/@types/node/stream/promises.d.ts +83 -0
- package/.cache/typescript/5.3/node_modules/@types/node/stream/web.d.ts +350 -0
- package/.cache/typescript/5.3/node_modules/@types/node/stream.d.ts +1701 -0
- package/.cache/typescript/5.3/node_modules/@types/node/string_decoder.d.ts +67 -0
- package/.cache/typescript/5.3/node_modules/@types/node/test.d.ts +1382 -0
- package/.cache/typescript/5.3/node_modules/@types/node/timers/promises.d.ts +93 -0
- package/.cache/typescript/5.3/node_modules/@types/node/timers.d.ts +240 -0
- package/.cache/typescript/5.3/node_modules/@types/node/tls.d.ts +1210 -0
- package/.cache/typescript/5.3/node_modules/@types/node/trace_events.d.ts +182 -0
- package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/assert/strict.d.ts +8 -0
- package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/assert.d.ts +996 -0
- package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/async_hooks.d.ts +539 -0
- package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/buffer.d.ts +2362 -0
- package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/child_process.d.ts +1540 -0
- package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/cluster.d.ts +432 -0
- package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/console.d.ts +415 -0
- package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/constants.d.ts +19 -0
- package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/crypto.d.ts +4455 -0
- package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/dgram.d.ts +586 -0
- package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/diagnostics_channel.d.ts +191 -0
- package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/dns/promises.d.ts +425 -0
- package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/dns.d.ts +809 -0
- package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/dom-events.d.ts +122 -0
- package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/domain.d.ts +170 -0
- package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/events.d.ts +879 -0
- package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/fs/promises.d.ts +1239 -0
- package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/fs.d.ts +4291 -0
- package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/globals.d.ts +385 -0
- package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/globals.global.d.ts +1 -0
- package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/http.d.ts +1888 -0
- package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/http2.d.ts +2382 -0
- package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/https.d.ts +550 -0
- package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/index.d.ts +88 -0
- package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/inspector.d.ts +2747 -0
- package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/module.d.ts +301 -0
- package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/net.d.ts +949 -0
- package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/os.d.ts +478 -0
- package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/path.d.ts +191 -0
- package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/perf_hooks.d.ts +639 -0
- package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/process.d.ts +1539 -0
- package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/punycode.d.ts +117 -0
- package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/querystring.d.ts +141 -0
- package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/readline/promises.d.ts +150 -0
- package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/readline.d.ts +539 -0
- package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/repl.d.ts +430 -0
- package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/stream/consumers.d.ts +12 -0
- package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/stream/promises.d.ts +83 -0
- package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/stream/web.d.ts +350 -0
- package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/stream.d.ts +1701 -0
- package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/string_decoder.d.ts +67 -0
- package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/test.d.ts +1382 -0
- package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/timers/promises.d.ts +93 -0
- package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/timers.d.ts +240 -0
- package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/tls.d.ts +1210 -0
- package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/trace_events.d.ts +182 -0
- package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/tty.d.ts +208 -0
- package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/url.d.ts +927 -0
- package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/util.d.ts +2183 -0
- package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/v8.d.ts +635 -0
- package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/vm.d.ts +903 -0
- package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/wasi.d.ts +158 -0
- package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/worker_threads.d.ts +691 -0
- package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/zlib.d.ts +517 -0
- package/.cache/typescript/5.3/node_modules/@types/node/tty.d.ts +208 -0
- package/.cache/typescript/5.3/node_modules/@types/node/url.d.ts +927 -0
- package/.cache/typescript/5.3/node_modules/@types/node/util.d.ts +2183 -0
- package/.cache/typescript/5.3/node_modules/@types/node/v8.d.ts +635 -0
- package/.cache/typescript/5.3/node_modules/@types/node/vm.d.ts +903 -0
- package/.cache/typescript/5.3/node_modules/@types/node/wasi.d.ts +158 -0
- package/.cache/typescript/5.3/node_modules/@types/node/worker_threads.d.ts +691 -0
- package/.cache/typescript/5.3/node_modules/@types/node/zlib.d.ts +517 -0
- package/.cache/typescript/5.3/node_modules/@types/node-fetch/LICENSE +21 -0
- package/.cache/typescript/5.3/node_modules/@types/node-fetch/README.md +15 -0
- package/.cache/typescript/5.3/node_modules/@types/node-fetch/externals.d.ts +32 -0
- package/.cache/typescript/5.3/node_modules/@types/node-fetch/index.d.ts +214 -0
- package/.cache/typescript/5.3/node_modules/@types/node-fetch/package.json +83 -0
- package/.cache/typescript/5.3/node_modules/asynckit/LICENSE +21 -0
- package/.cache/typescript/5.3/node_modules/asynckit/README.md +233 -0
- package/.cache/typescript/5.3/node_modules/asynckit/bench.js +76 -0
- package/.cache/typescript/5.3/node_modules/asynckit/index.js +6 -0
- package/.cache/typescript/5.3/node_modules/asynckit/lib/abort.js +29 -0
- package/.cache/typescript/5.3/node_modules/asynckit/lib/async.js +34 -0
- package/.cache/typescript/5.3/node_modules/asynckit/lib/defer.js +26 -0
- package/.cache/typescript/5.3/node_modules/asynckit/lib/iterate.js +75 -0
- package/.cache/typescript/5.3/node_modules/asynckit/lib/readable_asynckit.js +91 -0
- package/.cache/typescript/5.3/node_modules/asynckit/lib/readable_parallel.js +25 -0
- package/.cache/typescript/5.3/node_modules/asynckit/lib/readable_serial.js +25 -0
- package/.cache/typescript/5.3/node_modules/asynckit/lib/readable_serial_ordered.js +29 -0
- package/.cache/typescript/5.3/node_modules/asynckit/lib/state.js +37 -0
- package/.cache/typescript/5.3/node_modules/asynckit/lib/streamify.js +141 -0
- package/.cache/typescript/5.3/node_modules/asynckit/lib/terminator.js +29 -0
- package/.cache/typescript/5.3/node_modules/asynckit/package.json +63 -0
- package/.cache/typescript/5.3/node_modules/asynckit/parallel.js +43 -0
- package/.cache/typescript/5.3/node_modules/asynckit/serial.js +17 -0
- package/.cache/typescript/5.3/node_modules/asynckit/serialOrdered.js +75 -0
- package/.cache/typescript/5.3/node_modules/asynckit/stream.js +21 -0
- package/.cache/typescript/5.3/node_modules/combined-stream/License +19 -0
- package/.cache/typescript/5.3/node_modules/combined-stream/Readme.md +138 -0
- package/.cache/typescript/5.3/node_modules/combined-stream/lib/combined_stream.js +208 -0
- package/.cache/typescript/5.3/node_modules/combined-stream/package.json +25 -0
- package/.cache/typescript/5.3/node_modules/combined-stream/yarn.lock +17 -0
- package/.cache/typescript/5.3/node_modules/delayed-stream/License +19 -0
- package/.cache/typescript/5.3/node_modules/delayed-stream/Makefile +7 -0
- package/.cache/typescript/5.3/node_modules/delayed-stream/Readme.md +141 -0
- package/.cache/typescript/5.3/node_modules/delayed-stream/lib/delayed_stream.js +107 -0
- package/.cache/typescript/5.3/node_modules/delayed-stream/package.json +27 -0
- package/.cache/typescript/5.3/node_modules/form-data/License +19 -0
- package/.cache/typescript/5.3/node_modules/form-data/README.md.bak +358 -0
- package/.cache/typescript/5.3/node_modules/form-data/Readme.md +358 -0
- package/.cache/typescript/5.3/node_modules/form-data/index.d.ts +62 -0
- package/.cache/typescript/5.3/node_modules/form-data/lib/browser.js +2 -0
- package/.cache/typescript/5.3/node_modules/form-data/lib/form_data.js +501 -0
- package/.cache/typescript/5.3/node_modules/form-data/lib/populate.js +10 -0
- package/.cache/typescript/5.3/node_modules/form-data/package.json +68 -0
- package/.cache/typescript/5.3/node_modules/mime-db/HISTORY.md +507 -0
- package/.cache/typescript/5.3/node_modules/mime-db/LICENSE +23 -0
- package/.cache/typescript/5.3/node_modules/mime-db/README.md +100 -0
- package/.cache/typescript/5.3/node_modules/mime-db/db.json +8519 -0
- package/.cache/typescript/5.3/node_modules/mime-db/index.js +12 -0
- package/.cache/typescript/5.3/node_modules/mime-db/package.json +60 -0
- package/.cache/typescript/5.3/node_modules/mime-types/HISTORY.md +397 -0
- package/.cache/typescript/5.3/node_modules/mime-types/LICENSE +23 -0
- package/.cache/typescript/5.3/node_modules/mime-types/README.md +113 -0
- package/.cache/typescript/5.3/node_modules/mime-types/index.js +188 -0
- package/.cache/typescript/5.3/node_modules/mime-types/package.json +44 -0
- package/.cache/typescript/5.3/node_modules/types-registry/README.md +2 -0
- package/.cache/typescript/5.3/node_modules/types-registry/index.json +1 -0
- package/.cache/typescript/5.3/node_modules/types-registry/package.json +20 -0
- package/.cache/typescript/5.3/node_modules/undici-types/README.md +6 -0
- package/.cache/typescript/5.3/node_modules/undici-types/agent.d.ts +31 -0
- package/.cache/typescript/5.3/node_modules/undici-types/api.d.ts +43 -0
- package/.cache/typescript/5.3/node_modules/undici-types/balanced-pool.d.ts +18 -0
- package/.cache/typescript/5.3/node_modules/undici-types/cache.d.ts +36 -0
- package/.cache/typescript/5.3/node_modules/undici-types/client.d.ts +97 -0
- package/.cache/typescript/5.3/node_modules/undici-types/connector.d.ts +34 -0
- package/.cache/typescript/5.3/node_modules/undici-types/content-type.d.ts +21 -0
- package/.cache/typescript/5.3/node_modules/undici-types/cookies.d.ts +28 -0
- package/.cache/typescript/5.3/node_modules/undici-types/diagnostics-channel.d.ts +67 -0
- package/.cache/typescript/5.3/node_modules/undici-types/dispatcher.d.ts +241 -0
- package/.cache/typescript/5.3/node_modules/undici-types/errors.d.ts +128 -0
- package/.cache/typescript/5.3/node_modules/undici-types/fetch.d.ts +209 -0
- package/.cache/typescript/5.3/node_modules/undici-types/file.d.ts +39 -0
- package/.cache/typescript/5.3/node_modules/undici-types/filereader.d.ts +54 -0
- package/.cache/typescript/5.3/node_modules/undici-types/formdata.d.ts +108 -0
- package/.cache/typescript/5.3/node_modules/undici-types/global-dispatcher.d.ts +9 -0
- package/.cache/typescript/5.3/node_modules/undici-types/global-origin.d.ts +7 -0
- package/.cache/typescript/5.3/node_modules/undici-types/handlers.d.ts +9 -0
- package/.cache/typescript/5.3/node_modules/undici-types/header.d.ts +4 -0
- package/.cache/typescript/5.3/node_modules/undici-types/index.d.ts +63 -0
- package/.cache/typescript/5.3/node_modules/undici-types/interceptors.d.ts +5 -0
- package/.cache/typescript/5.3/node_modules/undici-types/mock-agent.d.ts +50 -0
- package/.cache/typescript/5.3/node_modules/undici-types/mock-client.d.ts +25 -0
- package/.cache/typescript/5.3/node_modules/undici-types/mock-errors.d.ts +12 -0
- package/.cache/typescript/5.3/node_modules/undici-types/mock-interceptor.d.ts +93 -0
- package/.cache/typescript/5.3/node_modules/undici-types/mock-pool.d.ts +25 -0
- package/.cache/typescript/5.3/node_modules/undici-types/package.json +55 -0
- package/.cache/typescript/5.3/node_modules/undici-types/patch.d.ts +71 -0
- package/.cache/typescript/5.3/node_modules/undici-types/pool-stats.d.ts +19 -0
- package/.cache/typescript/5.3/node_modules/undici-types/pool.d.ts +28 -0
- package/.cache/typescript/5.3/node_modules/undici-types/proxy-agent.d.ts +30 -0
- package/.cache/typescript/5.3/node_modules/undici-types/readable.d.ts +61 -0
- package/.cache/typescript/5.3/node_modules/undici-types/webidl.d.ts +220 -0
- package/.cache/typescript/5.3/node_modules/undici-types/websocket.d.ts +131 -0
- package/.cache/typescript/5.3/package-lock.json +107 -0
- package/.cache/typescript/5.3/package.json +1 -0
- package/.cache/typescript/5.4/node_modules/.package-lock.json +115 -0
- package/.cache/typescript/5.4/node_modules/@types/body-parser/LICENSE +21 -0
- package/.cache/typescript/5.4/node_modules/@types/body-parser/README.md +15 -0
- package/.cache/typescript/5.4/node_modules/@types/body-parser/index.d.ts +95 -0
- package/.cache/typescript/5.4/node_modules/@types/body-parser/package.json +58 -0
- package/.cache/typescript/5.4/node_modules/@types/connect/LICENSE +21 -0
- package/.cache/typescript/5.4/node_modules/@types/connect/README.md +15 -0
- package/.cache/typescript/5.4/node_modules/@types/connect/index.d.ts +91 -0
- package/.cache/typescript/5.4/node_modules/@types/connect/package.json +32 -0
- package/.cache/typescript/5.4/node_modules/@types/express/LICENSE +21 -0
- package/.cache/typescript/5.4/node_modules/@types/express/README.md +15 -0
- package/.cache/typescript/5.4/node_modules/@types/express/index.d.ts +128 -0
- package/.cache/typescript/5.4/node_modules/@types/express/package.json +45 -0
- package/.cache/typescript/5.4/node_modules/@types/express-serve-static-core/LICENSE +21 -0
- package/.cache/typescript/5.4/node_modules/@types/express-serve-static-core/README.md +15 -0
- package/.cache/typescript/5.4/node_modules/@types/express-serve-static-core/index.d.ts +1295 -0
- package/.cache/typescript/5.4/node_modules/@types/express-serve-static-core/package.json +50 -0
- package/.cache/typescript/5.4/node_modules/@types/http-errors/LICENSE +21 -0
- package/.cache/typescript/5.4/node_modules/@types/http-errors/README.md +15 -0
- package/.cache/typescript/5.4/node_modules/@types/http-errors/index.d.ts +77 -0
- package/.cache/typescript/5.4/node_modules/@types/http-errors/package.json +30 -0
- package/.cache/typescript/5.4/node_modules/@types/mime/LICENSE +21 -0
- package/.cache/typescript/5.4/node_modules/@types/mime/Mime.d.ts +10 -0
- package/.cache/typescript/5.4/node_modules/@types/mime/README.md +15 -0
- package/.cache/typescript/5.4/node_modules/@types/mime/index.d.ts +31 -0
- package/.cache/typescript/5.4/node_modules/@types/mime/lite.d.ts +7 -0
- package/.cache/typescript/5.4/node_modules/@types/mime/package.json +30 -0
- package/.cache/typescript/5.4/node_modules/@types/node/LICENSE +21 -0
- package/.cache/typescript/5.4/node_modules/@types/node/README.md +15 -0
- package/.cache/typescript/5.4/node_modules/@types/node/assert/strict.d.ts +8 -0
- package/.cache/typescript/5.4/node_modules/@types/node/assert.d.ts +1040 -0
- package/.cache/typescript/5.4/node_modules/@types/node/async_hooks.d.ts +541 -0
- package/.cache/typescript/5.4/node_modules/@types/node/buffer.d.ts +2363 -0
- package/.cache/typescript/5.4/node_modules/@types/node/child_process.d.ts +1544 -0
- package/.cache/typescript/5.4/node_modules/@types/node/cluster.d.ts +578 -0
- package/.cache/typescript/5.4/node_modules/@types/node/console.d.ts +452 -0
- package/.cache/typescript/5.4/node_modules/@types/node/constants.d.ts +19 -0
- package/.cache/typescript/5.4/node_modules/@types/node/crypto.d.ts +4523 -0
- package/.cache/typescript/5.4/node_modules/@types/node/dgram.d.ts +596 -0
- package/.cache/typescript/5.4/node_modules/@types/node/diagnostics_channel.d.ts +554 -0
- package/.cache/typescript/5.4/node_modules/@types/node/dns/promises.d.ts +474 -0
- package/.cache/typescript/5.4/node_modules/@types/node/dns.d.ts +864 -0
- package/.cache/typescript/5.4/node_modules/@types/node/dom-events.d.ts +124 -0
- package/.cache/typescript/5.4/node_modules/@types/node/domain.d.ts +170 -0
- package/.cache/typescript/5.4/node_modules/@types/node/events.d.ts +909 -0
- package/.cache/typescript/5.4/node_modules/@types/node/fs/promises.d.ts +1245 -0
- package/.cache/typescript/5.4/node_modules/@types/node/fs.d.ts +4317 -0
- package/.cache/typescript/5.4/node_modules/@types/node/globals.d.ts +411 -0
- package/.cache/typescript/5.4/node_modules/@types/node/globals.global.d.ts +1 -0
- package/.cache/typescript/5.4/node_modules/@types/node/http.d.ts +1908 -0
- package/.cache/typescript/5.4/node_modules/@types/node/http2.d.ts +2418 -0
- package/.cache/typescript/5.4/node_modules/@types/node/https.d.ts +550 -0
- package/.cache/typescript/5.4/node_modules/@types/node/index.d.ts +89 -0
- package/.cache/typescript/5.4/node_modules/@types/node/inspector.d.ts +2746 -0
- package/.cache/typescript/5.4/node_modules/@types/node/module.d.ts +315 -0
- package/.cache/typescript/5.4/node_modules/@types/node/net.d.ts +999 -0
- package/.cache/typescript/5.4/node_modules/@types/node/os.d.ts +495 -0
- package/.cache/typescript/5.4/node_modules/@types/node/package.json +217 -0
- package/.cache/typescript/5.4/node_modules/@types/node/path.d.ts +191 -0
- package/.cache/typescript/5.4/node_modules/@types/node/perf_hooks.d.ts +905 -0
- package/.cache/typescript/5.4/node_modules/@types/node/process.d.ts +1754 -0
- package/.cache/typescript/5.4/node_modules/@types/node/punycode.d.ts +117 -0
- package/.cache/typescript/5.4/node_modules/@types/node/querystring.d.ts +153 -0
- package/.cache/typescript/5.4/node_modules/@types/node/readline/promises.d.ts +150 -0
- package/.cache/typescript/5.4/node_modules/@types/node/readline.d.ts +540 -0
- package/.cache/typescript/5.4/node_modules/@types/node/repl.d.ts +430 -0
- package/.cache/typescript/5.4/node_modules/@types/node/sea.d.ts +153 -0
- package/.cache/typescript/5.4/node_modules/@types/node/stream/consumers.d.ts +12 -0
- package/.cache/typescript/5.4/node_modules/@types/node/stream/promises.d.ts +83 -0
- package/.cache/typescript/5.4/node_modules/@types/node/stream/web.d.ts +367 -0
- package/.cache/typescript/5.4/node_modules/@types/node/stream.d.ts +1707 -0
- package/.cache/typescript/5.4/node_modules/@types/node/string_decoder.d.ts +67 -0
- package/.cache/typescript/5.4/node_modules/@types/node/test.d.ts +1718 -0
- package/.cache/typescript/5.4/node_modules/@types/node/timers/promises.d.ts +97 -0
- package/.cache/typescript/5.4/node_modules/@types/node/timers.d.ts +240 -0
- package/.cache/typescript/5.4/node_modules/@types/node/tls.d.ts +1217 -0
- package/.cache/typescript/5.4/node_modules/@types/node/trace_events.d.ts +197 -0
- package/.cache/typescript/5.4/node_modules/@types/node/tty.d.ts +208 -0
- package/.cache/typescript/5.4/node_modules/@types/node/url.d.ts +952 -0
- package/.cache/typescript/5.4/node_modules/@types/node/util.d.ts +2292 -0
- package/.cache/typescript/5.4/node_modules/@types/node/v8.d.ts +808 -0
- package/.cache/typescript/5.4/node_modules/@types/node/vm.d.ts +924 -0
- package/.cache/typescript/5.4/node_modules/@types/node/wasi.d.ts +181 -0
- package/.cache/typescript/5.4/node_modules/@types/node/worker_threads.d.ts +691 -0
- package/.cache/typescript/5.4/node_modules/@types/node/zlib.d.ts +530 -0
- package/.cache/typescript/5.4/node_modules/@types/qs/LICENSE +21 -0
- package/.cache/typescript/5.4/node_modules/@types/qs/README.md +15 -0
- package/.cache/typescript/5.4/node_modules/@types/qs/index.d.ts +79 -0
- package/.cache/typescript/5.4/node_modules/@types/qs/package.json +65 -0
- package/.cache/typescript/5.4/node_modules/@types/range-parser/LICENSE +21 -0
- package/.cache/typescript/5.4/node_modules/@types/range-parser/README.md +53 -0
- package/.cache/typescript/5.4/node_modules/@types/range-parser/index.d.ts +34 -0
- package/.cache/typescript/5.4/node_modules/@types/range-parser/package.json +25 -0
- package/.cache/typescript/5.4/node_modules/@types/send/LICENSE +21 -0
- package/.cache/typescript/5.4/node_modules/@types/send/README.md +15 -0
- package/.cache/typescript/5.4/node_modules/@types/send/index.d.ts +225 -0
- package/.cache/typescript/5.4/node_modules/@types/send/package.json +33 -0
- package/.cache/typescript/5.4/node_modules/@types/serve-static/LICENSE +21 -0
- package/.cache/typescript/5.4/node_modules/@types/serve-static/README.md +15 -0
- package/.cache/typescript/5.4/node_modules/@types/serve-static/index.d.ts +107 -0
- package/.cache/typescript/5.4/node_modules/@types/serve-static/package.json +39 -0
- package/.cache/typescript/5.4/node_modules/types-registry/README.md +2 -0
- package/.cache/typescript/5.4/node_modules/types-registry/index.json +1 -0
- package/.cache/typescript/5.4/node_modules/types-registry/package.json +20 -0
- package/.cache/typescript/5.4/node_modules/undici-types/README.md +6 -0
- package/.cache/typescript/5.4/node_modules/undici-types/agent.d.ts +31 -0
- package/.cache/typescript/5.4/node_modules/undici-types/api.d.ts +43 -0
- package/.cache/typescript/5.4/node_modules/undici-types/balanced-pool.d.ts +18 -0
- package/.cache/typescript/5.4/node_modules/undici-types/cache.d.ts +36 -0
- package/.cache/typescript/5.4/node_modules/undici-types/client.d.ts +97 -0
- package/.cache/typescript/5.4/node_modules/undici-types/connector.d.ts +34 -0
- package/.cache/typescript/5.4/node_modules/undici-types/content-type.d.ts +21 -0
- package/.cache/typescript/5.4/node_modules/undici-types/cookies.d.ts +28 -0
- package/.cache/typescript/5.4/node_modules/undici-types/diagnostics-channel.d.ts +67 -0
- package/.cache/typescript/5.4/node_modules/undici-types/dispatcher.d.ts +241 -0
- package/.cache/typescript/5.4/node_modules/undici-types/errors.d.ts +128 -0
- package/.cache/typescript/5.4/node_modules/undici-types/fetch.d.ts +209 -0
- package/.cache/typescript/5.4/node_modules/undici-types/file.d.ts +39 -0
- package/.cache/typescript/5.4/node_modules/undici-types/filereader.d.ts +54 -0
- package/.cache/typescript/5.4/node_modules/undici-types/formdata.d.ts +108 -0
- package/.cache/typescript/5.4/node_modules/undici-types/global-dispatcher.d.ts +9 -0
- package/.cache/typescript/5.4/node_modules/undici-types/global-origin.d.ts +7 -0
- package/.cache/typescript/5.4/node_modules/undici-types/handlers.d.ts +9 -0
- package/.cache/typescript/5.4/node_modules/undici-types/header.d.ts +4 -0
- package/.cache/typescript/5.4/node_modules/undici-types/index.d.ts +63 -0
- package/.cache/typescript/5.4/node_modules/undici-types/interceptors.d.ts +5 -0
- package/.cache/typescript/5.4/node_modules/undici-types/mock-agent.d.ts +50 -0
- package/.cache/typescript/5.4/node_modules/undici-types/mock-client.d.ts +25 -0
- package/.cache/typescript/5.4/node_modules/undici-types/mock-errors.d.ts +12 -0
- package/.cache/typescript/5.4/node_modules/undici-types/mock-interceptor.d.ts +93 -0
- package/.cache/typescript/5.4/node_modules/undici-types/mock-pool.d.ts +25 -0
- package/.cache/typescript/5.4/node_modules/undici-types/package.json +55 -0
- package/.cache/typescript/5.4/node_modules/undici-types/patch.d.ts +71 -0
- package/.cache/typescript/5.4/node_modules/undici-types/pool-stats.d.ts +19 -0
- package/.cache/typescript/5.4/node_modules/undici-types/pool.d.ts +28 -0
- package/.cache/typescript/5.4/node_modules/undici-types/proxy-agent.d.ts +30 -0
- package/.cache/typescript/5.4/node_modules/undici-types/readable.d.ts +61 -0
- package/.cache/typescript/5.4/node_modules/undici-types/webidl.d.ts +220 -0
- package/.cache/typescript/5.4/node_modules/undici-types/websocket.d.ts +131 -0
- package/.cache/typescript/5.4/package-lock.json +124 -0
- package/.cache/typescript/5.4/package.json +1 -0
- package/.replit +21 -0
- package/.upm/store.json +1 -0
- package/README.md +71 -0
- package/index.js +1 -0
- package/package.json +40 -0
- package/replit.nix +3 -0
@@ -0,0 +1,1718 @@
|
|
1
|
+
/**
|
2
|
+
* The `node:test` module facilitates the creation of JavaScript tests.
|
3
|
+
* To access it:
|
4
|
+
*
|
5
|
+
* ```js
|
6
|
+
* import test from 'node:test';
|
7
|
+
* ```
|
8
|
+
*
|
9
|
+
* This module is only available under the `node:` scheme. The following will not
|
10
|
+
* work:
|
11
|
+
*
|
12
|
+
* ```js
|
13
|
+
* import test from 'test';
|
14
|
+
* ```
|
15
|
+
*
|
16
|
+
* Tests created via the `test` module consist of a single function that is
|
17
|
+
* processed in one of three ways:
|
18
|
+
*
|
19
|
+
* 1. A synchronous function that is considered failing if it throws an exception,
|
20
|
+
* and is considered passing otherwise.
|
21
|
+
* 2. A function that returns a `Promise` that is considered failing if the `Promise` rejects, and is considered passing if the `Promise` fulfills.
|
22
|
+
* 3. A function that receives a callback function. If the callback receives any
|
23
|
+
* truthy value as its first argument, the test is considered failing. If a
|
24
|
+
* falsy value is passed as the first argument to the callback, the test is
|
25
|
+
* considered passing. If the test function receives a callback function and
|
26
|
+
* also returns a `Promise`, the test will fail.
|
27
|
+
*
|
28
|
+
* The following example illustrates how tests are written using the `test` module.
|
29
|
+
*
|
30
|
+
* ```js
|
31
|
+
* test('synchronous passing test', (t) => {
|
32
|
+
* // This test passes because it does not throw an exception.
|
33
|
+
* assert.strictEqual(1, 1);
|
34
|
+
* });
|
35
|
+
*
|
36
|
+
* test('synchronous failing test', (t) => {
|
37
|
+
* // This test fails because it throws an exception.
|
38
|
+
* assert.strictEqual(1, 2);
|
39
|
+
* });
|
40
|
+
*
|
41
|
+
* test('asynchronous passing test', async (t) => {
|
42
|
+
* // This test passes because the Promise returned by the async
|
43
|
+
* // function is settled and not rejected.
|
44
|
+
* assert.strictEqual(1, 1);
|
45
|
+
* });
|
46
|
+
*
|
47
|
+
* test('asynchronous failing test', async (t) => {
|
48
|
+
* // This test fails because the Promise returned by the async
|
49
|
+
* // function is rejected.
|
50
|
+
* assert.strictEqual(1, 2);
|
51
|
+
* });
|
52
|
+
*
|
53
|
+
* test('failing test using Promises', (t) => {
|
54
|
+
* // Promises can be used directly as well.
|
55
|
+
* return new Promise((resolve, reject) => {
|
56
|
+
* setImmediate(() => {
|
57
|
+
* reject(new Error('this will cause the test to fail'));
|
58
|
+
* });
|
59
|
+
* });
|
60
|
+
* });
|
61
|
+
*
|
62
|
+
* test('callback passing test', (t, done) => {
|
63
|
+
* // done() is the callback function. When the setImmediate() runs, it invokes
|
64
|
+
* // done() with no arguments.
|
65
|
+
* setImmediate(done);
|
66
|
+
* });
|
67
|
+
*
|
68
|
+
* test('callback failing test', (t, done) => {
|
69
|
+
* // When the setImmediate() runs, done() is invoked with an Error object and
|
70
|
+
* // the test fails.
|
71
|
+
* setImmediate(() => {
|
72
|
+
* done(new Error('callback failure'));
|
73
|
+
* });
|
74
|
+
* });
|
75
|
+
* ```
|
76
|
+
*
|
77
|
+
* If any tests fail, the process exit code is set to `1`.
|
78
|
+
* @since v18.0.0, v16.17.0
|
79
|
+
* @see [source](https://github.com/nodejs/node/blob/v20.13.1/lib/test.js)
|
80
|
+
*/
|
81
|
+
declare module "node:test" {
|
82
|
+
import { Readable } from "node:stream";
|
83
|
+
import { AsyncResource } from "node:async_hooks";
|
84
|
+
/**
|
85
|
+
* **Note:** `shard` is used to horizontally parallelize test running across
|
86
|
+
* machines or processes, ideal for large-scale executions across varied
|
87
|
+
* environments. It's incompatible with `watch` mode, tailored for rapid
|
88
|
+
* code iteration by automatically rerunning tests on file changes.
|
89
|
+
*
|
90
|
+
* ```js
|
91
|
+
* import { tap } from 'node:test/reporters';
|
92
|
+
* import { run } from 'node:test';
|
93
|
+
* import process from 'node:process';
|
94
|
+
* import path from 'node:path';
|
95
|
+
*
|
96
|
+
* run({ files: [path.resolve('./tests/test.js')] })
|
97
|
+
* .compose(tap)
|
98
|
+
* .pipe(process.stdout);
|
99
|
+
* ```
|
100
|
+
* @since v18.9.0, v16.19.0
|
101
|
+
* @param options Configuration options for running tests. The following properties are supported:
|
102
|
+
*/
|
103
|
+
function run(options?: RunOptions): TestsStream;
|
104
|
+
/**
|
105
|
+
* The `test()` function is the value imported from the `test` module. Each
|
106
|
+
* invocation of this function results in reporting the test to the `TestsStream`.
|
107
|
+
*
|
108
|
+
* The `TestContext` object passed to the `fn` argument can be used to perform
|
109
|
+
* actions related to the current test. Examples include skipping the test, adding
|
110
|
+
* additional diagnostic information, or creating subtests.
|
111
|
+
*
|
112
|
+
* `test()` returns a `Promise` that fulfills once the test completes.
|
113
|
+
* if `test()` is called within a suite, it fulfills immediately.
|
114
|
+
* The return value can usually be discarded for top level tests.
|
115
|
+
* However, the return value from subtests should be used to prevent the parent
|
116
|
+
* test from finishing first and cancelling the subtest
|
117
|
+
* as shown in the following example.
|
118
|
+
*
|
119
|
+
* ```js
|
120
|
+
* test('top level test', async (t) => {
|
121
|
+
* // The setTimeout() in the following subtest would cause it to outlive its
|
122
|
+
* // parent test if 'await' is removed on the next line. Once the parent test
|
123
|
+
* // completes, it will cancel any outstanding subtests.
|
124
|
+
* await t.test('longer running subtest', async (t) => {
|
125
|
+
* return new Promise((resolve, reject) => {
|
126
|
+
* setTimeout(resolve, 1000);
|
127
|
+
* });
|
128
|
+
* });
|
129
|
+
* });
|
130
|
+
* ```
|
131
|
+
*
|
132
|
+
* The `timeout` option can be used to fail the test if it takes longer than `timeout` milliseconds to complete. However, it is not a reliable mechanism for
|
133
|
+
* canceling tests because a running test might block the application thread and
|
134
|
+
* thus prevent the scheduled cancellation.
|
135
|
+
* @since v18.0.0, v16.17.0
|
136
|
+
* @param [name='The name'] The name of the test, which is displayed when reporting test results.
|
137
|
+
* @param options Configuration options for the test. The following properties are supported:
|
138
|
+
* @param [fn='A no-op function'] The function under test. The first argument to this function is a {@link TestContext} object. If the test uses callbacks, the
|
139
|
+
* callback function is passed as the second argument.
|
140
|
+
* @return Fulfilled with `undefined` once the test completes, or immediately if the test runs within a suite.
|
141
|
+
*/
|
142
|
+
function test(name?: string, fn?: TestFn): Promise<void>;
|
143
|
+
function test(name?: string, options?: TestOptions, fn?: TestFn): Promise<void>;
|
144
|
+
function test(options?: TestOptions, fn?: TestFn): Promise<void>;
|
145
|
+
function test(fn?: TestFn): Promise<void>;
|
146
|
+
namespace test {
|
147
|
+
export { after, afterEach, before, beforeEach, describe, it, mock, only, run, skip, test, todo };
|
148
|
+
}
|
149
|
+
/**
|
150
|
+
* The `suite()` function is imported from the `node:test` module.
|
151
|
+
* @param name The name of the suite, which is displayed when reporting test results. **Default:** The `name` property of `fn`, or `'<anonymous>'` if `fn` does not have a name.
|
152
|
+
* @param options Optional configuration options for the suite. This supports the same options as `test([name][, options][, fn])`.
|
153
|
+
* @param [fn='A no-op function'] The suite function declaring nested tests and suites. The first argument to this function is a `{@link SuiteContext}` object.
|
154
|
+
* @return Immediately fulfilled with `undefined`.
|
155
|
+
* @since v20.13.0
|
156
|
+
*/
|
157
|
+
function suite(name?: string, options?: TestOptions, fn?: SuiteFn): Promise<void>;
|
158
|
+
function suite(name?: string, fn?: SuiteFn): Promise<void>;
|
159
|
+
function suite(options?: TestOptions, fn?: SuiteFn): Promise<void>;
|
160
|
+
function suite(fn?: SuiteFn): Promise<void>;
|
161
|
+
namespace suite {
|
162
|
+
/**
|
163
|
+
* Shorthand for skipping a suite. This is the same as [`suite([name], { skip: true }[, fn])`](https://nodejs.org/docs/latest-v20.x/api/test.html#suitename-options-fn).
|
164
|
+
* @since v20.13.0
|
165
|
+
*/
|
166
|
+
function skip(name?: string, options?: TestOptions, fn?: SuiteFn): Promise<void>;
|
167
|
+
function skip(name?: string, fn?: SuiteFn): Promise<void>;
|
168
|
+
function skip(options?: TestOptions, fn?: SuiteFn): Promise<void>;
|
169
|
+
function skip(fn?: SuiteFn): Promise<void>;
|
170
|
+
/**
|
171
|
+
* Shorthand for marking a suite as `TODO`. This is the same as [`suite([name], { todo: true }[, fn])`](https://nodejs.org/docs/latest-v20.x/api/test.html#suitename-options-fn).
|
172
|
+
* @since v20.13.0
|
173
|
+
*/
|
174
|
+
function todo(name?: string, options?: TestOptions, fn?: SuiteFn): Promise<void>;
|
175
|
+
function todo(name?: string, fn?: SuiteFn): Promise<void>;
|
176
|
+
function todo(options?: TestOptions, fn?: SuiteFn): Promise<void>;
|
177
|
+
function todo(fn?: SuiteFn): Promise<void>;
|
178
|
+
/**
|
179
|
+
* Shorthand for marking a suite as `only`. This is the same as [`suite([name], { only: true }[, fn])`](https://nodejs.org/docs/latest-v20.x/api/test.html#suitename-options-fn).
|
180
|
+
* @since v20.13.0
|
181
|
+
*/
|
182
|
+
function only(name?: string, options?: TestOptions, fn?: SuiteFn): Promise<void>;
|
183
|
+
function only(name?: string, fn?: SuiteFn): Promise<void>;
|
184
|
+
function only(options?: TestOptions, fn?: SuiteFn): Promise<void>;
|
185
|
+
function only(fn?: SuiteFn): Promise<void>;
|
186
|
+
}
|
187
|
+
/**
|
188
|
+
* Alias for `{@link suite}`.
|
189
|
+
*
|
190
|
+
* The `describe()` function is imported from the `node:test` module.
|
191
|
+
*/
|
192
|
+
function describe(name?: string, options?: TestOptions, fn?: SuiteFn): Promise<void>;
|
193
|
+
function describe(name?: string, fn?: SuiteFn): Promise<void>;
|
194
|
+
function describe(options?: TestOptions, fn?: SuiteFn): Promise<void>;
|
195
|
+
function describe(fn?: SuiteFn): Promise<void>;
|
196
|
+
namespace describe {
|
197
|
+
/**
|
198
|
+
* Shorthand for skipping a suite. This is the same as [`describe([name], { skip: true }[, fn])`](https://nodejs.org/docs/latest-v20.x/api/test.html#describename-options-fn).
|
199
|
+
* @since v18.15.0
|
200
|
+
*/
|
201
|
+
function skip(name?: string, options?: TestOptions, fn?: SuiteFn): Promise<void>;
|
202
|
+
function skip(name?: string, fn?: SuiteFn): Promise<void>;
|
203
|
+
function skip(options?: TestOptions, fn?: SuiteFn): Promise<void>;
|
204
|
+
function skip(fn?: SuiteFn): Promise<void>;
|
205
|
+
/**
|
206
|
+
* Shorthand for marking a suite as `TODO`. This is the same as [`describe([name], { todo: true }[, fn])`](https://nodejs.org/docs/latest-v20.x/api/test.html#describename-options-fn).
|
207
|
+
* @since v18.15.0
|
208
|
+
*/
|
209
|
+
function todo(name?: string, options?: TestOptions, fn?: SuiteFn): Promise<void>;
|
210
|
+
function todo(name?: string, fn?: SuiteFn): Promise<void>;
|
211
|
+
function todo(options?: TestOptions, fn?: SuiteFn): Promise<void>;
|
212
|
+
function todo(fn?: SuiteFn): Promise<void>;
|
213
|
+
/**
|
214
|
+
* Shorthand for marking a suite as `only`. This is the same as [`describe([name], { only: true }[, fn])`](https://nodejs.org/docs/latest-v20.x/api/test.html#describename-options-fn).
|
215
|
+
* @since v18.15.0
|
216
|
+
*/
|
217
|
+
function only(name?: string, options?: TestOptions, fn?: SuiteFn): Promise<void>;
|
218
|
+
function only(name?: string, fn?: SuiteFn): Promise<void>;
|
219
|
+
function only(options?: TestOptions, fn?: SuiteFn): Promise<void>;
|
220
|
+
function only(fn?: SuiteFn): Promise<void>;
|
221
|
+
}
|
222
|
+
/**
|
223
|
+
* Alias for `test()`.
|
224
|
+
*
|
225
|
+
* The `it()` function is imported from the `node:test` module.
|
226
|
+
* @since v18.6.0, v16.17.0
|
227
|
+
*/
|
228
|
+
function it(name?: string, options?: TestOptions, fn?: TestFn): Promise<void>;
|
229
|
+
function it(name?: string, fn?: TestFn): Promise<void>;
|
230
|
+
function it(options?: TestOptions, fn?: TestFn): Promise<void>;
|
231
|
+
function it(fn?: TestFn): Promise<void>;
|
232
|
+
namespace it {
|
233
|
+
/**
|
234
|
+
* Shorthand for skipping a test, same as `it([name], { skip: true }[, fn])`.
|
235
|
+
*/
|
236
|
+
function skip(name?: string, options?: TestOptions, fn?: TestFn): Promise<void>;
|
237
|
+
function skip(name?: string, fn?: TestFn): Promise<void>;
|
238
|
+
function skip(options?: TestOptions, fn?: TestFn): Promise<void>;
|
239
|
+
function skip(fn?: TestFn): Promise<void>;
|
240
|
+
/**
|
241
|
+
* Shorthand for marking a test as `TODO`, same as `it([name], { todo: true }[, fn])`.
|
242
|
+
*/
|
243
|
+
function todo(name?: string, options?: TestOptions, fn?: TestFn): Promise<void>;
|
244
|
+
function todo(name?: string, fn?: TestFn): Promise<void>;
|
245
|
+
function todo(options?: TestOptions, fn?: TestFn): Promise<void>;
|
246
|
+
function todo(fn?: TestFn): Promise<void>;
|
247
|
+
/**
|
248
|
+
* Shorthand for marking a test as `only`, same as `it([name], { only: true }[, fn])`.
|
249
|
+
* @since v18.15.0
|
250
|
+
*/
|
251
|
+
function only(name?: string, options?: TestOptions, fn?: TestFn): Promise<void>;
|
252
|
+
function only(name?: string, fn?: TestFn): Promise<void>;
|
253
|
+
function only(options?: TestOptions, fn?: TestFn): Promise<void>;
|
254
|
+
function only(fn?: TestFn): Promise<void>;
|
255
|
+
}
|
256
|
+
/**
|
257
|
+
* Shorthand for skipping a test, same as `test([name], { skip: true }[, fn])`.
|
258
|
+
* @since v20.2.0
|
259
|
+
*/
|
260
|
+
function skip(name?: string, options?: TestOptions, fn?: TestFn): Promise<void>;
|
261
|
+
function skip(name?: string, fn?: TestFn): Promise<void>;
|
262
|
+
function skip(options?: TestOptions, fn?: TestFn): Promise<void>;
|
263
|
+
function skip(fn?: TestFn): Promise<void>;
|
264
|
+
/**
|
265
|
+
* Shorthand for marking a test as `TODO`, same as `test([name], { todo: true }[, fn])`.
|
266
|
+
* @since v20.2.0
|
267
|
+
*/
|
268
|
+
function todo(name?: string, options?: TestOptions, fn?: TestFn): Promise<void>;
|
269
|
+
function todo(name?: string, fn?: TestFn): Promise<void>;
|
270
|
+
function todo(options?: TestOptions, fn?: TestFn): Promise<void>;
|
271
|
+
function todo(fn?: TestFn): Promise<void>;
|
272
|
+
/**
|
273
|
+
* Shorthand for marking a test as `only`, same as `test([name], { only: true }[, fn])`.
|
274
|
+
* @since v20.2.0
|
275
|
+
*/
|
276
|
+
function only(name?: string, options?: TestOptions, fn?: TestFn): Promise<void>;
|
277
|
+
function only(name?: string, fn?: TestFn): Promise<void>;
|
278
|
+
function only(options?: TestOptions, fn?: TestFn): Promise<void>;
|
279
|
+
function only(fn?: TestFn): Promise<void>;
|
280
|
+
/**
|
281
|
+
* The type of a function under test. The first argument to this function is a
|
282
|
+
* {@link TestContext} object. If the test uses callbacks, the callback function is passed as
|
283
|
+
* the second argument.
|
284
|
+
*/
|
285
|
+
type TestFn = (t: TestContext, done: (result?: any) => void) => void | Promise<void>;
|
286
|
+
/**
|
287
|
+
* The type of a function under Suite.
|
288
|
+
*/
|
289
|
+
type SuiteFn = (s: SuiteContext) => void | Promise<void>;
|
290
|
+
interface TestShard {
|
291
|
+
/**
|
292
|
+
* A positive integer between 1 and `<total>` that specifies the index of the shard to run.
|
293
|
+
*/
|
294
|
+
index: number;
|
295
|
+
/**
|
296
|
+
* A positive integer that specifies the total number of shards to split the test files to.
|
297
|
+
*/
|
298
|
+
total: number;
|
299
|
+
}
|
300
|
+
interface RunOptions {
|
301
|
+
/**
|
302
|
+
* If a number is provided, then that many test processes would run in parallel, where each process corresponds to one test file.
|
303
|
+
* If `true`, it would run `os.availableParallelism() - 1` test files in parallel. If `false`, it would only run one test file at a time.
|
304
|
+
* @default false
|
305
|
+
*/
|
306
|
+
concurrency?: number | boolean | undefined;
|
307
|
+
/**
|
308
|
+
* An array containing the list of files to run. **Default** matching files from
|
309
|
+
* [test runner execution model](https://nodejs.org/docs/latest-v20.x/api/test.html#test-runner-execution-model).
|
310
|
+
*/
|
311
|
+
files?: readonly string[] | undefined;
|
312
|
+
/**
|
313
|
+
* Configures the test runner to exit the process once all known
|
314
|
+
* tests have finished executing even if the event loop would
|
315
|
+
* otherwise remain active.
|
316
|
+
* @default false
|
317
|
+
*/
|
318
|
+
forceExit?: boolean | undefined;
|
319
|
+
/**
|
320
|
+
* Sets inspector port of test child process.
|
321
|
+
* If a nullish value is provided, each process gets its own port,
|
322
|
+
* incremented from the primary's `process.debugPort`.
|
323
|
+
* @default undefined
|
324
|
+
*/
|
325
|
+
inspectPort?: number | (() => number) | undefined;
|
326
|
+
/**
|
327
|
+
* If truthy, the test context will only run tests that have the `only` option set
|
328
|
+
*/
|
329
|
+
only?: boolean;
|
330
|
+
/**
|
331
|
+
* A function that accepts the `TestsStream` instance and can be used to setup listeners before any tests are run.
|
332
|
+
* @default undefined
|
333
|
+
*/
|
334
|
+
setup?: (root: Test) => void | Promise<void>;
|
335
|
+
/**
|
336
|
+
* Allows aborting an in-progress test execution.
|
337
|
+
*/
|
338
|
+
signal?: AbortSignal | undefined;
|
339
|
+
/**
|
340
|
+
* A String, RegExp or a RegExp Array, that can be used to only run tests whose
|
341
|
+
* name matches the provided pattern. Test name patterns are interpreted as JavaScript
|
342
|
+
* regular expressions. For each test that is executed, any corresponding test hooks,
|
343
|
+
* such as `beforeEach()`, are also run.
|
344
|
+
* @default undefined
|
345
|
+
*/
|
346
|
+
testNamePatterns?: string | RegExp | string[] | RegExp[];
|
347
|
+
/**
|
348
|
+
* A number of milliseconds the test execution will fail after.
|
349
|
+
* If unspecified, subtests inherit this value from their parent.
|
350
|
+
* @default Infinity
|
351
|
+
*/
|
352
|
+
timeout?: number | undefined;
|
353
|
+
/**
|
354
|
+
* Whether to run in watch mode or not.
|
355
|
+
* @default false
|
356
|
+
*/
|
357
|
+
watch?: boolean | undefined;
|
358
|
+
/**
|
359
|
+
* Running tests in a specific shard.
|
360
|
+
* @default undefined
|
361
|
+
*/
|
362
|
+
shard?: TestShard | undefined;
|
363
|
+
}
|
364
|
+
class Test extends AsyncResource {
|
365
|
+
concurrency: number;
|
366
|
+
nesting: number;
|
367
|
+
only: boolean;
|
368
|
+
reporter: TestsStream;
|
369
|
+
runOnlySubtests: boolean;
|
370
|
+
testNumber: number;
|
371
|
+
timeout: number | null;
|
372
|
+
}
|
373
|
+
/**
|
374
|
+
* A successful call to `run()` method will return a new `TestsStream` object, streaming a series of events representing the execution of the tests. `TestsStream` will emit events, in the
|
375
|
+
* order of the tests definition
|
376
|
+
*
|
377
|
+
* Some of the events are guaranteed to be emitted in the same order as the tests are defined, while others are emitted in the order that the tests execute.
|
378
|
+
* @since v18.9.0, v16.19.0
|
379
|
+
*/
|
380
|
+
class TestsStream extends Readable implements NodeJS.ReadableStream {
|
381
|
+
addListener(event: "test:coverage", listener: (data: TestCoverage) => void): this;
|
382
|
+
addListener(event: "test:complete", listener: (data: TestComplete) => void): this;
|
383
|
+
addListener(event: "test:dequeue", listener: (data: TestDequeue) => void): this;
|
384
|
+
addListener(event: "test:diagnostic", listener: (data: DiagnosticData) => void): this;
|
385
|
+
addListener(event: "test:enqueue", listener: (data: TestEnqueue) => void): this;
|
386
|
+
addListener(event: "test:fail", listener: (data: TestFail) => void): this;
|
387
|
+
addListener(event: "test:pass", listener: (data: TestPass) => void): this;
|
388
|
+
addListener(event: "test:plan", listener: (data: TestPlan) => void): this;
|
389
|
+
addListener(event: "test:start", listener: (data: TestStart) => void): this;
|
390
|
+
addListener(event: "test:stderr", listener: (data: TestStderr) => void): this;
|
391
|
+
addListener(event: "test:stdout", listener: (data: TestStdout) => void): this;
|
392
|
+
addListener(event: string, listener: (...args: any[]) => void): this;
|
393
|
+
emit(event: "test:coverage", data: TestCoverage): boolean;
|
394
|
+
emit(event: "test:complete", data: TestComplete): boolean;
|
395
|
+
emit(event: "test:dequeue", data: TestDequeue): boolean;
|
396
|
+
emit(event: "test:diagnostic", data: DiagnosticData): boolean;
|
397
|
+
emit(event: "test:enqueue", data: TestEnqueue): boolean;
|
398
|
+
emit(event: "test:fail", data: TestFail): boolean;
|
399
|
+
emit(event: "test:pass", data: TestPass): boolean;
|
400
|
+
emit(event: "test:plan", data: TestPlan): boolean;
|
401
|
+
emit(event: "test:start", data: TestStart): boolean;
|
402
|
+
emit(event: "test:stderr", data: TestStderr): boolean;
|
403
|
+
emit(event: "test:stdout", data: TestStdout): boolean;
|
404
|
+
emit(event: string | symbol, ...args: any[]): boolean;
|
405
|
+
on(event: "test:coverage", listener: (data: TestCoverage) => void): this;
|
406
|
+
on(event: "test:complete", listener: (data: TestComplete) => void): this;
|
407
|
+
on(event: "test:dequeue", listener: (data: TestDequeue) => void): this;
|
408
|
+
on(event: "test:diagnostic", listener: (data: DiagnosticData) => void): this;
|
409
|
+
on(event: "test:enqueue", listener: (data: TestEnqueue) => void): this;
|
410
|
+
on(event: "test:fail", listener: (data: TestFail) => void): this;
|
411
|
+
on(event: "test:pass", listener: (data: TestPass) => void): this;
|
412
|
+
on(event: "test:plan", listener: (data: TestPlan) => void): this;
|
413
|
+
on(event: "test:start", listener: (data: TestStart) => void): this;
|
414
|
+
on(event: "test:stderr", listener: (data: TestStderr) => void): this;
|
415
|
+
on(event: "test:stdout", listener: (data: TestStdout) => void): this;
|
416
|
+
on(event: string, listener: (...args: any[]) => void): this;
|
417
|
+
once(event: "test:coverage", listener: (data: TestCoverage) => void): this;
|
418
|
+
once(event: "test:complete", listener: (data: TestComplete) => void): this;
|
419
|
+
once(event: "test:dequeue", listener: (data: TestDequeue) => void): this;
|
420
|
+
once(event: "test:diagnostic", listener: (data: DiagnosticData) => void): this;
|
421
|
+
once(event: "test:enqueue", listener: (data: TestEnqueue) => void): this;
|
422
|
+
once(event: "test:fail", listener: (data: TestFail) => void): this;
|
423
|
+
once(event: "test:pass", listener: (data: TestPass) => void): this;
|
424
|
+
once(event: "test:plan", listener: (data: TestPlan) => void): this;
|
425
|
+
once(event: "test:start", listener: (data: TestStart) => void): this;
|
426
|
+
once(event: "test:stderr", listener: (data: TestStderr) => void): this;
|
427
|
+
once(event: "test:stdout", listener: (data: TestStdout) => void): this;
|
428
|
+
once(event: string, listener: (...args: any[]) => void): this;
|
429
|
+
prependListener(event: "test:coverage", listener: (data: TestCoverage) => void): this;
|
430
|
+
prependListener(event: "test:complete", listener: (data: TestComplete) => void): this;
|
431
|
+
prependListener(event: "test:dequeue", listener: (data: TestDequeue) => void): this;
|
432
|
+
prependListener(event: "test:diagnostic", listener: (data: DiagnosticData) => void): this;
|
433
|
+
prependListener(event: "test:enqueue", listener: (data: TestEnqueue) => void): this;
|
434
|
+
prependListener(event: "test:fail", listener: (data: TestFail) => void): this;
|
435
|
+
prependListener(event: "test:pass", listener: (data: TestPass) => void): this;
|
436
|
+
prependListener(event: "test:plan", listener: (data: TestPlan) => void): this;
|
437
|
+
prependListener(event: "test:start", listener: (data: TestStart) => void): this;
|
438
|
+
prependListener(event: "test:stderr", listener: (data: TestStderr) => void): this;
|
439
|
+
prependListener(event: "test:stdout", listener: (data: TestStdout) => void): this;
|
440
|
+
prependListener(event: string, listener: (...args: any[]) => void): this;
|
441
|
+
prependOnceListener(event: "test:coverage", listener: (data: TestCoverage) => void): this;
|
442
|
+
prependOnceListener(event: "test:complete", listener: (data: TestComplete) => void): this;
|
443
|
+
prependOnceListener(event: "test:dequeue", listener: (data: TestDequeue) => void): this;
|
444
|
+
prependOnceListener(event: "test:diagnostic", listener: (data: DiagnosticData) => void): this;
|
445
|
+
prependOnceListener(event: "test:enqueue", listener: (data: TestEnqueue) => void): this;
|
446
|
+
prependOnceListener(event: "test:fail", listener: (data: TestFail) => void): this;
|
447
|
+
prependOnceListener(event: "test:pass", listener: (data: TestPass) => void): this;
|
448
|
+
prependOnceListener(event: "test:plan", listener: (data: TestPlan) => void): this;
|
449
|
+
prependOnceListener(event: "test:start", listener: (data: TestStart) => void): this;
|
450
|
+
prependOnceListener(event: "test:stderr", listener: (data: TestStderr) => void): this;
|
451
|
+
prependOnceListener(event: "test:stdout", listener: (data: TestStdout) => void): this;
|
452
|
+
prependOnceListener(event: string, listener: (...args: any[]) => void): this;
|
453
|
+
}
|
454
|
+
/**
|
455
|
+
* An instance of `TestContext` is passed to each test function in order to
|
456
|
+
* interact with the test runner. However, the `TestContext` constructor is not
|
457
|
+
* exposed as part of the API.
|
458
|
+
* @since v18.0.0, v16.17.0
|
459
|
+
*/
|
460
|
+
class TestContext {
|
461
|
+
/**
|
462
|
+
* This function is used to create a hook running before subtest of the current test.
|
463
|
+
* @param fn The hook function. If the hook uses callbacks, the callback function is passed as
|
464
|
+
* the second argument. **Default:** A no-op function.
|
465
|
+
* @param options Configuration options for the hook.
|
466
|
+
* @since v20.1.0
|
467
|
+
*/
|
468
|
+
before: typeof before;
|
469
|
+
/**
|
470
|
+
* This function is used to create a hook running before each subtest of the current test.
|
471
|
+
* @param fn The hook function. If the hook uses callbacks, the callback function is passed as
|
472
|
+
* the second argument. **Default:** A no-op function.
|
473
|
+
* @param options Configuration options for the hook.
|
474
|
+
* @since v18.8.0
|
475
|
+
*/
|
476
|
+
beforeEach: typeof beforeEach;
|
477
|
+
/**
|
478
|
+
* This function is used to create a hook that runs after the current test finishes.
|
479
|
+
* @param [fn='A no-op function'] The hook function. If the hook uses callbacks, the callback function is passed as
|
480
|
+
* the second argument. Default: A no-op function.
|
481
|
+
* @param options Configuration options for the hook.
|
482
|
+
* @since v18.13.0
|
483
|
+
*/
|
484
|
+
after: typeof after;
|
485
|
+
/**
|
486
|
+
* This function is used to create a hook running after each subtest of the current test.
|
487
|
+
* @param fn The hook function. If the hook uses callbacks, the callback function is passed as
|
488
|
+
* the second argument. **Default:** A no-op function.
|
489
|
+
* @param options Configuration options for the hook.
|
490
|
+
* @since v18.8.0
|
491
|
+
*/
|
492
|
+
afterEach: typeof afterEach;
|
493
|
+
/**
|
494
|
+
* This function is used to write diagnostics to the output. Any diagnostic
|
495
|
+
* information is included at the end of the test's results. This function does
|
496
|
+
* not return a value.
|
497
|
+
*
|
498
|
+
* ```js
|
499
|
+
* test('top level test', (t) => {
|
500
|
+
* t.diagnostic('A diagnostic message');
|
501
|
+
* });
|
502
|
+
* ```
|
503
|
+
* @since v18.0.0, v16.17.0
|
504
|
+
* @param message Message to be reported.
|
505
|
+
*/
|
506
|
+
diagnostic(message: string): void;
|
507
|
+
/**
|
508
|
+
* The name of the test.
|
509
|
+
* @since v18.8.0, v16.18.0
|
510
|
+
*/
|
511
|
+
readonly name: string;
|
512
|
+
/**
|
513
|
+
* If `shouldRunOnlyTests` is truthy, the test context will only run tests that
|
514
|
+
* have the `only` option set. Otherwise, all tests are run. If Node.js was not
|
515
|
+
* started with the `--test-only` command-line option, this function is a
|
516
|
+
* no-op.
|
517
|
+
*
|
518
|
+
* ```js
|
519
|
+
* test('top level test', (t) => {
|
520
|
+
* // The test context can be set to run subtests with the 'only' option.
|
521
|
+
* t.runOnly(true);
|
522
|
+
* return Promise.all([
|
523
|
+
* t.test('this subtest is now skipped'),
|
524
|
+
* t.test('this subtest is run', { only: true }),
|
525
|
+
* ]);
|
526
|
+
* });
|
527
|
+
* ```
|
528
|
+
* @since v18.0.0, v16.17.0
|
529
|
+
* @param shouldRunOnlyTests Whether or not to run `only` tests.
|
530
|
+
*/
|
531
|
+
runOnly(shouldRunOnlyTests: boolean): void;
|
532
|
+
/**
|
533
|
+
* ```js
|
534
|
+
* test('top level test', async (t) => {
|
535
|
+
* await fetch('some/uri', { signal: t.signal });
|
536
|
+
* });
|
537
|
+
* ```
|
538
|
+
* @since v18.7.0, v16.17.0
|
539
|
+
*/
|
540
|
+
readonly signal: AbortSignal;
|
541
|
+
/**
|
542
|
+
* This function causes the test's output to indicate the test as skipped. If `message` is provided, it is included in the output. Calling `skip()` does
|
543
|
+
* not terminate execution of the test function. This function does not return a
|
544
|
+
* value.
|
545
|
+
*
|
546
|
+
* ```js
|
547
|
+
* test('top level test', (t) => {
|
548
|
+
* // Make sure to return here as well if the test contains additional logic.
|
549
|
+
* t.skip('this is skipped');
|
550
|
+
* });
|
551
|
+
* ```
|
552
|
+
* @since v18.0.0, v16.17.0
|
553
|
+
* @param message Optional skip message.
|
554
|
+
*/
|
555
|
+
skip(message?: string): void;
|
556
|
+
/**
|
557
|
+
* This function adds a `TODO` directive to the test's output. If `message` is
|
558
|
+
* provided, it is included in the output. Calling `todo()` does not terminate
|
559
|
+
* execution of the test function. This function does not return a value.
|
560
|
+
*
|
561
|
+
* ```js
|
562
|
+
* test('top level test', (t) => {
|
563
|
+
* // This test is marked as `TODO`
|
564
|
+
* t.todo('this is a todo');
|
565
|
+
* });
|
566
|
+
* ```
|
567
|
+
* @since v18.0.0, v16.17.0
|
568
|
+
* @param message Optional `TODO` message.
|
569
|
+
*/
|
570
|
+
todo(message?: string): void;
|
571
|
+
/**
|
572
|
+
* This function is used to create subtests under the current test. This function behaves in
|
573
|
+
* the same fashion as the top level {@link test} function.
|
574
|
+
* @since v18.0.0
|
575
|
+
* @param name The name of the test, which is displayed when reporting test results.
|
576
|
+
* Default: The `name` property of fn, or `'<anonymous>'` if `fn` does not have a name.
|
577
|
+
* @param options Configuration options for the test
|
578
|
+
* @param fn The function under test. This first argument to this function is a
|
579
|
+
* {@link TestContext} object. If the test uses callbacks, the callback function is
|
580
|
+
* passed as the second argument. **Default:** A no-op function.
|
581
|
+
* @returns A {@link Promise} resolved with `undefined` once the test completes.
|
582
|
+
*/
|
583
|
+
test: typeof test;
|
584
|
+
/**
|
585
|
+
* Each test provides its own MockTracker instance.
|
586
|
+
*/
|
587
|
+
readonly mock: MockTracker;
|
588
|
+
}
|
589
|
+
|
590
|
+
/**
|
591
|
+
* An instance of `SuiteContext` is passed to each suite function in order to
|
592
|
+
* interact with the test runner. However, the `SuiteContext` constructor is not
|
593
|
+
* exposed as part of the API.
|
594
|
+
* @since v18.7.0, v16.17.0
|
595
|
+
*/
|
596
|
+
class SuiteContext {
|
597
|
+
/**
|
598
|
+
* The name of the suite.
|
599
|
+
* @since v18.8.0, v16.18.0
|
600
|
+
*/
|
601
|
+
readonly name: string;
|
602
|
+
/**
|
603
|
+
* Can be used to abort test subtasks when the test has been aborted.
|
604
|
+
* @since v18.7.0, v16.17.0
|
605
|
+
*/
|
606
|
+
readonly signal: AbortSignal;
|
607
|
+
}
|
608
|
+
interface TestOptions {
|
609
|
+
/**
|
610
|
+
* If a number is provided, then that many tests would run in parallel.
|
611
|
+
* If truthy, it would run (number of cpu cores - 1) tests in parallel.
|
612
|
+
* For subtests, it will be `Infinity` tests in parallel.
|
613
|
+
* If falsy, it would only run one test at a time.
|
614
|
+
* If unspecified, subtests inherit this value from their parent.
|
615
|
+
* @default false
|
616
|
+
*/
|
617
|
+
concurrency?: number | boolean | undefined;
|
618
|
+
/**
|
619
|
+
* If truthy, and the test context is configured to run `only` tests, then this test will be
|
620
|
+
* run. Otherwise, the test is skipped.
|
621
|
+
* @default false
|
622
|
+
*/
|
623
|
+
only?: boolean | undefined;
|
624
|
+
/**
|
625
|
+
* Allows aborting an in-progress test.
|
626
|
+
* @since v18.8.0
|
627
|
+
*/
|
628
|
+
signal?: AbortSignal | undefined;
|
629
|
+
/**
|
630
|
+
* If truthy, the test is skipped. If a string is provided, that string is displayed in the
|
631
|
+
* test results as the reason for skipping the test.
|
632
|
+
* @default false
|
633
|
+
*/
|
634
|
+
skip?: boolean | string | undefined;
|
635
|
+
/**
|
636
|
+
* A number of milliseconds the test will fail after. If unspecified, subtests inherit this
|
637
|
+
* value from their parent.
|
638
|
+
* @default Infinity
|
639
|
+
* @since v18.7.0
|
640
|
+
*/
|
641
|
+
timeout?: number | undefined;
|
642
|
+
/**
|
643
|
+
* If truthy, the test marked as `TODO`. If a string is provided, that string is displayed in
|
644
|
+
* the test results as the reason why the test is `TODO`.
|
645
|
+
* @default false
|
646
|
+
*/
|
647
|
+
todo?: boolean | string | undefined;
|
648
|
+
}
|
649
|
+
/**
|
650
|
+
* This function creates a hook that runs before executing a suite.
|
651
|
+
*
|
652
|
+
* ```js
|
653
|
+
* describe('tests', async () => {
|
654
|
+
* before(() => console.log('about to run some test'));
|
655
|
+
* it('is a subtest', () => {
|
656
|
+
* assert.ok('some relevant assertion here');
|
657
|
+
* });
|
658
|
+
* });
|
659
|
+
* ```
|
660
|
+
* @since v18.8.0, v16.18.0
|
661
|
+
* @param [fn='A no-op function'] The hook function. If the hook uses callbacks, the callback function is passed as the second argument.
|
662
|
+
* @param options Configuration options for the hook. The following properties are supported:
|
663
|
+
*/
|
664
|
+
function before(fn?: HookFn, options?: HookOptions): void;
|
665
|
+
/**
|
666
|
+
* This function creates a hook that runs after executing a suite.
|
667
|
+
*
|
668
|
+
* ```js
|
669
|
+
* describe('tests', async () => {
|
670
|
+
* after(() => console.log('finished running tests'));
|
671
|
+
* it('is a subtest', () => {
|
672
|
+
* assert.ok('some relevant assertion here');
|
673
|
+
* });
|
674
|
+
* });
|
675
|
+
* ```
|
676
|
+
* @since v18.8.0, v16.18.0
|
677
|
+
* @param [fn='A no-op function'] The hook function. If the hook uses callbacks, the callback function is passed as the second argument.
|
678
|
+
* @param options Configuration options for the hook. The following properties are supported:
|
679
|
+
*/
|
680
|
+
function after(fn?: HookFn, options?: HookOptions): void;
|
681
|
+
/**
|
682
|
+
* This function creates a hook that runs before each test in the current suite.
|
683
|
+
*
|
684
|
+
* ```js
|
685
|
+
* describe('tests', async () => {
|
686
|
+
* beforeEach(() => console.log('about to run a test'));
|
687
|
+
* it('is a subtest', () => {
|
688
|
+
* assert.ok('some relevant assertion here');
|
689
|
+
* });
|
690
|
+
* });
|
691
|
+
* ```
|
692
|
+
* @since v18.8.0, v16.18.0
|
693
|
+
* @param [fn='A no-op function'] The hook function. If the hook uses callbacks, the callback function is passed as the second argument.
|
694
|
+
* @param options Configuration options for the hook. The following properties are supported:
|
695
|
+
*/
|
696
|
+
function beforeEach(fn?: HookFn, options?: HookOptions): void;
|
697
|
+
/**
|
698
|
+
* This function creates a hook that runs after each test in the current suite.
|
699
|
+
* The `afterEach()` hook is run even if the test fails.
|
700
|
+
*
|
701
|
+
* ```js
|
702
|
+
* describe('tests', async () => {
|
703
|
+
* afterEach(() => console.log('finished running a test'));
|
704
|
+
* it('is a subtest', () => {
|
705
|
+
* assert.ok('some relevant assertion here');
|
706
|
+
* });
|
707
|
+
* });
|
708
|
+
* ```
|
709
|
+
* @since v18.8.0, v16.18.0
|
710
|
+
* @param [fn='A no-op function'] The hook function. If the hook uses callbacks, the callback function is passed as the second argument.
|
711
|
+
* @param options Configuration options for the hook. The following properties are supported:
|
712
|
+
*/
|
713
|
+
function afterEach(fn?: HookFn, options?: HookOptions): void;
|
714
|
+
/**
|
715
|
+
* The hook function. If the hook uses callbacks, the callback function is passed as the
|
716
|
+
* second argument.
|
717
|
+
*/
|
718
|
+
type HookFn = (s: SuiteContext, done: (result?: any) => void) => any;
|
719
|
+
/**
|
720
|
+
* Configuration options for hooks.
|
721
|
+
* @since v18.8.0
|
722
|
+
*/
|
723
|
+
interface HookOptions {
|
724
|
+
/**
|
725
|
+
* Allows aborting an in-progress hook.
|
726
|
+
*/
|
727
|
+
signal?: AbortSignal | undefined;
|
728
|
+
/**
|
729
|
+
* A number of milliseconds the hook will fail after. If unspecified, subtests inherit this
|
730
|
+
* value from their parent.
|
731
|
+
* @default Infinity
|
732
|
+
*/
|
733
|
+
timeout?: number | undefined;
|
734
|
+
}
|
735
|
+
interface MockFunctionOptions {
|
736
|
+
/**
|
737
|
+
* The number of times that the mock will use the behavior of `implementation`.
|
738
|
+
* Once the mock function has been called `times` times,
|
739
|
+
* it will automatically restore the behavior of `original`.
|
740
|
+
* This value must be an integer greater than zero.
|
741
|
+
* @default Infinity
|
742
|
+
*/
|
743
|
+
times?: number | undefined;
|
744
|
+
}
|
745
|
+
interface MockMethodOptions extends MockFunctionOptions {
|
746
|
+
/**
|
747
|
+
* If `true`, `object[methodName]` is treated as a getter.
|
748
|
+
* This option cannot be used with the `setter` option.
|
749
|
+
*/
|
750
|
+
getter?: boolean | undefined;
|
751
|
+
/**
|
752
|
+
* If `true`, `object[methodName]` is treated as a setter.
|
753
|
+
* This option cannot be used with the `getter` option.
|
754
|
+
*/
|
755
|
+
setter?: boolean | undefined;
|
756
|
+
}
|
757
|
+
type Mock<F extends Function> = F & {
|
758
|
+
mock: MockFunctionContext<F>;
|
759
|
+
};
|
760
|
+
type NoOpFunction = (...args: any[]) => undefined;
|
761
|
+
type FunctionPropertyNames<T> = {
|
762
|
+
[K in keyof T]: T[K] extends Function ? K : never;
|
763
|
+
}[keyof T];
|
764
|
+
/**
|
765
|
+
* The `MockTracker` class is used to manage mocking functionality. The test runner
|
766
|
+
* module provides a top level `mock` export which is a `MockTracker` instance.
|
767
|
+
* Each test also provides its own `MockTracker` instance via the test context's `mock` property.
|
768
|
+
* @since v19.1.0, v18.13.0
|
769
|
+
*/
|
770
|
+
class MockTracker {
|
771
|
+
/**
|
772
|
+
* This function is used to create a mock function.
|
773
|
+
*
|
774
|
+
* The following example creates a mock function that increments a counter by one
|
775
|
+
* on each invocation. The `times` option is used to modify the mock behavior such
|
776
|
+
* that the first two invocations add two to the counter instead of one.
|
777
|
+
*
|
778
|
+
* ```js
|
779
|
+
* test('mocks a counting function', (t) => {
|
780
|
+
* let cnt = 0;
|
781
|
+
*
|
782
|
+
* function addOne() {
|
783
|
+
* cnt++;
|
784
|
+
* return cnt;
|
785
|
+
* }
|
786
|
+
*
|
787
|
+
* function addTwo() {
|
788
|
+
* cnt += 2;
|
789
|
+
* return cnt;
|
790
|
+
* }
|
791
|
+
*
|
792
|
+
* const fn = t.mock.fn(addOne, addTwo, { times: 2 });
|
793
|
+
*
|
794
|
+
* assert.strictEqual(fn(), 2);
|
795
|
+
* assert.strictEqual(fn(), 4);
|
796
|
+
* assert.strictEqual(fn(), 5);
|
797
|
+
* assert.strictEqual(fn(), 6);
|
798
|
+
* });
|
799
|
+
* ```
|
800
|
+
* @since v19.1.0, v18.13.0
|
801
|
+
* @param [original='A no-op function'] An optional function to create a mock on.
|
802
|
+
* @param implementation An optional function used as the mock implementation for `original`. This is useful for creating mocks that exhibit one behavior for a specified number of calls and
|
803
|
+
* then restore the behavior of `original`.
|
804
|
+
* @param options Optional configuration options for the mock function. The following properties are supported:
|
805
|
+
* @return The mocked function. The mocked function contains a special `mock` property, which is an instance of {@link MockFunctionContext}, and can be used for inspecting and changing the
|
806
|
+
* behavior of the mocked function.
|
807
|
+
*/
|
808
|
+
fn<F extends Function = NoOpFunction>(original?: F, options?: MockFunctionOptions): Mock<F>;
|
809
|
+
fn<F extends Function = NoOpFunction, Implementation extends Function = F>(
|
810
|
+
original?: F,
|
811
|
+
implementation?: Implementation,
|
812
|
+
options?: MockFunctionOptions,
|
813
|
+
): Mock<F | Implementation>;
|
814
|
+
/**
|
815
|
+
* This function is used to create a mock on an existing object method. The
|
816
|
+
* following example demonstrates how a mock is created on an existing object
|
817
|
+
* method.
|
818
|
+
*
|
819
|
+
* ```js
|
820
|
+
* test('spies on an object method', (t) => {
|
821
|
+
* const number = {
|
822
|
+
* value: 5,
|
823
|
+
* subtract(a) {
|
824
|
+
* return this.value - a;
|
825
|
+
* },
|
826
|
+
* };
|
827
|
+
*
|
828
|
+
* t.mock.method(number, 'subtract');
|
829
|
+
* assert.strictEqual(number.subtract.mock.calls.length, 0);
|
830
|
+
* assert.strictEqual(number.subtract(3), 2);
|
831
|
+
* assert.strictEqual(number.subtract.mock.calls.length, 1);
|
832
|
+
*
|
833
|
+
* const call = number.subtract.mock.calls[0];
|
834
|
+
*
|
835
|
+
* assert.deepStrictEqual(call.arguments, [3]);
|
836
|
+
* assert.strictEqual(call.result, 2);
|
837
|
+
* assert.strictEqual(call.error, undefined);
|
838
|
+
* assert.strictEqual(call.target, undefined);
|
839
|
+
* assert.strictEqual(call.this, number);
|
840
|
+
* });
|
841
|
+
* ```
|
842
|
+
* @since v19.1.0, v18.13.0
|
843
|
+
* @param object The object whose method is being mocked.
|
844
|
+
* @param methodName The identifier of the method on `object` to mock. If `object[methodName]` is not a function, an error is thrown.
|
845
|
+
* @param implementation An optional function used as the mock implementation for `object[methodName]`.
|
846
|
+
* @param options Optional configuration options for the mock method. The following properties are supported:
|
847
|
+
* @return The mocked method. The mocked method contains a special `mock` property, which is an instance of {@link MockFunctionContext}, and can be used for inspecting and changing the
|
848
|
+
* behavior of the mocked method.
|
849
|
+
*/
|
850
|
+
method<
|
851
|
+
MockedObject extends object,
|
852
|
+
MethodName extends FunctionPropertyNames<MockedObject>,
|
853
|
+
>(
|
854
|
+
object: MockedObject,
|
855
|
+
methodName: MethodName,
|
856
|
+
options?: MockFunctionOptions,
|
857
|
+
): MockedObject[MethodName] extends Function ? Mock<MockedObject[MethodName]>
|
858
|
+
: never;
|
859
|
+
method<
|
860
|
+
MockedObject extends object,
|
861
|
+
MethodName extends FunctionPropertyNames<MockedObject>,
|
862
|
+
Implementation extends Function,
|
863
|
+
>(
|
864
|
+
object: MockedObject,
|
865
|
+
methodName: MethodName,
|
866
|
+
implementation: Implementation,
|
867
|
+
options?: MockFunctionOptions,
|
868
|
+
): MockedObject[MethodName] extends Function ? Mock<MockedObject[MethodName] | Implementation>
|
869
|
+
: never;
|
870
|
+
method<MockedObject extends object>(
|
871
|
+
object: MockedObject,
|
872
|
+
methodName: keyof MockedObject,
|
873
|
+
options: MockMethodOptions,
|
874
|
+
): Mock<Function>;
|
875
|
+
method<MockedObject extends object>(
|
876
|
+
object: MockedObject,
|
877
|
+
methodName: keyof MockedObject,
|
878
|
+
implementation: Function,
|
879
|
+
options: MockMethodOptions,
|
880
|
+
): Mock<Function>;
|
881
|
+
|
882
|
+
/**
|
883
|
+
* This function is syntax sugar for `MockTracker.method` with `options.getter` set to `true`.
|
884
|
+
* @since v19.3.0, v18.13.0
|
885
|
+
*/
|
886
|
+
getter<
|
887
|
+
MockedObject extends object,
|
888
|
+
MethodName extends keyof MockedObject,
|
889
|
+
>(
|
890
|
+
object: MockedObject,
|
891
|
+
methodName: MethodName,
|
892
|
+
options?: MockFunctionOptions,
|
893
|
+
): Mock<() => MockedObject[MethodName]>;
|
894
|
+
getter<
|
895
|
+
MockedObject extends object,
|
896
|
+
MethodName extends keyof MockedObject,
|
897
|
+
Implementation extends Function,
|
898
|
+
>(
|
899
|
+
object: MockedObject,
|
900
|
+
methodName: MethodName,
|
901
|
+
implementation?: Implementation,
|
902
|
+
options?: MockFunctionOptions,
|
903
|
+
): Mock<(() => MockedObject[MethodName]) | Implementation>;
|
904
|
+
/**
|
905
|
+
* This function is syntax sugar for `MockTracker.method` with `options.setter` set to `true`.
|
906
|
+
* @since v19.3.0, v18.13.0
|
907
|
+
*/
|
908
|
+
setter<
|
909
|
+
MockedObject extends object,
|
910
|
+
MethodName extends keyof MockedObject,
|
911
|
+
>(
|
912
|
+
object: MockedObject,
|
913
|
+
methodName: MethodName,
|
914
|
+
options?: MockFunctionOptions,
|
915
|
+
): Mock<(value: MockedObject[MethodName]) => void>;
|
916
|
+
setter<
|
917
|
+
MockedObject extends object,
|
918
|
+
MethodName extends keyof MockedObject,
|
919
|
+
Implementation extends Function,
|
920
|
+
>(
|
921
|
+
object: MockedObject,
|
922
|
+
methodName: MethodName,
|
923
|
+
implementation?: Implementation,
|
924
|
+
options?: MockFunctionOptions,
|
925
|
+
): Mock<((value: MockedObject[MethodName]) => void) | Implementation>;
|
926
|
+
/**
|
927
|
+
* This function restores the default behavior of all mocks that were previously
|
928
|
+
* created by this `MockTracker` and disassociates the mocks from the `MockTracker` instance. Once disassociated, the mocks can still be used, but the `MockTracker` instance can no longer be
|
929
|
+
* used to reset their behavior or
|
930
|
+
* otherwise interact with them.
|
931
|
+
*
|
932
|
+
* After each test completes, this function is called on the test context's `MockTracker`. If the global `MockTracker` is used extensively, calling this
|
933
|
+
* function manually is recommended.
|
934
|
+
* @since v19.1.0, v18.13.0
|
935
|
+
*/
|
936
|
+
reset(): void;
|
937
|
+
/**
|
938
|
+
* This function restores the default behavior of all mocks that were previously
|
939
|
+
* created by this `MockTracker`. Unlike `mock.reset()`, `mock.restoreAll()` does
|
940
|
+
* not disassociate the mocks from the `MockTracker` instance.
|
941
|
+
* @since v19.1.0, v18.13.0
|
942
|
+
*/
|
943
|
+
restoreAll(): void;
|
944
|
+
timers: MockTimers;
|
945
|
+
}
|
946
|
+
const mock: MockTracker;
|
947
|
+
interface MockFunctionCall<
|
948
|
+
F extends Function,
|
949
|
+
ReturnType = F extends (...args: any) => infer T ? T
|
950
|
+
: F extends abstract new(...args: any) => infer T ? T
|
951
|
+
: unknown,
|
952
|
+
Args = F extends (...args: infer Y) => any ? Y
|
953
|
+
: F extends abstract new(...args: infer Y) => any ? Y
|
954
|
+
: unknown[],
|
955
|
+
> {
|
956
|
+
/**
|
957
|
+
* An array of the arguments passed to the mock function.
|
958
|
+
*/
|
959
|
+
arguments: Args;
|
960
|
+
/**
|
961
|
+
* If the mocked function threw then this property contains the thrown value.
|
962
|
+
*/
|
963
|
+
error: unknown | undefined;
|
964
|
+
/**
|
965
|
+
* The value returned by the mocked function.
|
966
|
+
*
|
967
|
+
* If the mocked function threw, it will be `undefined`.
|
968
|
+
*/
|
969
|
+
result: ReturnType | undefined;
|
970
|
+
/**
|
971
|
+
* An `Error` object whose stack can be used to determine the callsite of the mocked function invocation.
|
972
|
+
*/
|
973
|
+
stack: Error;
|
974
|
+
/**
|
975
|
+
* If the mocked function is a constructor, this field contains the class being constructed.
|
976
|
+
* Otherwise this will be `undefined`.
|
977
|
+
*/
|
978
|
+
target: F extends abstract new(...args: any) => any ? F : undefined;
|
979
|
+
/**
|
980
|
+
* The mocked function's `this` value.
|
981
|
+
*/
|
982
|
+
this: unknown;
|
983
|
+
}
|
984
|
+
/**
|
985
|
+
* The `MockFunctionContext` class is used to inspect or manipulate the behavior of
|
986
|
+
* mocks created via the `MockTracker` APIs.
|
987
|
+
* @since v19.1.0, v18.13.0
|
988
|
+
*/
|
989
|
+
class MockFunctionContext<F extends Function> {
|
990
|
+
/**
|
991
|
+
* A getter that returns a copy of the internal array used to track calls to the
|
992
|
+
* mock. Each entry in the array is an object with the following properties.
|
993
|
+
* @since v19.1.0, v18.13.0
|
994
|
+
*/
|
995
|
+
readonly calls: Array<MockFunctionCall<F>>;
|
996
|
+
/**
|
997
|
+
* This function returns the number of times that this mock has been invoked. This
|
998
|
+
* function is more efficient than checking `ctx.calls.length` because `ctx.calls` is a getter that creates a copy of the internal call tracking array.
|
999
|
+
* @since v19.1.0, v18.13.0
|
1000
|
+
* @return The number of times that this mock has been invoked.
|
1001
|
+
*/
|
1002
|
+
callCount(): number;
|
1003
|
+
/**
|
1004
|
+
* This function is used to change the behavior of an existing mock.
|
1005
|
+
*
|
1006
|
+
* The following example creates a mock function using `t.mock.fn()`, calls the
|
1007
|
+
* mock function, and then changes the mock implementation to a different function.
|
1008
|
+
*
|
1009
|
+
* ```js
|
1010
|
+
* test('changes a mock behavior', (t) => {
|
1011
|
+
* let cnt = 0;
|
1012
|
+
*
|
1013
|
+
* function addOne() {
|
1014
|
+
* cnt++;
|
1015
|
+
* return cnt;
|
1016
|
+
* }
|
1017
|
+
*
|
1018
|
+
* function addTwo() {
|
1019
|
+
* cnt += 2;
|
1020
|
+
* return cnt;
|
1021
|
+
* }
|
1022
|
+
*
|
1023
|
+
* const fn = t.mock.fn(addOne);
|
1024
|
+
*
|
1025
|
+
* assert.strictEqual(fn(), 1);
|
1026
|
+
* fn.mock.mockImplementation(addTwo);
|
1027
|
+
* assert.strictEqual(fn(), 3);
|
1028
|
+
* assert.strictEqual(fn(), 5);
|
1029
|
+
* });
|
1030
|
+
* ```
|
1031
|
+
* @since v19.1.0, v18.13.0
|
1032
|
+
* @param implementation The function to be used as the mock's new implementation.
|
1033
|
+
*/
|
1034
|
+
mockImplementation(implementation: Function): void;
|
1035
|
+
/**
|
1036
|
+
* This function is used to change the behavior of an existing mock for a single
|
1037
|
+
* invocation. Once invocation `onCall` has occurred, the mock will revert to
|
1038
|
+
* whatever behavior it would have used had `mockImplementationOnce()` not been
|
1039
|
+
* called.
|
1040
|
+
*
|
1041
|
+
* The following example creates a mock function using `t.mock.fn()`, calls the
|
1042
|
+
* mock function, changes the mock implementation to a different function for the
|
1043
|
+
* next invocation, and then resumes its previous behavior.
|
1044
|
+
*
|
1045
|
+
* ```js
|
1046
|
+
* test('changes a mock behavior once', (t) => {
|
1047
|
+
* let cnt = 0;
|
1048
|
+
*
|
1049
|
+
* function addOne() {
|
1050
|
+
* cnt++;
|
1051
|
+
* return cnt;
|
1052
|
+
* }
|
1053
|
+
*
|
1054
|
+
* function addTwo() {
|
1055
|
+
* cnt += 2;
|
1056
|
+
* return cnt;
|
1057
|
+
* }
|
1058
|
+
*
|
1059
|
+
* const fn = t.mock.fn(addOne);
|
1060
|
+
*
|
1061
|
+
* assert.strictEqual(fn(), 1);
|
1062
|
+
* fn.mock.mockImplementationOnce(addTwo);
|
1063
|
+
* assert.strictEqual(fn(), 3);
|
1064
|
+
* assert.strictEqual(fn(), 4);
|
1065
|
+
* });
|
1066
|
+
* ```
|
1067
|
+
* @since v19.1.0, v18.13.0
|
1068
|
+
* @param implementation The function to be used as the mock's implementation for the invocation number specified by `onCall`.
|
1069
|
+
* @param onCall The invocation number that will use `implementation`. If the specified invocation has already occurred then an exception is thrown.
|
1070
|
+
*/
|
1071
|
+
mockImplementationOnce(implementation: Function, onCall?: number): void;
|
1072
|
+
/**
|
1073
|
+
* Resets the call history of the mock function.
|
1074
|
+
* @since v19.3.0, v18.13.0
|
1075
|
+
*/
|
1076
|
+
resetCalls(): void;
|
1077
|
+
/**
|
1078
|
+
* Resets the implementation of the mock function to its original behavior. The
|
1079
|
+
* mock can still be used after calling this function.
|
1080
|
+
* @since v19.1.0, v18.13.0
|
1081
|
+
*/
|
1082
|
+
restore(): void;
|
1083
|
+
}
|
1084
|
+
type Timer = "setInterval" | "setTimeout" | "setImmediate" | "Date";
|
1085
|
+
|
1086
|
+
interface MockTimersOptions {
|
1087
|
+
apis: Timer[];
|
1088
|
+
now?: number | Date;
|
1089
|
+
}
|
1090
|
+
/**
|
1091
|
+
* Mocking timers is a technique commonly used in software testing to simulate and
|
1092
|
+
* control the behavior of timers, such as `setInterval` and `setTimeout`,
|
1093
|
+
* without actually waiting for the specified time intervals.
|
1094
|
+
*
|
1095
|
+
* The MockTimers API also allows for mocking of the `Date` constructor and
|
1096
|
+
* `setImmediate`/`clearImmediate` functions.
|
1097
|
+
*
|
1098
|
+
* The `MockTracker` provides a top-level `timers` export
|
1099
|
+
* which is a `MockTimers` instance.
|
1100
|
+
* @since v20.4.0
|
1101
|
+
* @experimental
|
1102
|
+
*/
|
1103
|
+
class MockTimers {
|
1104
|
+
/**
|
1105
|
+
* Enables timer mocking for the specified timers.
|
1106
|
+
*
|
1107
|
+
* **Note:** When you enable mocking for a specific timer, its associated
|
1108
|
+
* clear function will also be implicitly mocked.
|
1109
|
+
*
|
1110
|
+
* **Note:** Mocking `Date` will affect the behavior of the mocked timers
|
1111
|
+
* as they use the same internal clock.
|
1112
|
+
*
|
1113
|
+
* Example usage without setting initial time:
|
1114
|
+
*
|
1115
|
+
* ```js
|
1116
|
+
* import { mock } from 'node:test';
|
1117
|
+
* mock.timers.enable({ apis: ['setInterval', 'Date'], now: 1234 });
|
1118
|
+
* ```
|
1119
|
+
*
|
1120
|
+
* The above example enables mocking for the `Date` constructor, `setInterval` timer and
|
1121
|
+
* implicitly mocks the `clearInterval` function. Only the `Date` constructor from `globalThis`,
|
1122
|
+
* `setInterval` and `clearInterval` functions from `node:timers`, `node:timers/promises`, and `globalThis` will be mocked.
|
1123
|
+
*
|
1124
|
+
* Example usage with initial time set
|
1125
|
+
*
|
1126
|
+
* ```js
|
1127
|
+
* import { mock } from 'node:test';
|
1128
|
+
* mock.timers.enable({ apis: ['Date'], now: 1000 });
|
1129
|
+
* ```
|
1130
|
+
*
|
1131
|
+
* Example usage with initial Date object as time set
|
1132
|
+
*
|
1133
|
+
* ```js
|
1134
|
+
* import { mock } from 'node:test';
|
1135
|
+
* mock.timers.enable({ apis: ['Date'], now: new Date() });
|
1136
|
+
* ```
|
1137
|
+
*
|
1138
|
+
* Alternatively, if you call `mock.timers.enable()` without any parameters:
|
1139
|
+
*
|
1140
|
+
* All timers (`'setInterval'`, `'clearInterval'`, `'Date'`, `'setImmediate'`, `'clearImmediate'`, `'setTimeout'`, and `'clearTimeout'`)
|
1141
|
+
* will be mocked.
|
1142
|
+
*
|
1143
|
+
* The `setInterval`, `clearInterval`, `setTimeout`, and `clearTimeout` functions from `node:timers`, `node:timers/promises`,
|
1144
|
+
* and `globalThis` will be mocked.
|
1145
|
+
* The `Date` constructor from `globalThis` will be mocked.
|
1146
|
+
*
|
1147
|
+
* If there is no initial epoch set, the initial date will be based on 0 in the Unix epoch. This is `January 1st, 1970, 00:00:00 UTC`. You can
|
1148
|
+
* set an initial date by passing a now property to the `.enable()` method. This value will be used as the initial date for the mocked Date
|
1149
|
+
* object. It can either be a positive integer, or another Date object.
|
1150
|
+
* @since v20.4.0
|
1151
|
+
*/
|
1152
|
+
enable(options?: MockTimersOptions): void;
|
1153
|
+
/**
|
1154
|
+
* You can use the `.setTime()` method to manually move the mocked date to another time. This method only accepts a positive integer.
|
1155
|
+
* Note: This method will execute any mocked timers that are in the past from the new time.
|
1156
|
+
* In the below example we are setting a new time for the mocked date.
|
1157
|
+
* ```js
|
1158
|
+
* import assert from 'node:assert';
|
1159
|
+
* import { test } from 'node:test';
|
1160
|
+
* test('sets the time of a date object', (context) => {
|
1161
|
+
* // Optionally choose what to mock
|
1162
|
+
* context.mock.timers.enable({ apis: ['Date'], now: 100 });
|
1163
|
+
* assert.strictEqual(Date.now(), 100);
|
1164
|
+
* // Advance in time will also advance the date
|
1165
|
+
* context.mock.timers.setTime(1000);
|
1166
|
+
* context.mock.timers.tick(200);
|
1167
|
+
* assert.strictEqual(Date.now(), 1200);
|
1168
|
+
* });
|
1169
|
+
* ```
|
1170
|
+
*/
|
1171
|
+
setTime(time: number): void;
|
1172
|
+
/**
|
1173
|
+
* This function restores the default behavior of all mocks that were previously
|
1174
|
+
* created by this `MockTimers` instance and disassociates the mocks
|
1175
|
+
* from the `MockTracker` instance.
|
1176
|
+
*
|
1177
|
+
* **Note:** After each test completes, this function is called on
|
1178
|
+
* the test context's `MockTracker`.
|
1179
|
+
*
|
1180
|
+
* ```js
|
1181
|
+
* import { mock } from 'node:test';
|
1182
|
+
* mock.timers.reset();
|
1183
|
+
* ```
|
1184
|
+
* @since v20.4.0
|
1185
|
+
*/
|
1186
|
+
reset(): void;
|
1187
|
+
/**
|
1188
|
+
* Advances time for all mocked timers.
|
1189
|
+
*
|
1190
|
+
* **Note:** This diverges from how `setTimeout` in Node.js behaves and accepts
|
1191
|
+
* only positive numbers. In Node.js, `setTimeout` with negative numbers is
|
1192
|
+
* only supported for web compatibility reasons.
|
1193
|
+
*
|
1194
|
+
* The following example mocks a `setTimeout` function and
|
1195
|
+
* by using `.tick` advances in
|
1196
|
+
* time triggering all pending timers.
|
1197
|
+
*
|
1198
|
+
* ```js
|
1199
|
+
* import assert from 'node:assert';
|
1200
|
+
* import { test } from 'node:test';
|
1201
|
+
*
|
1202
|
+
* test('mocks setTimeout to be executed synchronously without having to actually wait for it', (context) => {
|
1203
|
+
* const fn = context.mock.fn();
|
1204
|
+
*
|
1205
|
+
* context.mock.timers.enable({ apis: ['setTimeout'] });
|
1206
|
+
*
|
1207
|
+
* setTimeout(fn, 9999);
|
1208
|
+
*
|
1209
|
+
* assert.strictEqual(fn.mock.callCount(), 0);
|
1210
|
+
*
|
1211
|
+
* // Advance in time
|
1212
|
+
* context.mock.timers.tick(9999);
|
1213
|
+
*
|
1214
|
+
* assert.strictEqual(fn.mock.callCount(), 1);
|
1215
|
+
* });
|
1216
|
+
* ```
|
1217
|
+
*
|
1218
|
+
* Alternativelly, the `.tick` function can be called many times
|
1219
|
+
*
|
1220
|
+
* ```js
|
1221
|
+
* import assert from 'node:assert';
|
1222
|
+
* import { test } from 'node:test';
|
1223
|
+
*
|
1224
|
+
* test('mocks setTimeout to be executed synchronously without having to actually wait for it', (context) => {
|
1225
|
+
* const fn = context.mock.fn();
|
1226
|
+
* context.mock.timers.enable({ apis: ['setTimeout'] });
|
1227
|
+
* const nineSecs = 9000;
|
1228
|
+
* setTimeout(fn, nineSecs);
|
1229
|
+
*
|
1230
|
+
* const twoSeconds = 3000;
|
1231
|
+
* context.mock.timers.tick(twoSeconds);
|
1232
|
+
* context.mock.timers.tick(twoSeconds);
|
1233
|
+
* context.mock.timers.tick(twoSeconds);
|
1234
|
+
*
|
1235
|
+
* assert.strictEqual(fn.mock.callCount(), 1);
|
1236
|
+
* });
|
1237
|
+
* ```
|
1238
|
+
*
|
1239
|
+
* Advancing time using `.tick` will also advance the time for any `Date` object
|
1240
|
+
* created after the mock was enabled (if `Date` was also set to be mocked).
|
1241
|
+
*
|
1242
|
+
* ```js
|
1243
|
+
* import assert from 'node:assert';
|
1244
|
+
* import { test } from 'node:test';
|
1245
|
+
*
|
1246
|
+
* test('mocks setTimeout to be executed synchronously without having to actually wait for it', (context) => {
|
1247
|
+
* const fn = context.mock.fn();
|
1248
|
+
*
|
1249
|
+
* context.mock.timers.enable({ apis: ['setTimeout', 'Date'] });
|
1250
|
+
* setTimeout(fn, 9999);
|
1251
|
+
*
|
1252
|
+
* assert.strictEqual(fn.mock.callCount(), 0);
|
1253
|
+
* assert.strictEqual(Date.now(), 0);
|
1254
|
+
*
|
1255
|
+
* // Advance in time
|
1256
|
+
* context.mock.timers.tick(9999);
|
1257
|
+
* assert.strictEqual(fn.mock.callCount(), 1);
|
1258
|
+
* assert.strictEqual(Date.now(), 9999);
|
1259
|
+
* });
|
1260
|
+
* ```
|
1261
|
+
* @since v20.4.0
|
1262
|
+
*/
|
1263
|
+
tick(milliseconds: number): void;
|
1264
|
+
/**
|
1265
|
+
* Triggers all pending mocked timers immediately. If the `Date` object is also
|
1266
|
+
* mocked, it will also advance the `Date` object to the furthest timer's time.
|
1267
|
+
*
|
1268
|
+
* The example below triggers all pending timers immediately,
|
1269
|
+
* causing them to execute without any delay.
|
1270
|
+
*
|
1271
|
+
* ```js
|
1272
|
+
* import assert from 'node:assert';
|
1273
|
+
* import { test } from 'node:test';
|
1274
|
+
*
|
1275
|
+
* test('runAll functions following the given order', (context) => {
|
1276
|
+
* context.mock.timers.enable({ apis: ['setTimeout', 'Date'] });
|
1277
|
+
* const results = [];
|
1278
|
+
* setTimeout(() => results.push(1), 9999);
|
1279
|
+
*
|
1280
|
+
* // Notice that if both timers have the same timeout,
|
1281
|
+
* // the order of execution is guaranteed
|
1282
|
+
* setTimeout(() => results.push(3), 8888);
|
1283
|
+
* setTimeout(() => results.push(2), 8888);
|
1284
|
+
*
|
1285
|
+
* assert.deepStrictEqual(results, []);
|
1286
|
+
*
|
1287
|
+
* context.mock.timers.runAll();
|
1288
|
+
* assert.deepStrictEqual(results, [3, 2, 1]);
|
1289
|
+
* // The Date object is also advanced to the furthest timer's time
|
1290
|
+
* assert.strictEqual(Date.now(), 9999);
|
1291
|
+
* });
|
1292
|
+
* ```
|
1293
|
+
*
|
1294
|
+
* **Note:** The `runAll()` function is specifically designed for
|
1295
|
+
* triggering timers in the context of timer mocking.
|
1296
|
+
* It does not have any effect on real-time system
|
1297
|
+
* clocks or actual timers outside of the mocking environment.
|
1298
|
+
* @since v20.4.0
|
1299
|
+
*/
|
1300
|
+
runAll(): void;
|
1301
|
+
/**
|
1302
|
+
* Calls {@link MockTimers.reset()}.
|
1303
|
+
*/
|
1304
|
+
[Symbol.dispose](): void;
|
1305
|
+
}
|
1306
|
+
export {
|
1307
|
+
after,
|
1308
|
+
afterEach,
|
1309
|
+
before,
|
1310
|
+
beforeEach,
|
1311
|
+
describe,
|
1312
|
+
it,
|
1313
|
+
Mock,
|
1314
|
+
mock,
|
1315
|
+
only,
|
1316
|
+
run,
|
1317
|
+
skip,
|
1318
|
+
SuiteContext,
|
1319
|
+
test,
|
1320
|
+
test as default,
|
1321
|
+
TestContext,
|
1322
|
+
todo,
|
1323
|
+
};
|
1324
|
+
}
|
1325
|
+
|
1326
|
+
interface TestLocationInfo {
|
1327
|
+
/**
|
1328
|
+
* The column number where the test is defined, or
|
1329
|
+
* `undefined` if the test was run through the REPL.
|
1330
|
+
*/
|
1331
|
+
column?: number;
|
1332
|
+
/**
|
1333
|
+
* The path of the test file, `undefined` if test was run through the REPL.
|
1334
|
+
*/
|
1335
|
+
file?: string;
|
1336
|
+
/**
|
1337
|
+
* The line number where the test is defined, or `undefined` if the test was run through the REPL.
|
1338
|
+
*/
|
1339
|
+
line?: number;
|
1340
|
+
}
|
1341
|
+
interface DiagnosticData extends TestLocationInfo {
|
1342
|
+
/**
|
1343
|
+
* The diagnostic message.
|
1344
|
+
*/
|
1345
|
+
message: string;
|
1346
|
+
/**
|
1347
|
+
* The nesting level of the test.
|
1348
|
+
*/
|
1349
|
+
nesting: number;
|
1350
|
+
}
|
1351
|
+
interface TestCoverage {
|
1352
|
+
/**
|
1353
|
+
* An object containing the coverage report.
|
1354
|
+
*/
|
1355
|
+
summary: {
|
1356
|
+
/**
|
1357
|
+
* An array of coverage reports for individual files. Each report is an object with the following schema:
|
1358
|
+
*/
|
1359
|
+
files: Array<{
|
1360
|
+
/**
|
1361
|
+
* The absolute path of the file.
|
1362
|
+
*/
|
1363
|
+
path: string;
|
1364
|
+
/**
|
1365
|
+
* The total number of lines.
|
1366
|
+
*/
|
1367
|
+
totalLineCount: number;
|
1368
|
+
/**
|
1369
|
+
* The total number of branches.
|
1370
|
+
*/
|
1371
|
+
totalBranchCount: number;
|
1372
|
+
/**
|
1373
|
+
* The total number of functions.
|
1374
|
+
*/
|
1375
|
+
totalFunctionCount: number;
|
1376
|
+
/**
|
1377
|
+
* The number of covered lines.
|
1378
|
+
*/
|
1379
|
+
coveredLineCount: number;
|
1380
|
+
/**
|
1381
|
+
* The number of covered branches.
|
1382
|
+
*/
|
1383
|
+
coveredBranchCount: number;
|
1384
|
+
/**
|
1385
|
+
* The number of covered functions.
|
1386
|
+
*/
|
1387
|
+
coveredFunctionCount: number;
|
1388
|
+
/**
|
1389
|
+
* The percentage of lines covered.
|
1390
|
+
*/
|
1391
|
+
coveredLinePercent: number;
|
1392
|
+
/**
|
1393
|
+
* The percentage of branches covered.
|
1394
|
+
*/
|
1395
|
+
coveredBranchPercent: number;
|
1396
|
+
/**
|
1397
|
+
* The percentage of functions covered.
|
1398
|
+
*/
|
1399
|
+
coveredFunctionPercent: number;
|
1400
|
+
/**
|
1401
|
+
* An array of functions representing function coverage.
|
1402
|
+
*/
|
1403
|
+
functions: Array<{
|
1404
|
+
/**
|
1405
|
+
* The name of the function.
|
1406
|
+
*/
|
1407
|
+
name: string;
|
1408
|
+
/**
|
1409
|
+
* The line number where the function is defined.
|
1410
|
+
*/
|
1411
|
+
line: number;
|
1412
|
+
/**
|
1413
|
+
* The number of times the function was called.
|
1414
|
+
*/
|
1415
|
+
count: number;
|
1416
|
+
}>;
|
1417
|
+
/**
|
1418
|
+
* An array of lines representing line numbers and the number of times they were covered.
|
1419
|
+
*/
|
1420
|
+
lines: Array<{
|
1421
|
+
/**
|
1422
|
+
* The line number.
|
1423
|
+
*/
|
1424
|
+
line: number;
|
1425
|
+
/**
|
1426
|
+
* The number of times the line was covered.
|
1427
|
+
*/
|
1428
|
+
count: number;
|
1429
|
+
}>;
|
1430
|
+
}>;
|
1431
|
+
/**
|
1432
|
+
* An object containing a summary of coverage for all files.
|
1433
|
+
*/
|
1434
|
+
totals: {
|
1435
|
+
/**
|
1436
|
+
* The total number of lines.
|
1437
|
+
*/
|
1438
|
+
totalLineCount: number;
|
1439
|
+
/**
|
1440
|
+
* The total number of branches.
|
1441
|
+
*/
|
1442
|
+
totalBranchCount: number;
|
1443
|
+
/**
|
1444
|
+
* The total number of functions.
|
1445
|
+
*/
|
1446
|
+
totalFunctionCount: number;
|
1447
|
+
/**
|
1448
|
+
* The number of covered lines.
|
1449
|
+
*/
|
1450
|
+
coveredLineCount: number;
|
1451
|
+
/**
|
1452
|
+
* The number of covered branches.
|
1453
|
+
*/
|
1454
|
+
coveredBranchCount: number;
|
1455
|
+
/**
|
1456
|
+
* The number of covered functions.
|
1457
|
+
*/
|
1458
|
+
coveredFunctionCount: number;
|
1459
|
+
/**
|
1460
|
+
* The percentage of lines covered.
|
1461
|
+
*/
|
1462
|
+
coveredLinePercent: number;
|
1463
|
+
/**
|
1464
|
+
* The percentage of branches covered.
|
1465
|
+
*/
|
1466
|
+
coveredBranchPercent: number;
|
1467
|
+
/**
|
1468
|
+
* The percentage of functions covered.
|
1469
|
+
*/
|
1470
|
+
coveredFunctionPercent: number;
|
1471
|
+
};
|
1472
|
+
/**
|
1473
|
+
* The working directory when code coverage began. This
|
1474
|
+
* is useful for displaying relative path names in case
|
1475
|
+
* the tests changed the working directory of the Node.js process.
|
1476
|
+
*/
|
1477
|
+
workingDirectory: string;
|
1478
|
+
};
|
1479
|
+
/**
|
1480
|
+
* The nesting level of the test.
|
1481
|
+
*/
|
1482
|
+
nesting: number;
|
1483
|
+
}
|
1484
|
+
interface TestComplete extends TestLocationInfo {
|
1485
|
+
/**
|
1486
|
+
* Additional execution metadata.
|
1487
|
+
*/
|
1488
|
+
details: {
|
1489
|
+
/**
|
1490
|
+
* Whether the test passed or not.
|
1491
|
+
*/
|
1492
|
+
passed: boolean;
|
1493
|
+
/**
|
1494
|
+
* The duration of the test in milliseconds.
|
1495
|
+
*/
|
1496
|
+
duration_ms: number;
|
1497
|
+
/**
|
1498
|
+
* An error wrapping the error thrown by the test if it did not pass.
|
1499
|
+
*/
|
1500
|
+
error: Error;
|
1501
|
+
/**
|
1502
|
+
* The type of the test, used to denote whether this is a suite.
|
1503
|
+
*/
|
1504
|
+
type?: "suite";
|
1505
|
+
};
|
1506
|
+
/**
|
1507
|
+
* The test name.
|
1508
|
+
*/
|
1509
|
+
name: string;
|
1510
|
+
/**
|
1511
|
+
* The nesting level of the test.
|
1512
|
+
*/
|
1513
|
+
nesting: number;
|
1514
|
+
/**
|
1515
|
+
* The ordinal number of the test.
|
1516
|
+
*/
|
1517
|
+
testNumber: number;
|
1518
|
+
/**
|
1519
|
+
* Present if `context.todo` is called.
|
1520
|
+
*/
|
1521
|
+
todo?: string | boolean;
|
1522
|
+
/**
|
1523
|
+
* Present if `context.skip` is called.
|
1524
|
+
*/
|
1525
|
+
skip?: string | boolean;
|
1526
|
+
}
|
1527
|
+
interface TestDequeue extends TestLocationInfo {
|
1528
|
+
/**
|
1529
|
+
* The test name.
|
1530
|
+
*/
|
1531
|
+
name: string;
|
1532
|
+
/**
|
1533
|
+
* The nesting level of the test.
|
1534
|
+
*/
|
1535
|
+
nesting: number;
|
1536
|
+
}
|
1537
|
+
interface TestEnqueue extends TestLocationInfo {
|
1538
|
+
/**
|
1539
|
+
* The test name.
|
1540
|
+
*/
|
1541
|
+
name: string;
|
1542
|
+
/**
|
1543
|
+
* The nesting level of the test.
|
1544
|
+
*/
|
1545
|
+
nesting: number;
|
1546
|
+
}
|
1547
|
+
interface TestFail extends TestLocationInfo {
|
1548
|
+
/**
|
1549
|
+
* Additional execution metadata.
|
1550
|
+
*/
|
1551
|
+
details: {
|
1552
|
+
/**
|
1553
|
+
* The duration of the test in milliseconds.
|
1554
|
+
*/
|
1555
|
+
duration_ms: number;
|
1556
|
+
/**
|
1557
|
+
* An error wrapping the error thrown by the test if it did not pass.
|
1558
|
+
*/
|
1559
|
+
error: Error;
|
1560
|
+
/**
|
1561
|
+
* The type of the test, used to denote whether this is a suite.
|
1562
|
+
* @since v20.0.0, v19.9.0, v18.17.0
|
1563
|
+
*/
|
1564
|
+
type?: "suite";
|
1565
|
+
};
|
1566
|
+
/**
|
1567
|
+
* The test name.
|
1568
|
+
*/
|
1569
|
+
name: string;
|
1570
|
+
/**
|
1571
|
+
* The nesting level of the test.
|
1572
|
+
*/
|
1573
|
+
nesting: number;
|
1574
|
+
/**
|
1575
|
+
* The ordinal number of the test.
|
1576
|
+
*/
|
1577
|
+
testNumber: number;
|
1578
|
+
/**
|
1579
|
+
* Present if `context.todo` is called.
|
1580
|
+
*/
|
1581
|
+
todo?: string | boolean;
|
1582
|
+
/**
|
1583
|
+
* Present if `context.skip` is called.
|
1584
|
+
*/
|
1585
|
+
skip?: string | boolean;
|
1586
|
+
}
|
1587
|
+
interface TestPass extends TestLocationInfo {
|
1588
|
+
/**
|
1589
|
+
* Additional execution metadata.
|
1590
|
+
*/
|
1591
|
+
details: {
|
1592
|
+
/**
|
1593
|
+
* The duration of the test in milliseconds.
|
1594
|
+
*/
|
1595
|
+
duration_ms: number;
|
1596
|
+
/**
|
1597
|
+
* The type of the test, used to denote whether this is a suite.
|
1598
|
+
* @since 20.0.0, 19.9.0, 18.17.0
|
1599
|
+
*/
|
1600
|
+
type?: "suite";
|
1601
|
+
};
|
1602
|
+
/**
|
1603
|
+
* The test name.
|
1604
|
+
*/
|
1605
|
+
name: string;
|
1606
|
+
/**
|
1607
|
+
* The nesting level of the test.
|
1608
|
+
*/
|
1609
|
+
nesting: number;
|
1610
|
+
/**
|
1611
|
+
* The ordinal number of the test.
|
1612
|
+
*/
|
1613
|
+
testNumber: number;
|
1614
|
+
/**
|
1615
|
+
* Present if `context.todo` is called.
|
1616
|
+
*/
|
1617
|
+
todo?: string | boolean;
|
1618
|
+
/**
|
1619
|
+
* Present if `context.skip` is called.
|
1620
|
+
*/
|
1621
|
+
skip?: string | boolean;
|
1622
|
+
}
|
1623
|
+
interface TestPlan extends TestLocationInfo {
|
1624
|
+
/**
|
1625
|
+
* The nesting level of the test.
|
1626
|
+
*/
|
1627
|
+
nesting: number;
|
1628
|
+
/**
|
1629
|
+
* The number of subtests that have ran.
|
1630
|
+
*/
|
1631
|
+
count: number;
|
1632
|
+
}
|
1633
|
+
interface TestStart extends TestLocationInfo {
|
1634
|
+
/**
|
1635
|
+
* The test name.
|
1636
|
+
*/
|
1637
|
+
name: string;
|
1638
|
+
/**
|
1639
|
+
* The nesting level of the test.
|
1640
|
+
*/
|
1641
|
+
nesting: number;
|
1642
|
+
}
|
1643
|
+
interface TestStderr extends TestLocationInfo {
|
1644
|
+
/**
|
1645
|
+
* The message written to `stderr`.
|
1646
|
+
*/
|
1647
|
+
message: string;
|
1648
|
+
}
|
1649
|
+
interface TestStdout extends TestLocationInfo {
|
1650
|
+
/**
|
1651
|
+
* The message written to `stdout`.
|
1652
|
+
*/
|
1653
|
+
message: string;
|
1654
|
+
}
|
1655
|
+
|
1656
|
+
/**
|
1657
|
+
* The `node:test/reporters` module exposes the builtin-reporters for `node:test`.
|
1658
|
+
* To access it:
|
1659
|
+
*
|
1660
|
+
* ```js
|
1661
|
+
* import test from 'node:test/reporters';
|
1662
|
+
* ```
|
1663
|
+
*
|
1664
|
+
* This module is only available under the `node:` scheme. The following will not
|
1665
|
+
* work:
|
1666
|
+
*
|
1667
|
+
* ```js
|
1668
|
+
* import test from 'test/reporters';
|
1669
|
+
* ```
|
1670
|
+
* @since v19.9.0
|
1671
|
+
* @see [source](https://github.com/nodejs/node/blob/v20.13.1/lib/test/reporters.js)
|
1672
|
+
*/
|
1673
|
+
declare module "node:test/reporters" {
|
1674
|
+
import { Transform, TransformOptions } from "node:stream";
|
1675
|
+
|
1676
|
+
type TestEvent =
|
1677
|
+
| { type: "test:coverage"; data: TestCoverage }
|
1678
|
+
| { type: "test:complete"; data: TestComplete }
|
1679
|
+
| { type: "test:dequeue"; data: TestDequeue }
|
1680
|
+
| { type: "test:diagnostic"; data: DiagnosticData }
|
1681
|
+
| { type: "test:enqueue"; data: TestEnqueue }
|
1682
|
+
| { type: "test:fail"; data: TestFail }
|
1683
|
+
| { type: "test:pass"; data: TestPass }
|
1684
|
+
| { type: "test:plan"; data: TestPlan }
|
1685
|
+
| { type: "test:start"; data: TestStart }
|
1686
|
+
| { type: "test:stderr"; data: TestStderr }
|
1687
|
+
| { type: "test:stdout"; data: TestStdout }
|
1688
|
+
| { type: "test:watch:drained" };
|
1689
|
+
type TestEventGenerator = AsyncGenerator<TestEvent, void>;
|
1690
|
+
|
1691
|
+
/**
|
1692
|
+
* The `dot` reporter outputs the test results in a compact format,
|
1693
|
+
* where each passing test is represented by a `.`,
|
1694
|
+
* and each failing test is represented by a `X`.
|
1695
|
+
*/
|
1696
|
+
function dot(source: TestEventGenerator): AsyncGenerator<"\n" | "." | "X", void>;
|
1697
|
+
/**
|
1698
|
+
* The `tap` reporter outputs the test results in the [TAP](https://testanything.org/) format.
|
1699
|
+
*/
|
1700
|
+
function tap(source: TestEventGenerator): AsyncGenerator<string, void>;
|
1701
|
+
/**
|
1702
|
+
* The `spec` reporter outputs the test results in a human-readable format.
|
1703
|
+
*/
|
1704
|
+
class Spec extends Transform {
|
1705
|
+
constructor();
|
1706
|
+
}
|
1707
|
+
/**
|
1708
|
+
* The `junit` reporter outputs test results in a jUnit XML format.
|
1709
|
+
*/
|
1710
|
+
function junit(source: TestEventGenerator): AsyncGenerator<string, void>;
|
1711
|
+
/**
|
1712
|
+
* The `lcov` reporter outputs test coverage when used with the [`--experimental-test-coverage`](https://nodejs.org/docs/latest-v20.x/api/cli.html#--experimental-test-coverage) flag.
|
1713
|
+
*/
|
1714
|
+
class Lcov extends Transform {
|
1715
|
+
constructor(opts?: TransformOptions);
|
1716
|
+
}
|
1717
|
+
export { dot, junit, Lcov as lcov, Spec as spec, tap, TestEvent };
|
1718
|
+
}
|