From c59a61c4e5d942549173c53c93c0eaef72af80d7 Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Tue, 6 Oct 2026 02:12:55 +0000 Subject: [PATCH 01/11] Fix every type error in test/ `cd test && bun check` reported 8,080 type errors in 1,107 files, and reports none now. tsc 7.0.2 agrees on both numbers. The edits to tests are erased by the transpiler (annotations, type arguments, `!`, casts, `import type`, `// @ts-expect-error`), so no test changes what it does. test/tsconfig.json drops `baseUrl` (removed in TypeScript 7), no longer gets lib.dom from a fixture's triple-slash reference, is not `composite`, takes bun-types through `include`, and excludes vendored code and fixture apps that have their own tsconfig.json. bun-types: `test.todo(label)`, `test(label, options, fn)`, `each()` with readonly tables, `expect(await genericCall())`, `TOML.stringify()` of an object, `YAML.parse()` of bytes, `new ReadableStream({ type: "bytes" })`, `Blob#slice()` and `new TextDecoderStream(label, options)` without lib.dom, `WebView#goBack()` / `goForward()`. --- packages/bun-error/runtime-error.ts | 6 +- packages/bun-release/src/fs.ts | 8 +- packages/bun-release/src/platform.ts | 6 +- packages/bun-types/bun.d.ts | 19 +- packages/bun-types/globals.d.ts | 19 +- packages/bun-types/test.d.ts | 33 ++- scripts/build/jsonByteClass.ts | 2 +- scripts/build/xmlByteClass.ts | 2 +- test/asset-imports.d.ts | 26 +++ test/bake/bake-harness.ts | 3 +- test/bake/dev/import-meta-inline.test.ts | 18 +- .../framework/client.ts | 1 + .../framework/server.ts | 2 +- test/bundler/bun-build-compile.test.ts | 11 +- .../bundler/bundler_bytecode_portable.test.ts | 6 +- test/bundler/bundler_comments.test.ts | 4 +- .../bundler/bundler_compile_splitting.test.ts | 4 +- test/bundler/bundler_minify.test.ts | 4 +- test/bundler/bundler_plugin.test.ts | 2 +- test/bundler/bundler_plugin_chain.test.ts | 4 +- test/bundler/bundler_splitting.test.ts | 31 ++- test/bundler/cli.test.ts | 2 +- test/bundler/esbuild/css.test.ts | 3 +- test/bundler/esbuild/default.test.ts | 4 +- test/bundler/esbuild/tsconfig.test.ts | 2 + test/bundler/expectBundled.ts | 40 ++-- test/bundler/html-import-manifest.test.ts | 2 +- test/bundler/metafile.test.ts | 12 +- test/bundler/native-plugin.test.ts | 4 +- test/bundler/standalone.test.ts | 4 +- .../transpiler/decorator-metadata.test.ts | 4 +- test/bundler/transpiler/macro-test.test.ts | 35 +++- .../react-compiler-fixtures.test.ts | 3 +- test/cli/create/shadcn.tsx | 4 + test/cli/create/tailwind.tsx | 2 +- test/cli/hot/hot.test.ts | 2 +- test/cli/hot/watch-many-dirs.test.ts | 2 +- test/cli/inspect/BunFrontendDevServer.test.ts | 6 +- test/cli/inspect/test-reporter.test.ts | 2 +- test/cli/install/bun-add.test.ts | 2 +- test/cli/install/bun-audit.test.ts | 2 +- test/cli/install/bun-dedupe.test.ts | 2 +- test/cli/install/bun-install-git-deps.test.ts | 6 +- .../bun-install-native-binlink.test.ts | 2 +- test/cli/install/bun-install-registry.test.ts | 6 +- test/cli/install/bun-install.test.ts | 22 +- test/cli/install/bun-patch.test.ts | 6 +- test/cli/install/bun-prune.test.ts | 2 +- test/cli/install/bun-run.test.ts | 2 +- .../cli/install/bun-update-transitive.test.ts | 28 +-- test/cli/install/bun-upgrade.test.ts | 2 +- test/cli/install/bunx.test.ts | 2 +- test/cli/install/catalogs.test.ts | 2 +- test/cli/install/dummy.registry.ts | 2 +- test/cli/install/install-fd-leak.test.ts | 2 +- test/cli/install/isolated-install.test.ts | 8 +- test/cli/install/migrate-bun-lockb-v2.test.ts | 4 +- .../install/migration/pnpm-lock-v9.test.ts | 2 +- .../install/migration/pnpm-migration.test.ts | 2 +- test/cli/install/minimum-release-age.test.ts | 4 +- test/cli/install/npmrc.test.ts | 2 +- test/cli/install/simple-dummy-registry.ts | 2 +- test/cli/run/esm-defineProperty.test.ts | 2 +- test/cli/run/markdown-entrypoint.test.ts | 2 +- test/cli/run/no-orphans.test.ts | 16 +- test/cli/run/run_command.test.ts | 2 +- test/cli/test/isolation.test.ts | 2 +- test/cli/test/test-randomize.test.ts | 2 +- test/cli/watch/watch.test.ts | 8 +- test/cli/watch/watcher-trace.test.ts | 4 +- test/docker/index.ts | 2 +- test/harness.ts | 27 ++- test/http-test-server.ts | 2 +- test/integration/bun-types/fixture/bun.ts | 4 + test/integration/bun-types/fixture/globals.ts | 6 + test/integration/bun-types/fixture/streams.ts | 14 ++ test/integration/bun-types/fixture/test.ts | 44 ++++ test/integration/bun-types/fixture/toml.ts | 12 +- test/integration/bun-types/fixture/yaml.ts | 13 +- test/integration/nest/nest_metadata.test.ts | 2 +- .../next-pages/test/dev-server-puppeteer.ts | 7 + .../test/dev-server-ssr-100.test.ts | 4 +- .../next-pages/test/dev-server.test.ts | 2 +- test/integration/svelte/fixtures/app/index.ts | 2 + .../svelte/fixtures/client-code-on-server.ts | 6 +- .../typegraphql/src/ts_example.test.ts | 7 +- .../typegraphql/src/unsolvable.test.ts | 4 +- test/internal-for-testing.d.ts | 12 ++ test/internal/fifo.test.ts | 6 +- test/internal/macos-cross-config.test.ts | 2 +- .../source-lints/windows-cross-config.test.ts | 2 +- test/js/bun/archive-extract-leak-repro.ts | 2 +- test/js/bun/archive.test.ts | 1 - .../bun-object/deep-equals-temporal.test.ts | 4 +- test/js/bun/bun-object/deep-match.spec.ts | 2 +- test/js/bun/console/bun-inspect-table.test.ts | 20 +- test/js/bun/console/console-iterator-run-2.ts | 2 +- test/js/bun/console/console-table.test.ts | 4 +- .../cookie/cookie-expires-validation.test.ts | 8 +- test/js/bun/cookie/cookie.test.ts | 2 +- test/js/bun/cron/cron.test.ts | 2 +- .../js/bun/crypto/cipheriv-decipheriv.test.ts | 4 +- test/js/bun/crypto/x25519-derive-bits.test.ts | 8 +- test/js/bun/css/color.test.ts | 23 ++- test/js/bun/css/css-fuzz.test.ts | 2 +- test/js/bun/css/doesnt_crash.test.ts | 2 +- test/js/bun/css/util.ts | 4 +- test/js/bun/dns/resolve-dns.test.ts | 2 +- test/js/bun/fetch/node-use-system-ca.test.ts | 2 +- test/js/bun/ffi/addr32.test.ts | 3 +- test/js/bun/ffi/cc.test.ts | 3 +- test/js/bun/ffi/ffi-error-messages.test.ts | 4 +- .../bun/ffi/ffi-viewSource-non-object.test.ts | 2 +- test/js/bun/glob/proto.test.ts | 2 +- .../js/bun/http/async-iterator-stream.test.ts | 24 +-- test/js/bun/http/body-leak-test-fixture.ts | 2 +- test/js/bun/http/bun-connect-x509.test.ts | 2 +- test/js/bun/http/bun-serve-9222-fixture.ts | 6 +- test/js/bun/http/bun-serve-args.test.ts | 7 +- test/js/bun/http/bun-serve-cookies.test.ts | 8 +- .../http/bun-serve-fetch-invalid-args.test.ts | 2 +- test/js/bun/http/bun-serve-file.test.ts | 6 +- test/js/bun/http/bun-serve-headers.test.ts | 16 +- test/js/bun/http/bun-serve-html-entry.test.ts | 2 +- test/js/bun/http/bun-serve-html.test.ts | 11 +- test/js/bun/http/bun-serve-routes.test.ts | 32 +-- test/js/bun/http/bun-serve-ssl.test.ts | 24 +-- test/js/bun/http/bun-serve-static-helpers.ts | 4 +- ...un-serve-static-stress-access-body.test.ts | 3 +- .../bun-serve-static-stress-no-body.test.ts | 3 +- test/js/bun/http/bun-serve-static.test.ts | 25 ++- test/js/bun/http/bun-server.test.ts | 31 +-- test/js/bun/http/fetch-file-upload.test.ts | 4 +- test/js/bun/http/fetch-h3.ts | 2 +- .../bun/http/fetch-header-count-limit.test.ts | 6 +- test/js/bun/http/http-server-chunking.test.ts | 2 +- test/js/bun/http/http-spec.ts | 4 +- test/js/bun/http/listener-getsockname.test.ts | 2 +- .../node-http-halfclose-midupload.test.ts | 2 +- .../http/node-http-pipeline-callbacks.test.ts | 2 +- .../proxy-handshake-closed-socket-fixture.ts | 2 +- .../bun/http/proxy-stress-concurrent.test.ts | 4 +- test/js/bun/http/proxy-stress-helpers.ts | 6 +- test/js/bun/http/proxy-stress-matrix.test.ts | 6 +- .../bun/http/proxy-stress-memory-fixture.ts | 2 +- .../js/bun/http/proxy-stress-protocol.test.ts | 6 +- .../proxy-upgrade-fatal-record-fixture.ts | 6 +- test/js/bun/http/proxy.test.ts | 30 +-- test/js/bun/http/req-url-leak.test.ts | 4 +- test/js/bun/http/request-smuggling.test.ts | 88 ++++---- .../serve-close-delimited-framing.test.ts | 6 +- .../http/serve-direct-readable-stream.test.ts | 28 ++- .../bun/http/serve-directory-routes.test.ts | 4 +- ...serve-error-stream-client-abort-fixture.ts | 2 +- test/js/bun/http/serve-http2-helpers.ts | 8 +- .../js/bun/http/serve-http2-lifecycle.test.ts | 2 +- test/js/bun/http/serve-http2.test.ts | 16 +- test/js/bun/http/serve-http3.test.ts | 59 +++--- test/js/bun/http/serve-if-none-match.test.ts | 7 +- ...erve-pending-promise-abort-leak-fixture.ts | 2 +- test/js/bun/http/serve-protocols.test.ts | 5 +- .../http/serve-request-extra-memory.test.ts | 2 +- .../http/serve-split-head-close-fixture.ts | 2 +- .../bun/http/serve-split-head-stop-fixture.ts | 2 +- .../http/serve-stream-body-error-fixture.ts | 4 +- .../serve-stream-reject-flush-leak-fixture.ts | 2 +- test/js/bun/http/serve.leak.ts | 2 +- test/js/bun/http/serve.test.ts | 190 +++++++++--------- test/js/bun/image/image-adversarial.test.ts | 9 +- test/js/bun/image/image-kernels.test.ts | 7 +- test/js/bun/image/image.test.ts | 5 +- test/js/bun/jsc/bun-jsc.test.ts | 6 +- test/js/bun/jsc/heapStats-mimalloc.test.ts | 10 +- .../bun/jsc/webkit-upgrade-3722912f.test.ts | 10 +- .../bun/jsc/webkit-upgrade-7b485a76e9.test.ts | 2 +- .../bun/jsc/webkit-upgrade-ccdcb8a026.test.ts | 2 +- test/js/bun/json5/json5.test.ts | 24 ++- test/js/bun/jsonc/jsonc.test.ts | 4 +- test/js/bun/jsonl/jsonl-parse.test.ts | 2 +- test/js/bun/md/md-react.test.ts | 12 +- test/js/bun/md/md-render-callback.test.ts | 2 +- .../module-graph-callbacks.test.ts | 2 +- .../bun/module-graph/module-graph-gc.test.ts | 5 + .../bun/module-graph/module-graph-io.test.ts | 2 +- .../module-graph-isolation.test.ts | 16 +- .../module-graph/module-graph-matrix.test.ts | 2 +- test/js/bun/module-graph/module-graph.test.ts | 10 +- .../bun/net/kqueue-filter-coalesce-fixture.ts | 2 +- test/js/bun/net/socket-dns-error.test.ts | 6 +- test/js/bun/net/socket-retention.test.ts | 2 +- test/js/bun/net/socket-session-oom-fixture.ts | 2 +- test/js/bun/net/socket-syscall-fault.test.ts | 4 +- test/js/bun/net/socket.test.ts | 38 ++-- test/js/bun/net/tcp-server.test.ts | 4 +- .../bun/net/tls-close-all-sibling-fixture.ts | 2 +- test/js/bun/net/tls-low-prio-queue-fixture.ts | 2 +- .../net/tls-reject-before-client-cert.test.ts | 4 +- test/js/bun/perf_hooks/histogram.test.ts | 32 +-- .../plugin/plugin-recursive-fixture-run.ts | 1 + test/js/bun/plugin/plugins.test.ts | 7 +- test/js/bun/resolve/build-error.test.ts | 4 +- test/js/bun/resolve/esModule.test.ts | 20 +- test/js/bun/resolve/import-query.test.ts | 4 +- .../resolve/lower-using-bun-target.test.ts | 2 +- test/js/bun/resolve/toml/toml-parse.test.ts | 6 +- test/js/bun/s3/s3-argument-validation.test.ts | 1 + test/js/bun/s3/s3-fd-validation.test.ts | 5 + test/js/bun/s3/s3-requester-pays.test.ts | 4 +- test/js/bun/s3/s3.test.ts | 15 +- test/js/bun/secrets.test.ts | 18 +- test/js/bun/shell/brace.test.ts | 4 +- test/js/bun/shell/bunshell-instance.test.ts | 6 +- test/js/bun/shell/bunshell.test.ts | 2 +- test/js/bun/shell/commands/rm.test.ts | 2 +- test/js/bun/shell/leak.test.ts | 4 +- test/js/bun/shell/shelloutput.test.ts | 10 +- test/js/bun/shell/test_builder.ts | 11 +- test/js/bun/shell/util.ts | 1 - .../spawn-empty-arrayBufferOrBlob.test.ts | 2 +- test/js/bun/spawn/spawn-kill-signal.test.ts | 9 +- test/js/bun/spawn/spawn-maxbuf.test.ts | 6 +- test/js/bun/spawn/spawn-signal.test.ts | 2 +- ...n-stdin-readable-stream-edge-cases.test.ts | 2 +- .../spawn-stdout-filereader-gc-uaf.test.ts | 2 +- .../bun/spawn/spawn-streaming-stdout.test.ts | 2 +- test/js/bun/spawn/spawn-stress.test.ts | 4 +- test/js/bun/spawn/spawn.test.ts | 10 +- test/js/bun/spawn/spawnSync.test.ts | 2 +- test/js/bun/spawn/spawn_waiter_thread.test.ts | 2 +- .../stream/direct-readable-stream.test.tsx | 6 +- test/js/bun/symbols.test.ts | 4 +- test/js/bun/terminal/terminal-spawn.test.ts | 5 +- test/js/bun/terminal/terminal.test.ts | 4 +- test/js/bun/test/cross-file-safety/shared.ts | 4 +- test/js/bun/test/failure-skip.test.ts | 2 +- .../bun/test/fake-timers/fake-timers.test.ts | 4 +- .../fake-timers/sinonjs/fake-timers.test.ts | 136 +++++++------ .../sinonjs/helpers/setup-tests.ts | 14 +- .../fake-timers/sinonjs/issue-315.test.ts | 2 +- .../fake-timers/sinonjs/issue-437.test.ts | 1 + .../test/mock/mock-module-non-string.test.ts | 2 +- .../test/mock/mock-module-resolve-log.test.ts | 2 +- test/js/bun/test/mock/mock-module.test.ts | 8 +- ...-cause-duplicated-character-or-segfault.ts | 6 +- .../test-http-11425-no-payload-limit.ts | 1 + ...ould-be-true-after-the-request-listener.ts | 3 +- ...dersSent-to-true-after-headers-are-sent.ts | 3 +- .../test-http-4415-IncomingMessage-es5.ts | 9 +- .../parallel/test-http-4415-Server-es5.ts | 1 + .../test-http-4415-ServerResponse-es6.ts | 2 +- ...tp-9242-IncomingMessage-has-constructor.ts | 2 +- ...ttp-9242-ServerResponse-has-constructor.ts | 2 +- ...test-http-Agent-is-configured-correctly.ts | 4 +- ...lientRequest-field-exposes-agent-getter.ts | 5 +- ...tli-from-Server-and-receive-with-Client.ts | 4 +- ...otli-from-Server-and-receive-with-fetch.ts | 3 +- ...late-from-Server-and-receive-with-fetch.ts | 3 +- ...gzip-from-Server-and-receive-with-fetch.ts | 3 +- ...coding-must-be-valid-after-flushHeaders.ts | 12 +- ...ust-be-valid-after-without-flushHeaders.ts | 12 +- ...coding-must-be-valid-using-minimal-code.ts | 12 +- ...to-send-array-of-[key-value]-as-headers.ts | 4 +- ...coding-if-more-than-one-write-is-called.ts | 4 +- ...tp-client-side-flushHeaders-should-work.ts | 2 +- ...ould-fire-when-receiving-invalid-method.ts | 2 +- .../test-http-destroy-should-end-download.ts | 2 +- ...sts-should-be-Transfer-Encoding-chunked.ts | 3 +- .../parallel/test-http-get-can-use-Agent.ts | 2 +- ...http-host-array-should-throw-in-request.ts | 1 + ...aders-are-sent-when-using-chunk-encoded.ts | 3 +- ...Written-must-be-supported-on-the-server.ts | 2 +- ...st-http-request-has-the-correct-options.ts | 2 +- ...hould-accept-custom-certs-when-provided.ts | 3 +- ...-accept-received-and-send-blank-headers.ts | 2 +- ...-should-allow-Strict-Transport-Security.ts | 3 +- ...-headers-to-be-set-in-server-and-client.ts | 7 +- ...headers-socket._httpMessage-must-be-set.ts | 4 +- ...entError-when-Content-Length-is-invalid.ts | 8 +- ...ng-Content-Length-and-Transfer-Encoding.ts | 8 +- ...d-emit-close-when-connection-is-aborted.ts | 3 +- ...eout-event-when-using-server-setTimeout.ts | 3 +- ...test-http-should-error-with-faulty-args.ts | 7 +- ...-handle-data-if-not-immediately-handled.ts | 3 +- ...test-http-should-handle-header-overflow.ts | 2 +- .../test-http-should-handle-invalid-method.ts | 2 +- ...hould-not-accept-untrusted-certificates.ts | 5 +- ...row-error-when-writing-after-socket.end.ts | 6 +- ...en-rejectNonStandardBodyWrites-is-false.ts | 3 +- ...hen-rejectNonStandardBodyWrites-is-true.ts | 3 +- ...ejectNonStandardBodyWrites-is-undefined.ts | 3 +- .../test-http-should-support-localAddress.ts | 9 +- ...rictContentLength-should-work-on-server.ts | 3 +- ...ould-be-propagated-to-uncaughtException.ts | 6 +- .../test/parallel/test-http-unref-works.ts | 3 +- ...est-https-Agent-is-configured-correctly.ts | 4 +- .../parallel/test-https-get-can-use-Agent.ts | 2 +- ...Written-must-be-supported-on-the-server.ts | 2 +- .../printing/diffexample-color.fixture.ts | 20 +- test/js/bun/test/spyMatchers.test.ts | 13 +- test/js/bun/test/test-failing.test.ts | 1 + test/js/bun/toml/toml.test.ts | 22 +- .../transpiler-unsupported-loader.test.ts | 10 +- .../transpiler-utf16-loader.test.ts | 8 +- test/js/bun/udp/dgram.test.ts | 8 +- .../bun/udp/sendMany-payload-uaf-fixture.ts | 4 +- test/js/bun/udp/udp_socket.test.ts | 5 +- test/js/bun/udp/udp_socket_recv_flags.test.ts | 2 +- test/js/bun/util/arraybuffersink.test.ts | 4 +- test/js/bun/util/bun-cryptohasher.test.ts | 24 +-- test/js/bun/util/escapeRegExp.test.ts | 1 + .../exotic-global-mutable-prototype.test.ts | 5 +- test/js/bun/util/filesink.test.ts | 10 +- test/js/bun/util/fuzzy-wuzzy.test.ts | 70 +++---- test/js/bun/util/heap-snapshot.test.ts | 16 +- test/js/bun/util/highlight-cat.ts | 1 - test/js/bun/util/highway-strings.test.ts | 2 +- test/js/bun/util/index-of-line.test.ts | 14 +- test/js/bun/util/password.test.ts | 8 +- test/js/bun/util/sliceAnsi-fuzz.test.ts | 6 +- test/js/bun/util/stringWidth.test.ts | 12 +- test/js/bun/util/stripANSI.test.ts | 2 +- .../js/bun/util/utf8-conversion-limit.test.ts | 2 +- test/js/bun/util/v8-heap-snapshot-fixture.ts | 4 +- test/js/bun/util/wrapAnsi.test.ts | 4 +- test/js/bun/util/zstd.test.ts | 14 +- ...bsocket-server-backpressure-buffer.test.ts | 14 +- .../websocket-server-forced-close.test.ts | 8 +- .../websocket-server-rsv-frames.test.ts | 2 +- .../websocket-server-unmasked-frames.test.ts | 2 +- ...socket-server-upgrade-early-frames.test.ts | 27 +-- .../js/bun/websocket/websocket-server.test.ts | 85 ++++---- test/js/bun/webview/webview-chrome.test.ts | 10 +- test/js/bun/webview/webview.test.ts | 22 +- test/js/bun/xml/generate_xml_test_suite.ts | 2 +- test/js/bun/xml/xml-test-suite.test.ts | 2 +- test/js/bun/yaml/yaml.test.ts | 127 ++++++------ .../undici/undici-primordials.test.ts | 2 +- test/js/first_party/undici/undici.test.ts | 4 +- test/js/first_party/ws/ws-proxy.test.ts | 39 ++-- test/js/first_party/ws/ws.test.ts | 29 +-- test/js/node/assert/deep-equal.test.ts | 28 +-- .../async_hooks/AsyncLocalStorage.test.ts | 8 +- .../EventEmitterAsyncResource.test.ts | 8 +- .../async-local-storage-thenable.test.ts | 6 +- test/js/node/buffer-concat.test.ts | 2 +- test/js/node/buffer-resolveObjectURL.test.ts | 2 + test/js/node/buffer-utf16.test.ts | 2 +- .../child_process/child-process-exec.test.ts | 24 ++- .../node/child_process/child_process.test.ts | 24 +-- test/js/node/cluster/test-docs-http-server.ts | 4 +- .../node/cluster/test-worker-no-exit-http.ts | 2 +- .../node/crypto/crypto-hmac-algorithm.test.ts | 4 +- test/js/node/crypto/crypto-oneshot.test.ts | 8 +- test/js/node/crypto/crypto.hmac.test.ts | 12 +- .../js/node/crypto/crypto.key-objects.test.ts | 62 ++++-- test/js/node/crypto/ecdh.test.ts | 8 +- test/js/node/crypto/pbkdf2.test.ts | 12 +- .../node/crypto/sign-jwk-ieee-p1363.test.ts | 4 +- test/js/node/crypto/x509-subclass.test.ts | 2 +- .../diagnostics_channel.test.ts | 4 +- test/js/node/dns/dns-resolver-class.test.ts | 2 +- .../dns/dns-tcp-bidirectional-poll-fixture.ts | 4 +- .../node/errors/error-code-messages.test.ts | 2 +- test/js/node/events/event-emitter.test.ts | 14 +- test/js/node/fs/cp.test.ts | 6 +- test/js/node/fs/dir.test.ts | 6 +- ...-promises-writeFile-async-iterator.test.ts | 4 +- .../fs/fs-read-buffer-before-offset.test.ts | 6 +- test/js/node/fs/fs-stats-constructor.test.ts | 2 +- test/js/node/fs/fs-stats-truncate.test.ts | 2 +- test/js/node/fs/fs-write-offset-bound.test.ts | 2 +- test/js/node/fs/fs.test.ts | 123 ++++++------ test/js/node/fs/glob.test.ts | 6 +- test/js/node/fs/rm-windows-ntstatus.test.ts | 4 +- test/js/node/harness.ts | 10 +- .../fixtures/http.compress.leak.server.ts | 6 +- .../node/http/node-fetch-primordials.test.ts | 6 +- .../http/node-http-agent-tls-options.test.mts | 6 +- .../node/http/node-http-backpressure.test.ts | 12 +- test/js/node/http/node-http-connect.node.mts | 2 +- test/js/node/http/node-http-connect.test.ts | 36 ++-- .../node-http-displaced-response-fixture.ts | 2 +- .../http/node-http-incoming-socket.test.ts | 2 +- .../node/http/node-http-maxHeaderSize.test.ts | 6 +- test/js/node/http/node-http-parser.test.ts | 4 +- .../node/http/node-http-pinned-write.test.ts | 8 +- .../node/http/node-http-primoridals.test.ts | 8 +- test/js/node/http/node-http-proxy-url.test.ts | 2 +- .../http/node-http-server-close-drain.test.ts | 2 +- .../node-http-server-socket-end-drain.test.ts | 2 +- .../node/http/node-http-syscall-fault.test.ts | 4 +- .../http/node-http-transfer-encoding.test.ts | 16 +- test/js/node/http/node-http-uaf-fixture-2.ts | 3 +- test/js/node/http/node-http-uaf-fixture.ts | 4 +- test/js/node/http/node-http.test.ts | 186 ++++++++--------- .../node-https-checkServerIdentity.test.ts | 2 +- test/js/node/http2/h2-conformance.test.ts | 24 +-- .../http2/node-http2-client-close.test.ts | 4 +- .../http2/node-http2-continuation.test.ts | 2 +- .../http2/node-http2-invalid-padding.test.ts | 4 +- .../node-http2-settings-ack-ordering.test.ts | 2 +- .../http2/node-http2-syscall-fault.test.ts | 18 +- .../node-http2-writable-destroy-fixture.ts | 2 +- .../node/inspector/inspector-profiler.test.ts | 30 +-- test/js/node/net/net-syscall-fault.test.ts | 26 +-- test/js/node/net/node-net.test.ts | 41 ++-- test/js/node/net/server.spec.ts | 16 +- test/js/node/net/socketaddress.spec.ts | 33 +-- test/js/node/nodettywrap.test.ts | 3 +- test/js/node/perf_hooks/perf_hooks.test.ts | 23 ++- .../process-array-accessor-crash.test.ts | 10 +- test/js/node/process/process-execve.test.ts | 2 +- test/js/node/process/process-stdin.test.ts | 3 +- test/js/node/process/process-stdio.test.ts | 2 +- .../process-stdout-write-after-end.test.ts | 2 +- test/js/node/quic/quic-endpoint.test.ts | 38 ++-- test/js/node/quic/quic-sni.test.ts | 12 +- test/js/node/quic/quic-stream.test.ts | 42 ++-- .../readline/readline_promises.node.test.ts | 6 +- test/js/node/sqlite/node-sqlite.test.ts | 152 ++++++++------ .../stream/node-stream-uint8array.test.ts | 2 +- test/js/node/stream/web-stream-state.test.ts | 5 +- test/js/node/timers/node-timers.test.ts | 8 +- test/js/node/tls/fetch-tls-cert.test.ts | 11 +- test/js/node/tls/node-tls-cert.test.ts | 11 +- test/js/node/tls/node-tls-connect.test.ts | 31 +-- test/js/node/tls/node-tls-context.test.ts | 2 +- .../tls/node-tls-duplex-end-verify.test.ts | 147 +++++++------- test/js/node/tls/node-tls-internals.test.ts | 2 +- test/js/node/tls/node-tls-namedpipes.test.ts | 2 +- test/js/node/tls/node-tls-raw-end.test.ts | 10 +- test/js/node/tls/node-tls-server.test.ts | 28 +-- ...-tls-socket-allow-half-open-option.test.ts | 21 +- test/js/node/tls/renegotiation.test.ts | 4 +- test/js/node/tls/ssl-ctx-cache.test.ts | 8 +- test/js/node/tls/test-system-ca-https.test.ts | 2 +- .../node/tls/tls-connect-socket-churn.test.ts | 14 +- test/js/node/tls/tls-syscall-fault.test.ts | 8 +- test/js/node/url/url.test.ts | 3 +- test/js/node/util/bun-inspect.test.ts | 12 +- .../parse_args/parse-args-null-config.test.ts | 4 +- test/js/node/util/test-aborted.test.ts | 2 +- .../js/node/vm/vm-script-fetcher-leak.test.ts | 4 +- test/js/node/vm/vm.test.ts | 29 +-- test/js/node/watch/fs.watch.test.ts | 7 +- .../worker_threads/worker_threads.test.ts | 22 +- test/js/node/zlib/bytesWritten.test.ts | 3 +- .../js/sql/adapter-env-var-precedence.test.ts | 12 +- test/js/sql/adapter-override.test.ts | 13 +- test/js/sql/postgres-datarow-overrun.test.ts | 2 +- .../postgres-duplicate-auth-request.test.ts | 2 +- ...stgres-finish-request-underflow-fixture.ts | 2 +- test/js/sql/postgres-infinity-date.test.ts | 6 +- test/js/sql/postgres-listen-notify.test.ts | 2 +- test/js/sql/postgres-pgsslmode-env.test.ts | 4 +- ...postgres-prepared-pipeline-reorder.test.ts | 4 +- test/js/sql/postgres-row-decode-error.test.ts | 3 +- .../postgres-split-prepare-reorder-fixture.ts | 2 +- .../sql/sql-close-pending-connection.test.ts | 12 +- .../sql/sql-connect-error-reporting.test.ts | 2 +- test/js/sql/sql-empty-column-name.fixture.ts | 4 +- test/js/sql/sql-fixture-ref.ts | 2 +- .../js/sql/sql-mysql-auth-short-nonce.test.ts | 4 +- .../sql/sql-mysql-columns-realloc-oom.test.ts | 2 +- .../sql-mysql-duplicate-auth-switch.test.ts | 6 +- ...mysql-prepare-ok-zero-statement-id.test.ts | 2 +- .../js/sql/sql-mysql-row-decode-error.test.ts | 5 +- test/js/sql/sql-mysql.auth.test.ts | 6 +- test/js/sql/sql-mysql.helpers.test.ts | 2 +- test/js/sql/sql-mysql.test.ts | 18 +- test/js/sql/sql-mysql.transactions.test.ts | 2 +- test/js/sql/sql-prepare-false.test.ts | 2 +- test/js/sql/sql.test.ts | 43 ++-- test/js/sql/sqlite-sql.test.ts | 8 +- test/js/sql/tls-sql.test.ts | 10 +- test/js/sql/wire-frames.test.ts | 2 +- test/js/sql/wire-frames.ts | 19 +- .../body-parser/express-memory-leak.test.ts | 4 +- .../js/third_party/express/app.router.test.ts | 10 +- .../third_party/express/express.json.test.ts | 6 +- .../third_party/express/express.text.test.ts | 2 +- test/js/third_party/grpc-js/common.ts | 5 +- .../grpc-js/generated/TestService.ts | 2 +- .../grpc-js/generated/test_service.ts | 2 +- .../grpc-js/test-call-credentials.test.ts | 8 +- .../grpc-js/test-certificate-provider.test.ts | 26 +-- .../grpc-js/test-outlier-detection.test.ts | 2 +- .../grpc-js/test-pick-first.test.ts | 3 +- .../js/third_party/grpc-js/test-tonic.test.ts | 2 +- test/js/third_party/postgres/postgres.test.ts | 2 +- test/js/third_party/prisma/prisma.test.ts | 4 +- .../prisma/prisma/postgres/seed.ts | 2 +- test/js/third_party/remix/remix.test.ts | 4 +- .../socket.io/socket.io-middleware.test.ts | 4 +- .../socket.io/socket.io-namespaces.test.ts | 6 +- .../socket.io-server-attachment.test.ts | 2 +- .../socket.io-utility-methods.test.ts | 2 +- .../integration/complex-operations.test.ts | 2 +- .../reliability/connection-failures.test.ts | 24 +-- .../valkey/reliability/error-handling.test.ts | 3 +- .../reliability/protocol-handling.test.ts | 12 +- .../reliability/resp-nesting-depth.test.ts | 2 +- test/js/valkey/test-utils.ts | 2 +- test/js/valkey/unit/buffer-operations.test.ts | 4 +- test/js/valkey/unit/hash-operations.test.ts | 2 +- .../js/valkey/valkey-incremental-scan.test.ts | 2 +- test/js/valkey/valkey-tls-verify.test.ts | 2 +- test/js/valkey/valkey.test.ts | 30 +-- test/js/web/abort/abort.test.ts | 2 +- test/js/web/atomics.test.ts | 2 + .../broadcast-channel.test.ts | 31 +-- test/js/web/crypto/exception-scope-fixture.ts | 1 + test/js/web/crypto/web-crypto.test.ts | 30 ++- .../js/web/encoding/encode-bad-chunks.test.ts | 1 + test/js/web/encoding/text-decoder-cjk.test.ts | 14 +- .../encoding/text-decoder-single-byte.test.ts | 1 + .../web/encoding/text-decoder-stream.test.ts | 14 +- test/js/web/encoding/text-decoder-wpt.test.ts | 16 +- .../web/encoding/text-encoder-stream.test.ts | 1 + test/js/web/fetch/blob-oom.test.ts | 2 +- test/js/web/fetch/blob-write.test.ts | 20 +- test/js/web/fetch/blob.test.ts | 20 +- test/js/web/fetch/body-async-iterator.test.ts | 4 +- test/js/web/fetch/body-clone.test.ts | 20 +- test/js/web/fetch/body-mixin-errors.test.ts | 2 +- test/js/web/fetch/body.test.ts | 43 ++-- test/js/web/fetch/client-fetch.test.ts | 75 +++---- test/js/web/fetch/cookies.test.ts | 9 +- test/js/web/fetch/encoding.test.ts | 5 +- test/js/web/fetch/exiting.test.ts | 7 +- test/js/web/fetch/fetch-args.test.ts | 22 +- test/js/web/fetch/fetch-backpressure.test.ts | 13 +- test/js/web/fetch/fetch-compress.test.ts | 31 ++- test/js/web/fetch/fetch-gzip.test.ts | 6 +- .../web/fetch/fetch-http2-adversarial.test.ts | 4 +- test/js/web/fetch/fetch-http2-client.test.ts | 46 ++--- test/js/web/fetch/fetch-http2-leak-fixture.ts | 10 +- test/js/web/fetch/fetch-http2-leak.test.ts | 2 +- .../web/fetch/fetch-http3-adversarial.test.ts | 2 +- test/js/web/fetch/fetch-http3-client.test.ts | 12 +- .../fetch/fetch-http3-cold-post-fixture.ts | 4 +- .../fetch/fetch-http3-syscall-fault.test.ts | 13 +- test/js/web/fetch/fetch-keepalive.test.ts | 6 +- test/js/web/fetch/fetch-leak.test.ts | 10 +- test/js/web/fetch/fetch-tcp-keepalive.test.ts | 2 +- test/js/web/fetch/fetch-tcp-stress.test.ts | 10 +- .../fetch/fetch-url-after-redirect.test.ts | 11 +- test/js/web/fetch/fetch.stream.test.ts | 54 ++--- test/js/web/fetch/fetch.test.ts | 70 ++++--- .../fetch.tls.cert-mismatch-churn.fixture.ts | 2 +- test/js/web/fetch/fetch.tls.test.ts | 26 +-- test/js/web/fetch/fetch.tls.wildcard.test.ts | 9 +- test/js/web/fetch/fetch.unix.test.ts | 14 +- test/js/web/fetch/headers.test.ts | 11 +- test/js/web/fetch/headers.undici.test.ts | 90 ++++++--- .../fetch/request-cyclic-reference.test.ts | 6 +- .../fetch/response-cyclic-reference.test.ts | 2 +- test/js/web/fetch/response.test.ts | 14 +- test/js/web/fetch/stream-fast-path.test.ts | 8 +- test/js/web/fetch/websocket.helpers.ts | 4 +- .../html/FormData-file-error-leak-fixture.ts | 4 +- .../FormData-multipart-serialization.test.ts | 2 +- test/js/web/html/FormData.test.ts | 24 +-- test/js/web/html/URLSearchParams.test.ts | 17 +- test/js/web/nationalized.test.ts | 2 +- .../js/web/request/request-clone-leak.test.ts | 2 +- test/js/web/request/request-subclass.test.ts | 4 +- test/js/web/streams/compression.test.ts | 11 +- test/js/web/streams/direct-stream-contract.ts | 2 +- .../js/web/structured-clone-blob-file.test.ts | 2 +- test/js/web/structured-clone-fastpath.test.ts | 42 ++-- test/js/web/timers/setImmediate2.test.ts | 2 +- test/js/web/url/url.test.ts | 2 +- test/js/web/urlpattern/urlpattern.test.ts | 2 +- test/js/web/websocket/proxy-test-utils.ts | 4 +- test/js/web/websocket/websocket-blob.test.ts | 14 +- .../js/web/websocket/websocket-client.test.ts | 24 +-- .../websocket/websocket-close-code.test.ts | 2 +- ...cket-permessage-deflate-edge-cases.test.ts | 2 +- .../websocket-pong-fragmented.test.ts | 2 +- ...ebsocket-proxy-close-reentrancy-fixture.ts | 2 +- ...socket-proxy-tunnel-client-leak-fixture.ts | 4 +- ...ocket-proxy-tunnel-upgrade-leak-fixture.ts | 4 +- test/js/web/websocket/websocket-proxy.test.ts | 8 +- .../websocket-server-send-from-drain.test.ts | 2 +- .../websocket/websocket-syscall-fault.test.ts | 2 +- test/js/web/websocket/websocket-unix.test.ts | 2 - .../websocket/websocket-utf16-headers.test.ts | 2 +- test/js/web/workers/message-channel.test.ts | 22 +- test/js/web/workers/message-event.test.ts | 2 +- test/js/web/workers/structured-clone.test.ts | 12 +- .../workers/structuredClone-classes.test.ts | 2 +- .../workers/worker-late-completion.test.ts | 1 + test/js/web/workers/worker.test.ts | 8 +- test/js/workerd/html-rewriter-leak.test.ts | 13 +- test/napi/napi-value-ffi.test.ts | 4 +- test/regression/brotli-reset-leak.test.ts | 4 +- test/regression/issue/012040.test.ts | 3 +- test/regression/issue/014865.test.ts | 1 + test/regression/issue/04298/04298.test.ts | 2 +- test/regression/issue/07001.test.ts | 6 +- test/regression/issue/07500/07500.test.ts | 2 +- test/regression/issue/07736.test.ts | 1 - test/regression/issue/08794.test.ts | 2 +- test/regression/issue/08893.test.ts | 4 +- test/regression/issue/08965/1.ts | 2 +- test/regression/issue/08965/3.ts | 1 + test/regression/issue/09469.test.ts | 2 +- test/regression/issue/09555.test.ts | 20 +- test/regression/issue/09739.test.ts | 2 +- test/regression/issue/11297/11297.fixture.ts | 2 +- test/regression/issue/11677.test.ts | 2 +- test/regression/issue/14515.test.tsx | 3 + test/regression/issue/15314.test.ts | 2 +- test/regression/issue/16476/16476.test.ts | 4 + test/regression/issue/18595.test.ts | 9 +- test/regression/issue/19111.test.ts | 2 +- test/regression/issue/19412.test.ts | 2 +- test/regression/issue/20875.test.ts | 2 +- test/regression/issue/21177.fixture-2.ts | 1 + test/regression/issue/21677.test.ts | 2 +- test/regression/issue/22475.test.ts | 2 +- test/regression/issue/22481.test.ts | 2 +- .../23314/zstd-large-decompression.test.ts | 2 +- .../issue/23314/zstd-large-input.test.ts | 2 +- test/regression/issue/23474.test.ts | 4 +- test/regression/issue/24129.test.ts | 8 +- test/regression/issue/24338.test.ts | 2 +- test/regression/issue/24388.test.ts | 10 +- test/regression/issue/24575.test.ts | 14 +- test/regression/issue/24593.test.ts | 2 +- ...rocess_object_assign_compatibility.test.ts | 2 +- test/regression/issue/25231.test.ts | 4 +- .../issue/25589-frame-size-connect.test.ts | 10 +- test/regression/issue/25589-write-end.test.ts | 6 +- test/regression/issue/25589.test.ts | 10 +- test/regression/issue/25639.test.ts | 12 +- test/regression/issue/25785.test.ts | 4 +- test/regression/issue/25869.test.ts | 4 +- test/regression/issue/26125.test.ts | 2 +- test/regression/issue/26284.test.ts | 4 +- test/regression/issue/26358.test.ts | 4 +- test/regression/issue/26377.test.ts | 2 +- test/regression/issue/26915.test.ts | 2 +- test/regression/issue/28004.test.ts | 2 +- test/regression/issue/28014.test.ts | 2 +- test/regression/issue/28954.test.ts | 2 +- test/regression/issue/29073.test.ts | 2 +- test/regression/issue/29181.test.ts | 4 +- test/regression/issue/29268.test.ts | 2 +- test/regression/issue/29684.test.ts | 8 +- test/regression/issue/29780.test.ts | 2 +- test/regression/issue/34415.test.ts | 4 +- test/regression/issue/ENG-24434.test.ts | 6 +- .../issue/css-system-color-contexts.test.ts | 2 +- .../issue/css-system-color-mix-crash.test.ts | 4 +- test/regression/issue/ctrl-c.test.ts | 2 +- .../regression/issue/fuzzer-ENG-22942.test.ts | 5 +- .../htmlrewriter-additional-bugs.test.ts | 5 + .../issue/isArray-proxy-crash.test.ts | 2 +- .../issue-1825-jest-mock-functions.test.ts | 2 +- .../napi-exception-pending-crash.test.ts | 4 +- ...stringbuilder-assertion-aggressive.test.ts | 2 +- .../issue/prepare-stack-trace-crash.test.ts | 7 + .../issue/s3-signature-performance.test.ts | 2 +- .../issue/yaml-parse-syntax-error.test.ts | 8 +- test/runners/mocha.ts | 1 - test/snippets/reload/other.ts | 2 +- test/tsconfig.json | 26 ++- test/v8/v8.test.ts | 7 +- 670 files changed, 3497 insertions(+), 2920 deletions(-) create mode 100644 test/asset-imports.d.ts create mode 100644 test/internal-for-testing.d.ts diff --git a/packages/bun-error/runtime-error.ts b/packages/bun-error/runtime-error.ts index 87d1ce8d0d7c..038c7b7228ba 100644 --- a/packages/bun-error/runtime-error.ts +++ b/packages/bun-error/runtime-error.ts @@ -40,8 +40,8 @@ const CHROME_IE_STACK_REGEXP = /^\s*at .*(\S+:\d+|\(native\))/m; const SAFARI_NATIVE_CODE_REGEXP = /^(eval@)?(\[native code])?$/; export default class RuntimeError { - original: Error; - stack: StackFrame[]; + original!: Error; + stack!: StackFrame[]; static from(error: Error): RuntimeError { const runtime = new RuntimeError(); @@ -75,7 +75,7 @@ export default class RuntimeError { var regExp = /(.+?)(?::(\d+))?(?::(\d+))?$/; var parts = regExp.exec(urlLike.replace(/[()]/g, "")); - return [parts[1], parts[2] || undefined, parts[3] || undefined]; + return [parts![1], parts![2] || undefined, parts![3] || undefined]; } static parseV8OrIE(error) { diff --git a/packages/bun-release/src/fs.ts b/packages/bun-release/src/fs.ts index d70ccdd84f92..39a852e57dc8 100644 --- a/packages/bun-release/src/fs.ts +++ b/packages/bun-release/src/fs.ts @@ -42,7 +42,7 @@ export function rm(path: string): void { return; } try { - fs.rmdirSync(path, { recursive: true }); + (fs.rmdirSync as typeof fs.rmSync)(path, { recursive: true }); return; } catch (error) { debug("fs.rmdirSync failed", error); @@ -76,7 +76,7 @@ export function rename(path: string, newPath: string): void { export function write(dst: string, content: string | ArrayBuffer | ArrayBufferView): void { debug("write", dst); try { - fs.writeFileSync(dst, content); + fs.writeFileSync(dst, content as string | NodeJS.ArrayBufferView); return; } catch (error) { debug("fs.writeFileSync failed", error); @@ -88,7 +88,7 @@ export function write(dst: string, content: string | ArrayBuffer | ArrayBufferVi debug("fs.mkdirSync failed", error); // The directory could have been created already. } - fs.writeFileSync(dst, content); + fs.writeFileSync(dst, content as string | NodeJS.ArrayBufferView); } } @@ -124,7 +124,7 @@ export function blob(path: string): Blob { }); } -export function hash(content: string | crypto.BinaryLike): string { +export function hash(content: string | NodeJS.ArrayBufferView): string { debug("hash", content); return crypto .createHash("sha256") diff --git a/packages/bun-release/src/platform.ts b/packages/bun-release/src/platform.ts index 03af50376ad7..5f6aa8779e2b 100644 --- a/packages/bun-release/src/platform.ts +++ b/packages/bun-release/src/platform.ts @@ -144,15 +144,15 @@ export const supportedPlatforms: Platform[] = getSupportedPlatforms(os, arch, ab function isLinuxMusl(): boolean { try { if (process.report) { - const excludeNetwork = process.report.excludeNetwork; - process.report.excludeNetwork = true; + const excludeNetwork = (process.report as any).excludeNetwork; + (process.report as any).excludeNetwork = true; try { const report = process.report.getReport() as { header?: { glibcVersionRuntime?: string } }; if (report && report.header) { return !report.header.glibcVersionRuntime; } } finally { - process.report.excludeNetwork = excludeNetwork; + (process.report as any).excludeNetwork = excludeNetwork; } } } catch (error) { diff --git a/packages/bun-types/bun.d.ts b/packages/bun-types/bun.d.ts index 556dd79609cf..e36956306956 100644 --- a/packages/bun-types/bun.d.ts +++ b/packages/bun-types/bun.d.ts @@ -571,9 +571,6 @@ declare module "bun" { cancel?: UnderlyingSourceCancelCallback; pull?: UnderlyingSourcePullCallback; start?: UnderlyingSourceStartCallback; - /** - * Mode "bytes" is not supported. - */ type?: undefined; } @@ -1123,7 +1120,11 @@ declare module "bun" { * // 'name = "app"\n\n[server]\nport = 8080\n' * ``` */ - export function stringify(input: unknown, replacer?: undefined | null, space?: string | number): string | undefined; + export function stringify( + input: T, + replacer?: undefined | null, + space?: string | number, + ): T extends Function | symbol | undefined ? undefined : T extends object ? string : string | undefined; } /** @@ -1496,7 +1497,7 @@ declare module "bun" { * * @category Utilities * - * @param input The YAML string to parse + * @param input The YAML document to parse, as a string or UTF-8 bytes * @returns A JavaScript value, or an array of them for a multi-document stream * * @example @@ -1511,7 +1512,9 @@ declare module "bun" { * console.log(YAML.parse("abc: def")) // { "abc": "def" } * ``` */ - export function parse(input: string): unknown; + export function parse( + input: string | NodeJS.TypedArray | DataView | ArrayBufferLike | Blob, + ): unknown; /** * Convert a JavaScript value into a YAML string. Strings are double quoted if they contain keywords, non-printable or @@ -10061,9 +10064,9 @@ declare module "bun" { resize(width: number, height: number): Promise; /** Navigate back in session history. */ - back(): Promise; + goBack(): Promise; /** Navigate forward in session history. */ - forward(): Promise; + goForward(): Promise; /** Reload the current page. */ reload(): Promise; diff --git a/packages/bun-types/globals.d.ts b/packages/bun-types/globals.d.ts index 1a9ef0cb58ca..8057a61814c0 100644 --- a/packages/bun-types/globals.d.ts +++ b/packages/bun-types/globals.d.ts @@ -150,6 +150,10 @@ declare var ReadableStream: Bun.__internal.UseLibDomIfAvailable< "ReadableStream", { prototype: ReadableStream; + new ( + underlyingSource: import("node:stream/web").UnderlyingByteSource, + strategy?: { highWaterMark?: number }, + ): ReadableStream>; new (underlyingSource?: Bun.UnderlyingSource, strategy?: QueuingStrategy): ReadableStream; new (underlyingSource?: Bun.DirectUnderlyingSource, strategy?: QueuingStrategy): ReadableStream; } @@ -1502,6 +1506,16 @@ interface Blob { */ readonly type: string; + /** + * Returns a new `Blob` with the bytes from `start` up to but not including + * `end`. Negative indices count from the end. + * + * @param start byte offset to start at. Defaults to 0. + * @param end byte offset to stop at. Defaults to `size`. + * @param contentType the `type` of the new `Blob`. + */ + slice(start?: number, end?: number, contentType?: string): Blob; + /** * Read the data from the blob as a JSON object. * @@ -1822,7 +1836,10 @@ declare var ReadableStreamBYOBRequest: Bun.__internal.UseLibDomIfAvailable< interface TextDecoderStream extends Bun.__internal.LibEmptyOrNodeStreamWebTextDecoderStream {} declare var TextDecoderStream: Bun.__internal.UseLibDomIfAvailable< "TextDecoderStream", - { prototype: TextDecoderStream; new (): TextDecoderStream } + { + prototype: TextDecoderStream; + new (encoding?: Bun.Encoding, options?: { fatal?: boolean; ignoreBOM?: boolean }): TextDecoderStream; + } >; interface TextEncoderStream extends Bun.__internal.LibEmptyOrNodeStreamWebTextEncoderStream {} diff --git a/packages/bun-types/test.d.ts b/packages/bun-types/test.d.ts index 2ce1cba4695b..1a6349552cfe 100644 --- a/packages/bun-types/test.d.ts +++ b/packages/bun-types/test.d.ts @@ -243,7 +243,7 @@ declare module "bun:test" { /** * Marks this group of tests as to be written or to be fixed. */ - todo: Describe; + todo: Describe & ((label: DescribeLabel) => void); /** * Marks this group of tests to be executed concurrently. */ @@ -279,8 +279,8 @@ declare module "bun:test" { * @param table Array of Arrays with the arguments that are passed into the test fn for each row. */ each>(table: readonly T[]): Describe<[...T]>; - each(table: readonly T[]): Describe<[...T]>; - each(table: T[]): Describe<[T]>; + each(table: readonly T[]): Describe<[...T]>; + each(table: readonly T[]): Describe<[T]>; } /** * Describes a group of related tests. @@ -477,6 +477,25 @@ declare module "bun:test" { * @category Testing */ export interface Test> { + /** + * Runs a test, with the options before the test function. + * + * @example + * ```ts + * test("can retry", { retry: 3 }, () => { + * expect(Math.random()).toBeLessThan(0.5); + * }); + * ``` + */ + ( + label: string, + options: number | TestOptions, + fn: ( + ...args: __internal.IsTuple extends true + ? [...table: __internal.Flatten, done: (err?: unknown) => void] + : T + ) => void | Promise, + ): void; ( label: string, @@ -510,7 +529,7 @@ declare module "bun:test" { * a `.todo` test that passes is marked as `fail` in the results: remove * the `.todo` or check that the test is implemented correctly. */ - todo: Test; + todo: Test & ((label: string) => void); /** * Marks this test as failing. * @@ -575,8 +594,8 @@ declare module "bun:test" { * @param table Array of Arrays with the arguments that are passed into the test fn for each row. */ each>(table: readonly T[]): Test; - each(table: readonly T[]): Test; - each(table: T[]): Test<[T]>; + each(table: readonly T[]): Test; + each(table: readonly T[]): Test<[T]>; } /** * Runs a test. @@ -633,7 +652,7 @@ declare module "bun:test" { * @param customFailMessage an optional custom message to display if the test fails. * */ - (actual?: never, customFailMessage?: string): Matchers; + (): Matchers; (actual: T, customFailMessage?: string): Matchers; (actual?: T, customFailMessage?: string): Matchers; diff --git a/scripts/build/jsonByteClass.ts b/scripts/build/jsonByteClass.ts index c19e2dc5d540..17a28b634eaa 100644 --- a/scripts/build/jsonByteClass.ts +++ b/scripts/build/jsonByteClass.ts @@ -83,7 +83,7 @@ export function generateJsonByteClass(cfg: Pick): { h: str const table: string[] = []; for (let row = 0; row < 256; row += 16) { - const cells = []; + const cells: string[] = []; for (let b = row; b < row + 16; b++) cells.push(hex(classOf(b))); table.push(` ${cells.join(", ")},`); } diff --git a/scripts/build/xmlByteClass.ts b/scripts/build/xmlByteClass.ts index 7098243efffa..95ec4a77cd80 100644 --- a/scripts/build/xmlByteClass.ts +++ b/scripts/build/xmlByteClass.ts @@ -78,7 +78,7 @@ export function generateXmlByteClass(cfg: Pick): { h: stri const table: string[] = []; for (let row = 0; row < 256; row += 16) { - const cells = []; + const cells: string[] = []; for (let b = row; b < row + 16; b++) cells.push(hex(classOf(b))); table.push(` ${cells.join(", ")},`); } diff --git a/test/asset-imports.d.ts b/test/asset-imports.d.ts new file mode 100644 index 000000000000..2a4abb603806 --- /dev/null +++ b/test/asset-imports.d.ts @@ -0,0 +1,26 @@ +// Files that tests import for their path (the "file" loader) or their text (`with { type: "text" }`). +// TypeScript 7.1 can declare these by import attribute instead of by extension, see packages/bun-types/ts7.1. +declare module "*.c" { + var contents: string; + export = contents; +} +declare module "*.cc" { + var contents: string; + export = contents; +} +declare module "*.h" { + var contents: string; + export = contents; +} +declare module "*.pem" { + var contents: string; + export = contents; +} +declare module "*.br" { + var contents: string; + export = contents; +} +declare module "*.gzip" { + var contents: string; + export = contents; +} diff --git a/test/bake/bake-harness.ts b/test/bake/bake-harness.ts index df3335261457..c5ba2f53efaf 100644 --- a/test/bake/bake-harness.ts +++ b/test/bake/bake-harness.ts @@ -1,4 +1,4 @@ -/// +/// /* Dev server tests can be run with `bun test` or in interactive mode with `bun run test.ts "name filter"` * * Env vars: @@ -1731,7 +1731,6 @@ async function writeAll(root: string, files: FileObject) { fs.mkdirSync(path.dirname(filename), { recursive: true }); const formattedContents = typeof contents === "string" ? dedent(contents).replaceAll("{{root}}", root.replaceAll("\\", "\\\\")) : contents; - // @ts-expect-error the type of Bun.write is too strict promises.push(Bun.write(filename, formattedContents)); } await Promise.all(promises); diff --git a/test/bake/dev/import-meta-inline.test.ts b/test/bake/dev/import-meta-inline.test.ts index 904776a2ecb0..9bb985a04bd4 100644 --- a/test/bake/dev/import-meta-inline.test.ts +++ b/test/bake/dev/import-meta-inline.test.ts @@ -26,7 +26,7 @@ export default function (req, meta) { }, async test(dev) { const response = await dev.fetch("/"); - const json = await response.json(); + const json: any = await response.json(); // Check that all properties are strings, not undefined expect(typeof json.dir).toBe("string"); @@ -108,7 +108,7 @@ export default function (req, meta) { }, async test(dev) { const response = await dev.fetch("/api/v1/handler"); - const json = await response.json(); + const json: any = await response.json(); expect(json.file).toBe("handler.ts"); expect(json.path).toContain(platformPath("routes/api/v1/handler.ts")); @@ -182,7 +182,7 @@ export default function BlogPost(req, meta) { async test(dev) { // Test single segment const post1 = await dev.fetch("/blog/hello"); - const json1 = await post1.json(); + const json1: any = await post1.json(); expect(json1.slug).toEqual(["hello"]); expect(json1.title).toBe("Hello"); @@ -198,7 +198,7 @@ export default function BlogPost(req, meta) { // Test multiple segments const post2 = await dev.fetch("/blog/2024/tech/bun-framework"); - const json2 = await post2.json(); + const json2: any = await post2.json(); expect(json2.slug).toEqual(["2024", "tech", "bun-framework"]); expect(json2.title).toBe("2024 Tech Bun-framework"); @@ -210,7 +210,7 @@ export default function BlogPost(req, meta) { // Test empty slug (just /blog/) const post3 = await dev.fetch("/blog/"); - const json3 = await post3.json(); + const json3: any = await post3.json(); expect(json3.slug).toEqual([]); expect(json3.title).toBe(""); @@ -261,7 +261,7 @@ export default function GettingStarted(req, meta) { async test(dev) { // Test static route - should match api.ts, not catch-all const apiResponse = await dev.fetch("/docs/api"); - const apiJson = await apiResponse.json(); + const apiJson: any = await apiResponse.json(); expect(apiJson.type).toBe("static"); expect(apiJson.page).toBe("API Documentation"); @@ -271,7 +271,7 @@ export default function GettingStarted(req, meta) { // Test another static route const startResponse = await dev.fetch("/docs/getting-started"); - const startJson = await startResponse.json(); + const startJson: any = await startResponse.json(); expect(startJson.type).toBe("static"); expect(startJson.page).toBe("Getting Started"); @@ -281,7 +281,7 @@ export default function GettingStarted(req, meta) { // Test catch-all route - should match for non-static paths const guideResponse = await dev.fetch("/docs/guides/advanced/optimization"); expect(guideResponse.status).toBe(200); - const guideJson = await guideResponse.json(); + const guideJson: any = await guideResponse.json(); expect(guideJson.type).toBe("catch-all"); expect(guideJson.path).toEqual(["guides", "advanced", "optimization"]); @@ -296,7 +296,7 @@ export default function GettingStarted(req, meta) { }); const updatedResponse = await dev.fetch("/docs/tutorials/intro"); - const updatedJson = await updatedResponse.json(); + const updatedJson: any = await updatedResponse.json(); expect(updatedJson.type).toBe("dynamic-catch-all"); expect(updatedJson.file).toBe("[...path].ts"); diff --git a/test/bake/fixtures/svelte-component-islands/framework/client.ts b/test/bake/fixtures/svelte-component-islands/framework/client.ts index aca37275e03b..1ead9d0d6686 100644 --- a/test/bake/fixtures/svelte-component-islands/framework/client.ts +++ b/test/bake/fixtures/svelte-component-islands/framework/client.ts @@ -2,6 +2,7 @@ import type { IslandMap } from "./server"; import { hydrate } from 'svelte'; declare var $islands: IslandMap; +declare var document: any; Object.entries($islands).forEach(async([moduleId, islands]) => { const mod = await import(moduleId); for(const [islandId, exportId, props] of islands) { diff --git a/test/bake/fixtures/svelte-component-islands/framework/server.ts b/test/bake/fixtures/svelte-component-islands/framework/server.ts index 29253245f83d..d9e4dd4629f9 100644 --- a/test/bake/fixtures/svelte-component-islands/framework/server.ts +++ b/test/bake/fixtures/svelte-component-islands/framework/server.ts @@ -1,4 +1,4 @@ -/// +/// import type { Bake } from "bun"; import * as svelte from "svelte/server"; import { uneval } from "devalue"; diff --git a/test/bundler/bun-build-compile.test.ts b/test/bundler/bun-build-compile.test.ts index 22ac8769c986..5239e2bfba8c 100644 --- a/test/bundler/bun-build-compile.test.ts +++ b/test/bundler/bun-build-compile.test.ts @@ -204,7 +204,7 @@ console.log(JSON.stringify({ n, anonKB: anon }));`, // `Offsets.flags` in the trailer of the embedded module graph; bit 13 = all bytecode is one linked payload. function hasLinkedPayload(outfile: string) { const file = readFileSync(isAbsolute(outfile) ? outfile : join(cwd(), outfile)); - const trailer = file.lastIndexOf("\n---- Bun! ----\n", undefined, "latin1"); + const trailer = file.lastIndexOf("\n---- Bun! ----\n", undefined as any, "latin1"); return (file.readUInt32LE(trailer - 4) & (1 << 13)) !== 0; } // The ordered build's counterpart of compile/splitting/StartupModulesPrecedeLazyChunks (bundler_compile_splitting): @@ -213,7 +213,7 @@ console.log(JSON.stringify({ n, anonKB: anon }));`, // knew and did not evaluate, all other bodies, expression info). function linkedLayout(outfile: string) { const file = readFileSync(isAbsolute(outfile) ? outfile : join(cwd(), outfile)); - const trailer = file.lastIndexOf("\n---- Bun! ----\n", undefined, "latin1"); + const trailer = file.lastIndexOf("\n---- Bun! ----\n", undefined as any, "latin1"); // `Offsets { byte_count: usize, modules_ptr: StringPointer, entry_point_id: u32, compile_exec_argv_ptr: StringPointer, flags: u32 }` const offsets = trailer - 32; const base = offsets - Number(file.readBigUInt64LE(offsets)); @@ -830,7 +830,7 @@ console.log(JSON.stringify({ n, anonKB: anon }));`, // The first bytes of lazy.js's bytecode say which version of the cache wrote it. const outfile = join(String(dir), exe("plain")); const file = readFileSync(outfile); - const trailer = file.lastIndexOf("\n---- Bun! ----\n", undefined, "latin1"); + const trailer = file.lastIndexOf("\n---- Bun! ----\n", undefined as any, "latin1"); const offsets = trailer - 32; const base = offsets - Number(file.readBigUInt64LE(offsets)); const modules = { offset: file.readUInt32LE(offsets + 8), length: file.readUInt32LE(offsets + 12) }; @@ -1297,7 +1297,7 @@ console.log(JSON.stringify({ n, anonKB: anon }));`, }), ).toThrow('The "compile.bytecodeOrder" property must be of type string or array of strings. Received number'); // `false`, `null` and `[]` are no order file (`haveProfile && path`): the options after it are looked at. - for (const bytecodeOrder of [false, null, [] as string[]]) { + for (const bytecodeOrder of [false, null, [] as string[]] as const) { expect(() => Bun.build({ entrypoints: [join(cwd(), "app.js")], @@ -2010,7 +2010,7 @@ export function inOther() { // The positions, counted in the text the executable holds. A frame is where the call's arguments start. const file = readFileSync(outfile); - const trailer = file.lastIndexOf("\n---- Bun! ----\n", undefined, "latin1"); + const trailer = file.lastIndexOf("\n---- Bun! ----\n", undefined as any, "latin1"); const offsets = trailer - 32; const base = offsets - Number(file.readBigUInt64LE(offsets)); const record = base + file.readUInt32LE(offsets + 8); @@ -2043,6 +2043,7 @@ export function inOther() { Bun.build({ entrypoints: [join(dir, "index.js")], compile: { + // @ts-expect-error target: "bun-invalid-platform", outfile: join(dir, "invalid-app"), }, diff --git a/test/bundler/bundler_bytecode_portable.test.ts b/test/bundler/bundler_bytecode_portable.test.ts index 7c8f07040d02..9ee55aec72a4 100644 --- a/test/bundler/bundler_bytecode_portable.test.ts +++ b/test/bundler/bundler_bytecode_portable.test.ts @@ -404,7 +404,7 @@ describe("bytecode cache portability", () => { outputs["builtin corpus"] = fingerprint(builtin.bytecode); outputs["builtin corpus strings"] = fingerprint(builtin.strings, false); // the external string table --compile embeds beside it outputs["vm.SourceTextModule module.js"] = fingerprint( - new vm.SourceTextModule(moduleSource, { identifier: "module.js" }).createCachedData(), + (new vm.SourceTextModule(moduleSource, { identifier: "module.js" }) as any).createCachedData(), ); outputs["vm.Script big.js"] = fingerprint( new vm.Script(bigSource(), { filename: "big.js", produceCachedData: true }).cachedData!, @@ -423,7 +423,9 @@ describe("bytecode cache portability", () => { }).cachedData!, ); outputs["vm.SourceTextModule acorn.mjs"] = fingerprint( - new vm.SourceTextModule(librarySource("acorn/dist/acorn.mjs"), { identifier: "acorn.mjs" }).createCachedData(), + ( + new vm.SourceTextModule(librarySource("acorn/dist/acorn.mjs"), { identifier: "acorn.mjs" }) as any + ).createCachedData(), ); for (const [i, { name }] of bundlerBuilds.entries()) { const { js, jsc } = (await bundled)[i]; diff --git a/test/bundler/bundler_comments.test.ts b/test/bundler/bundler_comments.test.ts index a08d5f273baa..159f677f97ef 100644 --- a/test/bundler/bundler_comments.test.ts +++ b/test/bundler/bundler_comments.test.ts @@ -1,5 +1,5 @@ import { describe, expect } from "bun:test"; -import { SourceMap } from "node:module"; +import { SourceMap, type SourceMapping } from "node:module"; import { itBundled } from "./expectBundled"; describe("single-line comments", () => { @@ -426,7 +426,7 @@ describe("multi-line comments", () => { expect(commentLineIndex).toBeGreaterThanOrEqual(0); // The multi-line legal comment should have a sourcemap entry - const entry = sm.findEntry(commentLineIndex, 0); + const entry = sm.findEntry(commentLineIndex, 0) as SourceMapping; // Verify we found a mapping for the comment expect(entry).toBeTruthy(); diff --git a/test/bundler/bundler_compile_splitting.test.ts b/test/bundler/bundler_compile_splitting.test.ts index 2bb2125da041..eb76a01ed0ce 100644 --- a/test/bundler/bundler_compile_splitting.test.ts +++ b/test/bundler/bundler_compile_splitting.test.ts @@ -267,7 +267,7 @@ describe("bundler", () => { }, onAfterBundle(api) { const file = readFileSync(api.outfile); - const trailer = file.lastIndexOf("\n---- Bun! ----\n", undefined, "latin1"); + const trailer = file.lastIndexOf("\n---- Bun! ----\n", undefined as any, "latin1"); expect(trailer).toBeGreaterThan(0); // `Offsets { byte_count: usize, modules_ptr: StringPointer, entry_point_id: u32, compile_exec_argv_ptr: StringPointer, flags: u32 }` const offsets = trailer - 32; @@ -337,7 +337,7 @@ describe("bundler", () => { }, onAfterBundle(api) { const file = readFileSync(api.outfile); - const trailer = file.lastIndexOf("\n---- Bun! ----\n", undefined, "latin1"); + const trailer = file.lastIndexOf("\n---- Bun! ----\n", undefined as any, "latin1"); expect(trailer).toBeGreaterThan(0); const offsets = trailer - 32; const base = offsets - Number(file.readBigUInt64LE(offsets)); diff --git a/test/bundler/bundler_minify.test.ts b/test/bundler/bundler_minify.test.ts index 184f4cae3bed..5a335ed1060c 100644 --- a/test/bundler/bundler_minify.test.ts +++ b/test/bundler/bundler_minify.test.ts @@ -2033,7 +2033,7 @@ test.each(["transformSync", "transform"] as const)( "minify.identifiers: %s gives no import or parameter the name of an export", async method => { const exportNames = [..."abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_$"]; - const output = await new Bun.Transpiler({ loader: "js", minify: { identifiers: true } })[method]( + const output = await new Bun.Transpiler({ loader: "js", minify: { identifiers: true } } as any)[method]( [ `import { imported } from "./imported.js";`, ...exportNames.map(name => `export const ${name} = "${name}";`), @@ -2055,7 +2055,7 @@ test.each(["transformSync", "transform"] as const)( test.each(["transformSync", "transform"] as const)( "minify.identifiers: %s keeps the name of an export that is declared again", async method => { - const output = await new Bun.Transpiler({ loader: "js", minify: { identifiers: true } })[method]( + const output = await new Bun.Transpiler({ loader: "js", minify: { identifiers: true } } as any)[method]( "export var t = 1;\nvar t = 2;\nexport function read() { return t; }\n", ); expect(output).toBe("export var t = 1;\nvar t = 2;\nexport function read() {\n return t;\n}\n"); diff --git a/test/bundler/bundler_plugin.test.ts b/test/bundler/bundler_plugin.test.ts index e9312694e2b2..7535d6d374c1 100644 --- a/test/bundler/bundler_plugin.test.ts +++ b/test/bundler/bundler_plugin.test.ts @@ -933,7 +933,7 @@ describe("bundler", () => { }, entryPoints: ["./index.ts"], plugins(build) { - expect(build.config).toBe(getConfigRef()); + expect(build.config).toBe(getConfigRef() as typeof build.config); }, }; }); diff --git a/test/bundler/bundler_plugin_chain.test.ts b/test/bundler/bundler_plugin_chain.test.ts index dbf25e98c5cc..c4e908d77c57 100644 --- a/test/bundler/bundler_plugin_chain.test.ts +++ b/test/bundler/bundler_plugin_chain.test.ts @@ -45,7 +45,7 @@ describe("bundler", () => { builder.onResolve({ filter: /\.magic$/ }, args => { callOrder.push("plugin3-resolve"); // Return empty object - should continue to next plugin - return {}; + return {} as Bun.OnResolveResult; }); }, }, @@ -165,7 +165,7 @@ describe("bundler", () => { expect(args.kind).toBe("entry-point-build"); callOrder.push("plugin2-entry"); // Return empty object - continue to next - return {}; + return {} as Bun.OnResolveResult; }); }, }, diff --git a/test/bundler/bundler_splitting.test.ts b/test/bundler/bundler_splitting.test.ts index cf5ad324f2de..558fc358ac30 100644 --- a/test/bundler/bundler_splitting.test.ts +++ b/test/bundler/bundler_splitting.test.ts @@ -2,8 +2,8 @@ import { describe, expect, test } from "bun:test"; import { bunEnv, bunExe, isASAN, isDebug, tempDir } from "harness"; import { readdirSync, readFileSync } from "node:fs"; import { join } from "node:path"; -import { SourceMapConsumer } from "source-map"; -import { itBundled, type BundlerTestBundleAPI } from "./expectBundled"; +import { SourceMapConsumer, type RawSourceMap } from "source-map"; +import { itBundled, type BundlerTestBundleAPI, type BundlerTestInput } from "./expectBundled"; import { checkGraph, run } from "./splitting-fuzz"; const env = { @@ -26,7 +26,7 @@ describe("bundler", () => { splitting: true, outdir: "/out", target: "browser", - env: "inline", + env: "inline" as any, format: "esm", run: { file: "/out/client.js", @@ -56,7 +56,7 @@ describe("bundler", () => { splitting: true, outdir: "/out", target: "browser", - env: "inline", + env: "inline" as any, format: "esm", run: { file: "/out/entry.js", @@ -82,7 +82,7 @@ describe("bundler", () => { splitting: true, outdir: "/out", target: "browser", - env: "inline", + env: "inline" as any, format: "esm", run: { file: "/out/entry.js", @@ -112,7 +112,7 @@ describe("bundler", () => { splitting: true, outdir: "/out", target: "browser", - env: "inline", + env: "inline" as any, format: "esm", run: { file: "/out/entry.js", @@ -147,7 +147,7 @@ describe("bundler", () => { splitting: true, outdir: "/out", target: "browser", - env: "inline", + env: "inline" as any, format: "esm", run: { file: "/out/entry.js", @@ -193,7 +193,7 @@ describe("bundler", () => { splitting: true, outdir: "/out", target: "browser", - env: "inline", + env: "inline" as any, format: "esm", run: { file: "/out/entry.js", @@ -227,7 +227,7 @@ describe("bundler", () => { splitting: true, outdir: "/out", target: "browser", - env: "inline", + env: "inline" as any, format: "esm", run: { file: "/out/entry.js", @@ -256,7 +256,7 @@ describe("bundler", () => { splitting: true, outdir: "/out", target: "browser", - env: "inline", + env: "inline" as any, format: "esm", run: [ { @@ -283,7 +283,7 @@ describe("bundler", () => { splitting: true, outdir: "/out", target: "browser", - env: "inline", + env: "inline" as any, format: "esm", run: { file: "/out/entry.js", @@ -321,7 +321,7 @@ describe("bundler", () => { splitting: true, outdir: "/out", target: "browser", - env: "inline", + env: "inline" as any, format: "esm", run: { file: "/out/entry.js", @@ -520,8 +520,7 @@ describe("bundler", () => { pinned, folded, ...options - }: Omit[1], "onAfterBundle"> & - Record<"pinned" | "folded", (api: BundlerTestBundleAPI) => void>, + }: Omit & Record<"pinned" | "folded", (api: BundlerTestBundleAPI) => void>, ) { const entry = options.entryPoints![0].replace(/^\/|\.[jt]s$/g, ""); itBundled(id, { @@ -3992,7 +3991,7 @@ describe("bundler", () => { console.log(result.outputs.length); `, }); - const { BUN_FEATURE_FLAG_INTERNAL_FOR_TESTING: _, ...withoutInternals } = env; + const { BUN_FEATURE_FLAG_INTERNAL_FOR_TESTING: _, ...withoutInternals } = env as NodeJS.Dict; const chunks = async (...flags: string[]) => { const { stdout, ...rest } = await run([bunExe(), ...flags, "build.js"], String(dir), withoutInternals); return { stdout: stdout.trim(), ...rest }; @@ -4720,7 +4719,7 @@ describe("bundler", () => { // `util("admin")` follows the dynamic import on the same line, so the map // only points at it if the mappings were shifted by the difference between // the placeholder and the path written over it. - async function expectUtilCallToBeMapped(code: string, map: object) { + async function expectUtilCallToBeMapped(code: string, map: RawSourceMap) { const generatedLines = code.split("\n"); const line = generatedLines.findIndex(l => l.includes('util("admin")')) + 1; expect(line).toBeGreaterThan(0); diff --git a/test/bundler/cli.test.ts b/test/bundler/cli.test.ts index b0861c95ca98..416499daccd6 100644 --- a/test/bundler/cli.test.ts +++ b/test/bundler/cli.test.ts @@ -3,7 +3,7 @@ import { bunEnv, bunExe, isWindows, normalizeBunSnapshot, tempDir, tmpdirSync } import fs, { mkdirSync, realpathSync, rmSync, writeFileSync } from "node:fs"; import path, { join } from "node:path"; -describe.concurrent( +(describe.concurrent as any)( "bun build", () => { test("warnings dont return exit code 1", async () => { diff --git a/test/bundler/esbuild/css.test.ts b/test/bundler/esbuild/css.test.ts index e450a5fcd60f..5e6a6f91ca01 100644 --- a/test/bundler/esbuild/css.test.ts +++ b/test/bundler/esbuild/css.test.ts @@ -542,7 +542,8 @@ describe("bundler", () => { }); // Define all the invalid cases - const invalidComposesTests = [ + type InvalidComposesTest = { name: string; cssContent: string; expectedError?: string; expectedWarning?: string }; + const invalidComposesTests: InvalidComposesTest[] = [ { name: "IDSelector", cssContent: ` diff --git a/test/bundler/esbuild/default.test.ts b/test/bundler/esbuild/default.test.ts index 8a2dc3fdb8ec..52ec6a5d04df 100644 --- a/test/bundler/esbuild/default.test.ts +++ b/test/bundler/esbuild/default.test.ts @@ -2,7 +2,7 @@ import assert from "assert"; import { describe, expect, test } from "bun:test"; import { bunEnv, bunExe, osSlashes, tempDir } from "harness"; import path from "path"; -import { dedent, ESBUILD_PATH, itBundled } from "../expectBundled"; +import { type BundlerTestInput, dedent, ESBUILD_PATH, itBundled } from "../expectBundled"; // Tests ported from: // https://github.com/evanw/esbuild/blob/main/internal/bundler_tests/bundler_default_test.go @@ -2185,7 +2185,7 @@ describe.concurrent("bundler", () => { jsx: { factory: "h", automaticRuntime: false, - }, + } as BundlerTestInput["jsx"], external: ["preact"], run: true, }); diff --git a/test/bundler/esbuild/tsconfig.test.ts b/test/bundler/esbuild/tsconfig.test.ts index adec00bd3313..c41c85385fe8 100644 --- a/test/bundler/esbuild/tsconfig.test.ts +++ b/test/bundler/esbuild/tsconfig.test.ts @@ -1107,6 +1107,7 @@ describe("bundler", () => { }, }); test.skip("tsconfig/JsonExtendsAbsolute", () => { + // @ts-expect-error not imported expectBundled("tsconfig/JsonExtendsAbsoluteUnix", { // GENERATED host: "unix", @@ -1130,6 +1131,7 @@ describe("bundler", () => { `, }, }); + // @ts-expect-error not imported expectBundled("tsconfig/JsonExtendsAbsoluteWindows", { // GENERATED host: "windows", diff --git a/test/bundler/expectBundled.ts b/test/bundler/expectBundled.ts index ddb720563604..ed8d4411434b 100644 --- a/test/bundler/expectBundled.ts +++ b/test/bundler/expectBundled.ts @@ -83,7 +83,7 @@ function errorOrWarnParser(isError = true) { const prefix = isError ? "error: " : "warn: "; return function (text: string) { var i = 0; - var list = []; + var list: [message: string, fileLine: string][] = []; while (i < text.length) { let errorLineI = text.indexOf(prefix, i); if (errorLineI === -1) { @@ -149,7 +149,7 @@ const originalCwd = process.cwd(); function resolveBackend(opts: BundlerTestInput): "cli" | "api" { if (opts.backend) return opts.backend; const run = opts.run === true ? {} : opts.run; - const hasValidate = !Array.isArray(run) && run?.validate; + const hasValidate = !Array.isArray(run) && (run as BundlerTestRunOptions | undefined)?.validate; return opts.dotenv || typeof opts.production !== "undefined" || opts.bundling === false || @@ -247,7 +247,8 @@ export interface BundlerTestInput { publicPath?: string; keepNames?: boolean; legalComments?: "none" | "inline" | "eof" | "linked" | "external"; - loader?: Record<`.${string}`, Loader>; + /** Loaders that only esbuild has make the test a todo. "wtf" is for `edgecase/InvalidLoaderSegfault`. */ + loader?: Record<`.${string}`, Loader | esbuild.Loader | "wtf">; mangleProps?: RegExp; mangleQuoted?: boolean; mainFields?: string[]; @@ -273,7 +274,8 @@ export interface BundlerTestInput { reactCompilerOutputMode?: "client" | "ssr"; treeShaking?: boolean; unsupportedCSSFeatures?: string[]; - unsupportedJSFeatures?: string[]; + /** The tests generated from esbuild's suite pass a target name ("es2018") instead of a list of features. */ + unsupportedJSFeatures?: string[] | string; /** if set to true or false, create or edit tsconfig.json to set compilerOptions.useDefineForClassFields */ useDefineForClassFields?: boolean; sourceMap?: "inline" | "external" | "linked" | "none"; @@ -293,7 +295,7 @@ export interface BundlerTestInput { * * Pass an object mapping filenames to an array of error strings that file should contain. */ - bundleErrors?: true | Record; + bundleErrors?: true | Record; /** * Same as bundleErrors except for warnings. Bundle should still succeed. */ @@ -482,7 +484,7 @@ function expectBundled( ); } - var { expect, it, test } = testForFile(currentFile ?? callerSourceOrigin()); + var { expect, it, test } = testForFile(currentFile ?? callerSourceOrigin()!); if (!ignoreFilter && FILTER && !filterMatches(id)) return testRef(id, opts); let { @@ -1119,7 +1121,7 @@ function expectBundled( if (expectedErrors) { const errorsLeft = [...expectedErrors]; - let unexpectedErrors = []; + let unexpectedErrors: ErrorMeta[] = []; for (const error of allErrors) { const i = errorsLeft.findIndex(item => error.file === item.file && error.error.includes(item.error)); @@ -1167,7 +1169,7 @@ function expectBundled( const file = fullFilename.slice(id.length + path.basename(tempDirectory).length + 1).replaceAll("\\", "/"); return { error, file, line, col }; }) - .filter(Boolean); + .filter(Boolean) as ErrorMeta[]; const expectedWarnings = bundleWarnings ? Object.entries(bundleWarnings).flatMap(([file, v]) => v.map(error => ({ file, error }))) : null; @@ -1193,7 +1195,7 @@ function expectBundled( throw new Error("Warnings were thrown while bundling:\n" + allWarnings.map(formatError).join("\n")); } else if (expectedWarnings) { const warningsLeft = [...expectedWarnings]; - let unexpectedWarnings = []; + let unexpectedWarnings: ErrorMeta[] = []; for (const error of allWarnings) { const i = warningsLeft.findIndex(item => error.file === item.file && error.error.includes(item.error)); @@ -1230,7 +1232,7 @@ function expectBundled( }; } else if (typeof compile === "string") { compile = { - target: compile, + target: compile as Bun.Build.CompileTarget, outfile: outfile, }; } else if (typeof compile === "object") { @@ -1422,7 +1424,7 @@ for (const [key, blob] of build.outputs) { if (expectedErrors) { const errorsLeft = [...expectedErrors]; - let unexpectedErrors = []; + let unexpectedErrors: ErrorMeta[] = []; for (const error of allErrors) { const i = errorsLeft.findIndex(item => error.file === item.file && error.error.includes(item.error)); @@ -1491,7 +1493,7 @@ for (const [key, blob] of build.outputs) { const fileContents = readFile(file); let i = 0; const length = fileContents.length; - const matches = []; + const matches: string[] = []; while (i < length) { i = fileContents.indexOf(fnName, i); if (i === -1) { @@ -1864,7 +1866,7 @@ for (const [key, blob] of build.outputs) { if (run.errorLineMatch) { // in order to properly analyze the error, we have to look backwards on stderr. this approach // most definitely can be improved but it works fine here. - const stack = []; + const stack: string[] = []; let error; const lines = stderr! .toUnixString() @@ -1915,7 +1917,7 @@ for (const [key, blob] of build.outputs) { for (let [name, expected, out] of [ ["stdout", run.stdout, stdout], ["stderr", run.stderr, stderr], - ].filter(([, v]) => v !== undefined)) { + ].filter(([, v]) => v !== undefined) as [name: string, expected: string | RegExp, out: Buffer][]) { let result = out!.toUnixString().trim(); // no idea why this logs. ¯\_(ツ)_/¯ @@ -1977,7 +1979,7 @@ export function itBundled( opts._referenceFn = fn; } const ref = testRef(id, opts); - const { it } = testForFile(currentFile ?? callerSourceOrigin()) as any; + const { it } = testForFile(currentFile ?? callerSourceOrigin()!) as any; if (FILTER && !filterMatches(id)) { return ref; @@ -2010,11 +2012,11 @@ export function itBundled( } itBundled.only = (id: string, opts: BundlerTestInput) => { - const { it } = testForFile(currentFile ?? callerSourceOrigin()); + const { it } = testForFile(currentFile ?? callerSourceOrigin()!); it.only( id, - () => expectBundled(id, opts as any), + () => expectBundled(id, opts as any) as Promise, // sourcemap code is slow isCI ? undefined : isDebug ? Infinity : (opts.snapshotSourceMap ? 30_000 : 5_000) * (opts.timeoutScale ?? 1), ); @@ -2024,8 +2026,8 @@ itBundled.skip = (id: string, opts: BundlerTestInput) => { if (FILTER && !filterMatches(id)) { return testRef(id, opts); } - const { it } = testForFile(currentFile ?? callerSourceOrigin()); - if (!HIDE_SKIP) it.skip(id, () => expectBundled(id, opts)); + const { it } = testForFile(currentFile ?? callerSourceOrigin()!); + if (!HIDE_SKIP) it.skip(id, () => expectBundled(id, opts) as Promise); return testRef(id, opts); }; diff --git a/test/bundler/html-import-manifest.test.ts b/test/bundler/html-import-manifest.test.ts index 11b5454c9bf3..2698ff6936ef 100644 --- a/test/bundler/html-import-manifest.test.ts +++ b/test/bundler/html-import-manifest.test.ts @@ -292,7 +292,7 @@ console.log("About manifest:", aboutHtml); // The manifests are embedded as escaped JSON strings in __jsonParse calls const manifestMatches = [...serverCode.matchAll(/__jsonParse\("(.+?)"\)/gs)]; expect(manifestMatches.length).toBe(2); - let manifests = []; + let manifests: any[] = []; for (const match of manifestMatches) { // The captured group contains the escaped JSON string const escapedJson = match[1]; diff --git a/test/bundler/metafile.test.ts b/test/bundler/metafile.test.ts index e77b76b521d1..8953f2ac6bb9 100644 --- a/test/bundler/metafile.test.ts +++ b/test/bundler/metafile.test.ts @@ -686,7 +686,7 @@ describe("Bun.build metafile option variants", () => { const result = await Bun.build({ entrypoints: [`${dir}/entry.js`], outdir: `${dir}/dist`, - metafile: "output-meta.json", + metafile: "output-meta.json" as any, }); expect(result.success).toBe(true); @@ -717,7 +717,7 @@ describe("Bun.build metafile option variants", () => { const result = await Bun.build({ entrypoints: [`${dir}/main.js`], outdir: `${dir}/dist`, - metafile: { json: "custom-meta.json" }, + metafile: { json: "custom-meta.json" } as any, }); expect(result.success).toBe(true); @@ -741,7 +741,7 @@ describe("Bun.build metafile option variants", () => { const result = await Bun.build({ entrypoints: [`${dir}/app.js`], outdir: `${dir}/dist`, - metafile: { markdown: "analysis.md" }, + metafile: { markdown: "analysis.md" } as any, }); expect(result.success).toBe(true); @@ -773,7 +773,7 @@ describe("Bun.build metafile option variants", () => { metafile: { json: "meta.json", markdown: "meta.md", - }, + } as any, }); expect(result.success).toBe(true); @@ -849,7 +849,7 @@ describe("Bun.build metafile option variants", () => { const result = await Bun.build({ entrypoints: [`${dir}/test.js`], outdir: `${dir}/dist`, - metafile: { markdown: "meta.md" }, + metafile: { markdown: "meta.md" } as any, }); expect(result.success).toBe(true); @@ -1469,7 +1469,7 @@ describe("metafile outputs[..].bytes is the size of the emitted file", () => { /** `bytes` of every metafile output, next to the size of the file the build produced for it. */ function outputSizes(result: Bun.BuildOutput, outdir: string | undefined) { - const reported: Record = {}; + const reported: Record = {}; const actual: Record = {}; for (const [key, output] of Object.entries((result.metafile as Metafile).outputs)) { reported[key] = output.bytes; diff --git a/test/bundler/native-plugin.test.ts b/test/bundler/native-plugin.test.ts index 8bc704864e3a..92e8242cceee 100644 --- a/test/bundler/native-plugin.test.ts +++ b/test/bundler/native-plugin.test.ts @@ -534,7 +534,7 @@ const many_foo = ["foo","foo","foo","foo","foo","foo","foo"] ], }); expect.unreachable(); - } catch (e) { + } catch (e: any) { expect(e.toString()).toContain( "onBeforeParse `napiModule` must be a Napi module which exports the `BUN_PLUGIN_NAME` symbol.", ); @@ -559,7 +559,7 @@ const many_foo = ["foo","foo","foo","foo","foo","foo","foo"] ], }); expect.unreachable(); - } catch (e) { + } catch (e: any) { expect(e.toString()).toContain( 'TypeError [ERR_INVALID_ARG_TYPE]: Could not find the symbol "OOGA_BOOGA_420" in the given napi module.', ); diff --git a/test/bundler/standalone.test.ts b/test/bundler/standalone.test.ts index 20cbc916e2af..2f6769ac9859 100644 --- a/test/bundler/standalone.test.ts +++ b/test/bundler/standalone.test.ts @@ -1,7 +1,7 @@ import { describe, expect, test } from "bun:test"; import { bunEnv, bunExe, isWindows, tempDir } from "harness"; import { existsSync } from "node:fs"; -import { SourceMapConsumer } from "source-map"; +import { SourceMapConsumer, type RawSourceMap } from "source-map"; describe("compile --target=browser", () => { test("inlines JS and CSS into HTML", async () => { @@ -692,7 +692,7 @@ console.log(greet("world"));`, return { html, map: map && JSON.parse(await map.text()) }; } - async function expectInlinedScriptToBeMapped(html: string, map: object) { + async function expectInlinedScriptToBeMapped(html: string, map: RawSourceMap) { const open = '")); const [firstLine] = script.split("\n"); diff --git a/test/bundler/transpiler/decorator-metadata.test.ts b/test/bundler/transpiler/decorator-metadata.test.ts index 41d1b95fc8a1..2a93df308200 100644 --- a/test/bundler/transpiler/decorator-metadata.test.ts +++ b/test/bundler/transpiler/decorator-metadata.test.ts @@ -389,13 +389,13 @@ describe("decorator metadata", () => { } // @ts-ignore @d1 - prop1: () => {}; + prop1!: () => {}; // @ts-ignore @d1 prop2: "foo" = "foo"; // @ts-ignore @d1 - prop3: symbol; + prop3!: symbol; } expect(Reflect.getMetadata("design:type", A)).toBeUndefined(); diff --git a/test/bundler/transpiler/macro-test.test.ts b/test/bundler/transpiler/macro-test.test.ts index 965008868621..4b5254346695 100644 --- a/test/bundler/transpiler/macro-test.test.ts +++ b/test/bundler/transpiler/macro-test.test.ts @@ -1,4 +1,4 @@ -import { escapeHTML } from "bun" assert { type: "macro" }; +import { escapeHTML } from "bun" with { type: "macro" }; import { describe, expect, test } from "bun:test"; import { bunEnv, bunExe, tempDir } from "harness"; import { existsSync } from "node:fs"; @@ -13,9 +13,9 @@ import defaultMacro, { identity as identity2, ireturnapromise, symbolKeys, -} from "./macro.ts" assert { type: "macro" }; +} from "./macro.ts" with { type: "macro" }; -import * as macros from "./macro.ts" assert { type: "macro" }; +import * as macros from "./macro.ts" with { type: "macro" }; test("bun builtins can be used in macros", async () => { expect(escapeHTML("abc!")).toBe("abc!"); @@ -142,6 +142,35 @@ test("ireturnapromise", async () => { expect(await ireturnapromise()).toEqual("aaa"); }); +// This file used `assert` for its own imports until TypeScript 7 made that a syntax error (TS2880). +test("the `assert { type: 'macro' }` spelling works for every form of import", async () => { + using dir = tempDir("macro-import-assertion", { + "macro.ts": `export function identity(arg: any) {\n return arg;\n}\nexport default function () {\n return "default";\n}\n`, + "index.ts": ` + import { escapeHTML } from "bun" assert { type: "macro" }; + import defaultMacro, { identity, identity as alias, default as defaultAlias } from "./macro.ts" assert { type: "macro" }; + import * as macros from "./macro.ts" assert { type: "macro" }; + console.log(JSON.stringify([escapeHTML(""), defaultMacro(), identity(1), alias(2), defaultAlias(), macros.identity(3)])); + `, + }); + await using proc = Bun.spawn({ + cmd: [bunExe(), "build", "--no-bundle", "index.ts"], + env: bunEnv, + cwd: String(dir), + stdout: "pipe", + stderr: "pipe", + }); + const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]); + // Every call is replaced by its result, so the macros ran at transpile time. Debug builds print + // "[macro] call identity" to stdout first, so only the tail of stdout is matched. + expect({ stdout: stdout.trim(), stderr, exitCode }).toMatchObject({ + stdout: expect.stringMatching( + /console\.log\(JSON\.stringify\(\["<a>", "default", 1, 2, "default", 3\]\)\);$/, + ), + exitCode: 0, + }); +}); + // A numeric key >= 100000 (JSC's MIN_SPARSE_ARRAY_INDEX) makes the property put inside // JSC__JSValue__putToPropertyKey take a path that can throw, so the binding must check for // an exception. BUN_JSC_validateExceptionChecks=1 aborts the child if the check is missing. diff --git a/test/bundler/transpiler/react-compiler-fixtures.test.ts b/test/bundler/transpiler/react-compiler-fixtures.test.ts index 765929d45852..6cc76df81681 100644 --- a/test/bundler/transpiler/react-compiler-fixtures.test.ts +++ b/test/bundler/transpiler/react-compiler-fixtures.test.ts @@ -354,14 +354,13 @@ async function compileInto(into: Compiled, minify: false | { syntax: true }): Pr external: ["*"], treeShaking: false, minify, - // @ts-expect-error — wired in JSBundler.rs but not yet in bun-types reactCompiler: true, reactCompilerParseTestPragmas: true, // Upstream's Babel harness enables the TS plugin unconditionally, so // many `.js` fixtures contain TS syntax (casts, type params). loader: { ".js": "tsx", ".mjs": "tsx" }, throw: false, - }); + } as Bun.BuildConfig); if (result.success) { for (const artifact of result.outputs) { diff --git a/test/cli/create/shadcn.tsx b/test/cli/create/shadcn.tsx index 1cee706fee65..1d36bec8dc6e 100644 --- a/test/cli/create/shadcn.tsx +++ b/test/cli/create/shadcn.tsx @@ -1,6 +1,10 @@ +// @ts-expect-error installed by `bun create` import { Button } from "@/components/ui/button"; +// @ts-expect-error installed by `bun create` import { Badge } from "@/components/ui/badge"; +// @ts-expect-error installed by `bun create` import { Card } from "@/components/ui/card"; +// @ts-expect-error installed by `bun create` import { CheckCircle } from "lucide-react"; export default function LandingPage() { diff --git a/test/cli/create/tailwind.tsx b/test/cli/create/tailwind.tsx index fb4dc341b95a..00a90401e922 100644 --- a/test/cli/create/tailwind.tsx +++ b/test/cli/create/tailwind.tsx @@ -1,7 +1,7 @@ export default function LandingPage() { let copied = false; const handleCopy = () => { - navigator.clipboard.writeText("bun create ./MyComponent.tsx"); + (navigator as any).clipboard.writeText("bun create ./MyComponent.tsx"); }; return ( diff --git a/test/cli/hot/hot.test.ts b/test/cli/hot/hot.test.ts index 6252c8304a51..1f011aecfb4a 100644 --- a/test/cli/hot/hot.test.ts +++ b/test/cli/hot/hot.test.ts @@ -17,7 +17,7 @@ const longTimeout = isDebug ? Infinity : 30_000; * was encountered, potentially losing data and causing test hangs. */ async function driveErrorReloadCycle( - runner: ReturnType, + runner: Bun.Subprocess<"ignore", "ignore", "pipe">, opts: { targetCount: number; onReload: (counter: number) => void; diff --git a/test/cli/hot/watch-many-dirs.test.ts b/test/cli/hot/watch-many-dirs.test.ts index 991ef6c3b72f..1ee32d5dee8e 100644 --- a/test/cli/hot/watch-many-dirs.test.ts +++ b/test/cli/hot/watch-many-dirs.test.ts @@ -67,7 +67,7 @@ if (globalThis.reloaded++ >= ${maxCount}) process.exit(0); for (let cycle = 0; cycle < maxCount; cycle++) { // Update all files simultaneously const timestamp = Date.now() + cycle; - const updatePromises = []; + const updatePromises: Promise[] = []; for (let i = 0; i < dirCount; i++) { const dirName = `dir-${i.toString().padStart(4, "0")}`; diff --git a/test/cli/inspect/BunFrontendDevServer.test.ts b/test/cli/inspect/BunFrontendDevServer.test.ts index af083513f938..a5301cac32e9 100644 --- a/test/cli/inspect/BunFrontendDevServer.test.ts +++ b/test/cli/inspect/BunFrontendDevServer.test.ts @@ -73,7 +73,7 @@ class BunFrontendDevServerSession extends InspectorSession { } describe.if(isPosix)("BunFrontendDevServer inspector protocol", () => { - let devServerProcess: Subprocess; + let devServerProcess: Subprocess<"ignore", "pipe", "pipe">; let serverUrl: URL; let session: BunFrontendDevServerSession; let tempdir: string; @@ -881,7 +881,7 @@ function decodeGraphUpdate(buffer) { // Parse the files from the buffer function parseFiles(buffer, count, offset) { - const files = []; + const files: typeof clientFiles = []; for (let i = 0; i < count; i++) { const nameLength = readUint32(buffer, offset); @@ -921,7 +921,7 @@ function decodeGraphUpdate(buffer) { // Parse the edges from the buffer function parseEdges(buffer, count, offset) { - const edges = []; + const edges: typeof clientEdges = []; for (let i = 0; i < count; i++) { const from = readUint32(buffer, offset); offset += 4; diff --git a/test/cli/inspect/test-reporter.test.ts b/test/cli/inspect/test-reporter.test.ts index 45dd1d10d451..607d04a5ea37 100644 --- a/test/cli/inspect/test-reporter.test.ts +++ b/test/cli/inspect/test-reporter.test.ts @@ -166,7 +166,7 @@ class TestReporterSession extends InspectorSession { } describe.if(isPosix)("TestReporter inspector protocol", () => { - let proc: Subprocess | undefined; + let proc: Subprocess<"ignore", "pipe", "pipe"> | undefined; let socket: ReturnType extends Promise ? T : never; afterEach(() => { diff --git a/test/cli/install/bun-add.test.ts b/test/cli/install/bun-add.test.ts index 01325cc28cb5..96e94c89f4ed 100644 --- a/test/cli/install/bun-add.test.ts +++ b/test/cli/install/bun-add.test.ts @@ -1313,7 +1313,7 @@ describe("npm aliases", () => { setHandler(async request => { const response = await registry(request); if (request.url.endsWith(".tgz")) return response; - const manifest = await response.json(); + const manifest: any = await response.json(); manifest["dist-tags"].rc = "0.0.5-rc.123456789"; return Response.json(manifest); }); diff --git a/test/cli/install/bun-audit.test.ts b/test/cli/install/bun-audit.test.ts index b0197c013fb3..6f5e78a63bba 100644 --- a/test/cli/install/bun-audit.test.ts +++ b/test/cli/install/bun-audit.test.ts @@ -24,7 +24,7 @@ function fixture( return join(import.meta.dirname, "registry", "fixtures", "audit", folder); } -let server: Bun.Server; +let server: Bun.Server; const verdaccio = new VerdaccioRegistry(); beforeAll(async () => { diff --git a/test/cli/install/bun-dedupe.test.ts b/test/cli/install/bun-dedupe.test.ts index 5acae0cba2e9..b88d72da511e 100644 --- a/test/cli/install/bun-dedupe.test.ts +++ b/test/cli/install/bun-dedupe.test.ts @@ -1827,7 +1827,7 @@ test.concurrent.each<[string, (packageDir: string) => Promise, string]>( const after = await lock(packageDir); expect(after).toContain('"no-deps@1.0.0"'); expect(after).not.toContain('"no-deps@1.1.0"'); - expect(after.split("\n")).toContain(localEntry); + expect(after.split("\n")).toContain(localEntry!); expect(await nodeModulesVersion(packageDir, "nd-local")).toBe("2.0.0"); expect(await nodeModulesVersion(packageDir, "no-deps")).toBe("1.0.0"); await expectAlreadyDeduplicated(packageDir, 4); diff --git a/test/cli/install/bun-install-git-deps.test.ts b/test/cli/install/bun-install-git-deps.test.ts index e63c751009a6..ca6d27679bea 100644 --- a/test/cli/install/bun-install-git-deps.test.ts +++ b/test/cli/install/bun-install-git-deps.test.ts @@ -10,7 +10,7 @@ import { bunEnv, bunExe, isLinux, isWindows, normalizeBunSnapshot, tempDir } fro import { join } from "path"; import { pathToFileURL } from "url"; -const gitEnv = { +const gitEnv: NodeJS.Dict = { ...bunEnv, GIT_CONFIG_NOSYSTEM: "1", GIT_AUTHOR_NAME: "Test", @@ -186,7 +186,7 @@ function writeProject(root: string, dependencies: Record): strin } async function runInstall(cwd: string, cacheDir: string, extraEnv: Record, ...args: string[]) { - const env = { ...gitEnv, ...extraEnv, BUN_INSTALL_CACHE_DIR: cacheDir }; + const env: NodeJS.Dict = { ...gitEnv, ...extraEnv, BUN_INSTALL_CACHE_DIR: cacheDir }; // Set on ASAN CI lanes; it arms a subreaper around internal git spawns that // SIGKILLs concurrent clone tasks (see #33982). This test exercises install // task bookkeeping, not orphan reaping. @@ -660,7 +660,7 @@ exit 1 [nameOf("a")]: "git+https://localhost/scope/pkg-a.git", [nameOf("b")]: "git+https://localhost/scope/pkg-b.git", }); - const env = { ...gitEnv, BUN_INSTALL_CACHE_DIR: join(root, "cache"), PATH: `${bin}:${gitEnv.PATH}` }; + const env: typeof gitEnv = { ...gitEnv, BUN_INSTALL_CACHE_DIR: join(root, "cache"), PATH: `${bin}:${gitEnv.PATH}` }; delete env.BUN_FEATURE_FLAG_NO_ORPHANS; await using proc = Bun.spawn({ cmd: [bunExe(), "install"], diff --git a/test/cli/install/bun-install-native-binlink.test.ts b/test/cli/install/bun-install-native-binlink.test.ts index 71df3ee19c83..1edd5b30dd37 100644 --- a/test/cli/install/bun-install-native-binlink.test.ts +++ b/test/cli/install/bun-install-native-binlink.test.ts @@ -216,7 +216,7 @@ describe.concurrent("native binlink optimization", () => { // still run `node install.js`. describe("nested nativeDependencies", () => { async function setup(opts: { linker: "hoisted" | "isolated"; deps: Record; extraEnv?: object }) { - let env: Record = { ...bunEnv, ...(opts.extraEnv ?? {}) }; + let env: NodeJS.Dict = { ...bunEnv, ...(opts.extraEnv ?? {}) }; const { packageDir, packageJson } = await verdaccio.createTestDir(); env.BUN_INSTALL_CACHE_DIR = join(packageDir, ".bun-cache"); env.BUN_TMPDIR = env.TMPDIR = env.TEMP = join(packageDir, ".bun-tmp"); diff --git a/test/cli/install/bun-install-registry.test.ts b/test/cli/install/bun-install-registry.test.ts index 91bb302c2df2..15ae2d514406 100644 --- a/test/cli/install/bun-install-registry.test.ts +++ b/test/cli/install/bun-install-registry.test.ts @@ -94,10 +94,10 @@ async function generateRegistryUser(username: string, password: string): Promise }); if (response.ok) { - const data = await response.json(); + const data: any = await response.json(); return data.token; } else { - throw new Error("Failed to create user:", response.statusText); + throw new Error("Failed to create user:", response.statusText as any); } } @@ -281,7 +281,7 @@ describe("certificate authority", () => { /** Runs `bun install ` with `HTTPS_PROXY` set, for a project whose one dependency is a tarball on `server`. */ async function installThroughProxy( - server: { port: number }, + server: { port?: number }, proxyUrl: string, args: string[], extraEnv: Record = {}, diff --git a/test/cli/install/bun-install.test.ts b/test/cli/install/bun-install.test.ts index 7ac1c0c03b0e..31547343e7a4 100644 --- a/test/cli/install/bun-install.test.ts +++ b/test/cli/install/bun-install.test.ts @@ -33,16 +33,23 @@ expect.extend({ toBeWorkspaceLink, toBeValidBin, toHaveBins, - toHaveWorkspaceLink: function (package_dir: string, [link, real]: [string, string]) { + toHaveWorkspaceLink: function (package_dir: any, [link, real]: [string, string]) { const target = readlinkSync(join(package_dir, "node_modules", link)); return toBeWorkspaceLink(target, isWindows ? join(package_dir, real) : join("..", real)); }, - toHaveWorkspaceLink2: function (package_dir: string, [link, realPosix, realWin]: [string, string, string]) { + toHaveWorkspaceLink2: function (package_dir: any, [link, realPosix, realWin]: [string, string, string]) { const target = readlinkSync(join(package_dir, "node_modules", link)); return toBeWorkspaceLink(target, isWindows ? join(package_dir, realWin) : join("..", realPosix)); }, }); +declare module "bun:test" { + interface Matchers { + toHaveWorkspaceLink(expected: [link: string, real: string]): void; + toHaveWorkspaceLink2(expected: [link: string, realPosix: string, realWin: string]): void; + } +} + setDefaultTimeout(1000 * 60 * 5); beforeAll(() => { @@ -927,8 +934,8 @@ describe.concurrent("bun-install", () => { type Received = { url: string; authorization: string | null }; - function recording(received: Received[], handler: (req: Request, server: { port: number }) => Response) { - return (req: Request, server: { port: number }) => { + function recording(received: Received[], handler: (req: Request, server: { port?: number }) => Response) { + return (req: Request, server: { port?: number }) => { received.push({ url: req.url, authorization: req.headers.get("authorization") }); return handler(req, server); }; @@ -7506,7 +7513,7 @@ describe.concurrent("bun-install", () => { } const lockfile = await install(); - const packages = Bun.JSONC.parse(lockfile).packages as Record; + const packages = (Bun.JSONC.parse(lockfile) as any).packages as Record; expect(Object.fromEntries(Object.entries(packages).map(([name, [resolution]]) => [name, resolution]))).toEqual( expected, ); @@ -8454,7 +8461,7 @@ describe.concurrent("bun-install", () => { JSON.stringify({ name: "package3", version: "0.0.1", - workspaces: [join(base, "packages/**/*")], + workspaces: [join(base as any, "packages/**/*")], }), "packages": { "frontend": { @@ -9757,11 +9764,13 @@ describe.concurrent("bun-install", () => { const regURL = "asdfghjklqwertyuiop"; await writeFile( + // @ts-expect-error no ctx here join(ctx.package_dir, "bunfig.toml"), Bun.TOML.stringify({ install: { cache: false, registry: regURL } }), ); await writeFile( + // @ts-expect-error no ctx here join(ctx.package_dir, "package.json"), JSON.stringify({ name: "foo", @@ -9774,6 +9783,7 @@ describe.concurrent("bun-install", () => { const { stdout, stderr, exited } = spawn({ cmd: [bunExe(), "install"], + // @ts-expect-error no ctx here cwd: ctx.package_dir, stdout: "pipe", stdin: "pipe", diff --git a/test/cli/install/bun-patch.test.ts b/test/cli/install/bun-patch.test.ts index 0e61d4526398..cf7c036c08a0 100644 --- a/test/cli/install/bun-patch.test.ts +++ b/test/cli/install/bun-patch.test.ts @@ -1,10 +1,10 @@ -import { $, ShellOutput } from "bun"; +import { $ } from "bun"; import { afterAll, beforeAll, describe, expect, setDefaultTimeout, test } from "bun:test"; import { lstatSync, readFileSync } from "fs"; import { bunEnv, bunExe, isASAN, tempDir, VerdaccioRegistry } from "harness"; import { isAbsolute, join, sep } from "path"; -const expectNoError = (o: ShellOutput) => expect(o.stderr.toString()).not.toContain("error"); +const expectNoError = (o: $.ShellOutput) => expect(o.stderr.toString()).not.toContain("error"); // const platformPath = (path: string) => (process.platform === "win32" ? path.replaceAll("/", sep) : path); const platformPath = (path: string) => path; @@ -447,7 +447,7 @@ describe("bun patch ", async () => { return { subdir, absPath }; } - async function check(tempdir: string, commit: ShellOutput) { + async function check(tempdir: string, commit: $.ShellOutput) { expect(commit.stderr.toString()).not.toContain("ENOENT"); expect(commit.stderr.toString()).not.toContain("error"); expect(commit.exitCode).toBe(0); diff --git a/test/cli/install/bun-prune.test.ts b/test/cli/install/bun-prune.test.ts index b9162889a85c..e7e5948774cf 100644 --- a/test/cli/install/bun-prune.test.ts +++ b/test/cli/install/bun-prune.test.ts @@ -325,7 +325,7 @@ test.concurrent("prunes nested node_modules folders the tree installs into", asy expect(existsSync(join(nested, "package.json"))).toBeTrue(); }); -test.concurrent.each([["--production"], ["--prod"], ["--omit=dev"]])( +test.concurrent.each([["--production"], ["--prod"], ["--omit=dev"]] as string[][])( "%s removes packages only reachable through devDependencies", async (...flags: string[]) => { const dir = await setup({ diff --git a/test/cli/install/bun-run.test.ts b/test/cli/install/bun-run.test.ts index 25675aca221d..44f8acf2fe42 100644 --- a/test/cli/install/bun-run.test.ts +++ b/test/cli/install/bun-run.test.ts @@ -4,7 +4,7 @@ import { chmodSync } from "fs"; import { bunEnv as bunEnv_, bunExe, isWindows, tempDir, tempDirWithFiles } from "harness"; import { basename, join } from "path"; -const bunEnv = { +const bunEnv: typeof bunEnv_ = { ...bunEnv_, BUN_INTERNAL_SUPPRESS_CRASH_IN_BUN_RUN: "1", }; diff --git a/test/cli/install/bun-update-transitive.test.ts b/test/cli/install/bun-update-transitive.test.ts index 6eea04449b18..4a0686958e21 100644 --- a/test/cli/install/bun-update-transitive.test.ts +++ b/test/cli/install/bun-update-transitive.test.ts @@ -142,7 +142,7 @@ const NOT_A_DEPENDENCY_HERE = (name: string, ...workspaces: string[]) => notADependencyOf("this workspace", name, ...workspaces); const NOT_A_DEPENDENCY_OF_SELECTION = (name: string, ...workspaces: string[]) => notADependencyOf("the selected workspaces", name, ...workspaces); -const notCheckedWarning = (server: Bun.Server, name: string, version: string, status: number) => +const notCheckedWarning = (server: Bun.Server, name: string, version: string, status: number) => `warn: ${name}@${version} was not checked for updates: GET ${server.url.origin}/${name} - ${status}\n`; // The manifest-cache progress bar must never leak its `Resolving... ` fragment into a piped stderr. @@ -1280,13 +1280,13 @@ async function serveRegistry(manifests: Manifests, tags: Tags = {}, knobs: Regis } // Installs `pinned` against the in-memory registry, then re-installs `packageJson`, which drops the pins that parked the transitive edges. -async function setupServed(server: Bun.Server, prefix: string, pinned: Json, packageJson: Json = pinned) { +async function setupServed(server: Bun.Server, prefix: string, pinned: Json, packageJson: Json = pinned) { const dir = await installServed(server, prefix, pinned); if (packageJson !== pinned) await reinstall(dir, packageJson); return dir; } -const servedBunfig = (server: Bun.Server, dir: string, extra: Json = {}) => +const servedBunfig = (server: Bun.Server, dir: string, extra: Json = {}) => write( join(dir, "bunfig.toml"), Bun.TOML.stringify({ @@ -1300,14 +1300,14 @@ const servedBunfig = (server: Bun.Server, dir: string, extra: Json = {}) => }), ); -async function installServed(server: Bun.Server, prefix: string, packageJson: Json, ...args: string[]) { +async function installServed(server: Bun.Server, prefix: string, packageJson: Json, ...args: string[]) { const dir = String(tempDir(prefix, { "package.json": stringify(packageJson) })); await servedBunfig(server, dir); await install(dir, ...args); return dir; } -const freshInstallLock = async (server: Bun.Server, prefix: string, packageJson: Json, ...args: string[]) => +const freshInstallLock = async (server: Bun.Server, prefix: string, packageJson: Json, ...args: string[]) => lock(await installServed(server, prefix, packageJson, ...args)); test.concurrent("`bun update ` leaves the named package's own dependencies where they are", async () => { @@ -1613,7 +1613,7 @@ const STALE_CHILDREN: Manifests = { "other-leaf": { "1.0.0": {}, "1.1.0": {} }, }; -async function staleChildren(server: Bun.Server) { +async function staleChildren(server: Bun.Server) { const packageJson = pkgJson({ parent: "^1.0.0", other: "^1.0.0" }); const dir = await setupServed( server, @@ -1675,7 +1675,7 @@ const LEAF_1_1_0_FATAL_SCANNER = `export const scanner = { }; `; -async function withLeafScanner(server: Bun.Server, dir: string) { +async function withLeafScanner(server: Bun.Server, dir: string) { await write(join(dir, "scanner.ts"), LEAF_1_1_0_FATAL_SCANNER); await servedBunfig(server, dir, { security: { scanner: "./scanner.ts" } }); return lockText(dir); @@ -1753,7 +1753,7 @@ const TAGGED: Manifests = { }; // `stable` is moved after the install; `bun install` keeps the locked version, so only `bun update` can follow it. -async function movedTag(server: Bun.Server, tags: Tags, from: string, to: string) { +async function movedTag(server: Bun.Server, tags: Tags, from: string, to: string) { const packageJson = pkgJson({ parent: "^1.0.0" }); const dir = await setupServed(server, "update-moved-tag-", packageJson); expect(await lockedVersions(dir, "leaf")).toStrictEqual([from]); @@ -2050,10 +2050,10 @@ test.concurrent("`bun update --silent` swallows the unfetchable-manifest warning // `bun outdated` and `bun update -i` exist to answer for the direct dependencies, so for them a manifest that does not arrive is reported and fails the command (a registry that is down must not read as "nothing to update"); only an optional dependency's is a warning. const errorLines = (stderr: string) => stderr.split("\n").filter(line => line.startsWith("error:")); -const manifestFailure = (server: Bun.Server, status: number) => `GET ${server.url.origin}/leaf - ${status}`; +const manifestFailure = (server: Bun.Server, status: number) => `GET ${server.url.origin}/leaf - ${status}`; // leaf@1.0.0 installed while 1.1.0 exists, with the manifest cache off so every later command asks the registry again. -async function staleDirectLeaf(server: Bun.Server, groups: Groups = {}) { +async function staleDirectLeaf(server: Bun.Server, groups: Groups = {}) { const dir = await installServed(server, "direct-manifest-failure-", grouped({ leaf: "1.0.0" }, groups)); await servedBunfig(server, dir, { cache: false }); return dir; @@ -2138,7 +2138,11 @@ const hangUp = () => Bun.listen({ hostname: "127.0.0.1", port: 0, socket: { open: socket => void socket.end(), data() {} } }); // Breaks the download of leaf's manifest or of leaf@1.1.0's tarball; `down` is the origin of a `hangUp()` host. Returns the one warning to expect and the flags the update needs. -type Outage = (server: Bun.Server, knobs: RegistryKnobs, down: string) => { warning: unknown; flags?: string[] }; +type Outage = ( + server: Bun.Server, + knobs: RegistryKnobs, + down: string, +) => { warning: unknown; flags?: string[] }; const OUTAGES: Record = { "a 404 for the manifest": (server, knobs) => { knobs.status!.leaf = 404; @@ -2195,7 +2199,7 @@ test.concurrent.each( const { warning, flags = [] } = OUTAGES[outage](server, knobs, `http://127.0.0.1:${down.port}`); const { stderr, exitCode } = await run(dir, "update", ...args, ...flags); - expect(warningLines(stderr)).toStrictEqual([warning]); + expect(warningLines(stderr)).toStrictEqual([warning]); expect(errorLines(stderr)).toStrictEqual([]); expect(stderr).not.toContain("Saved lockfile"); expect(await packageJsonText(dir)).toBe(before.packageJson); diff --git a/test/cli/install/bun-upgrade.test.ts b/test/cli/install/bun-upgrade.test.ts index 6857b47e84b5..85226ef5275c 100644 --- a/test/cli/install/bun-upgrade.test.ts +++ b/test/cli/install/bun-upgrade.test.ts @@ -116,7 +116,7 @@ async function writeFakeReleaseZip(outPath: string, version: string): Promise }; +type ReleaseServer = Bun.Server & { env: Record }; function startReleaseServer(opts: { tagName: string; diff --git a/test/cli/install/bunx.test.ts b/test/cli/install/bunx.test.ts index ec0a9fb5a508..47c6b96727b1 100644 --- a/test/cli/install/bunx.test.ts +++ b/test/cli/install/bunx.test.ts @@ -10,7 +10,7 @@ import { dummyAfterAll, dummyBeforeAll, dummyBeforeEach, dummyRegistry, getPort, setDefaultTimeout(1000 * 60 * 5); let x_dir: string; -let env: Record = { ...bunEnv }; +let env = { ...bunEnv } as Record; // Each test that hits the network gets its own isolated tmpdir + install cache // so the network-heavy tests can run concurrently without sharing bunx cache state. diff --git a/test/cli/install/catalogs.test.ts b/test/cli/install/catalogs.test.ts index 159c6aabe4aa..08945dc8f724 100644 --- a/test/cli/install/catalogs.test.ts +++ b/test/cli/install/catalogs.test.ts @@ -148,7 +148,7 @@ describe("basic", () => { const { packageDir } = await registry.createTestDir({ bunfigOpts: { saveTextLockfile: !binaryLockfile, linker: "hoisted" }, }); - const packageJson = await createBasicCatalogMonorepo(packageDir, "catalog-basic-2"); + const packageJson: any = await createBasicCatalogMonorepo(packageDir, "catalog-basic-2"); let { err } = await runBunInstall(bunEnv, packageDir); expect(err).toContain("Saved lockfile"); diff --git a/test/cli/install/dummy.registry.ts b/test/cli/install/dummy.registry.ts index 282efcb0507a..1f55d8369b36 100644 --- a/test/cli/install/dummy.registry.ts +++ b/test/cli/install/dummy.registry.ts @@ -44,7 +44,7 @@ type Pkg = { }; }; -let server: Server; +let server: Server; export let root_url: string; export let check_npm_auth_type = { check: true }; diff --git a/test/cli/install/install-fd-leak.test.ts b/test/cli/install/install-fd-leak.test.ts index dee8fc7ec04e..8d44bb934d4c 100644 --- a/test/cli/install/install-fd-leak.test.ts +++ b/test/cli/install/install-fd-leak.test.ts @@ -13,7 +13,7 @@ const NUM_FILES = 1500; const FD_LIMIT = 1024; const LINKERS = ["isolated", "hoisted"] as const; -const BACKENDS = (["copyfile", "hardlink"] as const).concat(isMacOS ? (["clonefile"] as const) : []); +const BACKENDS = (["copyfile", "hardlink"] as string[]).concat(isMacOS ? (["clonefile"] as const) : []); // `ulimit` isn't available on Windows; skip the matrix there. describe.skipIf(isWindows)("install does not leak file descriptors", () => { diff --git a/test/cli/install/isolated-install.test.ts b/test/cli/install/isolated-install.test.ts index 4da9a83c8270..6b44b850e48d 100644 --- a/test/cli/install/isolated-install.test.ts +++ b/test/cli/install/isolated-install.test.ts @@ -2251,8 +2251,8 @@ test("transitive peer resolves when its tarball is cached from another registry" const cacheDir = join(String(root), "cache").replaceAll("\\", "\\\\"); const bunfig = (port: number) => `[install]\ncache = "${cacheDir}"\nregistry = "http://localhost:${port}/"\nlinker = "isolated"\n`; - await write(join(String(root), "warmup", "bunfig.toml"), bunfig(serverA.port)); - await write(join(String(root), "cold", "bunfig.toml"), bunfig(serverB.port)); + await write(join(String(root), "warmup", "bunfig.toml"), bunfig(serverA.port!)); + await write(join(String(root), "cold", "bunfig.toml"), bunfig(serverB.port!)); // Caches strict-peer-dep's manifest (registry A's URL hash) and extracts its // tarball (shared across registries). @@ -2691,7 +2691,7 @@ describe("store entry names of URL dependencies", () => { test.concurrent.each(tarballCases)("tarball dependency with %s", async (_, urlFor, hashed) => { using server = serveTarballs(); - const url = urlFor(server.port); + const url = urlFor(server.port!); using dir = tempDir("store-name-tarball-", { "bunfig.toml": `[install]\nlinker = "isolated"\n`, "package.json": JSON.stringify({ name: "app", dependencies: { "no-deps": url } }), @@ -2815,7 +2815,7 @@ describe("store entry names of URL dependencies", () => { using dir = tempDir("store-name-git-", {}); const { bare, sha } = await createBareRepo(String(dir)); using server = serveBareRepo(bare); - const repo = repoFor(server.port); + const repo = repoFor(server.port!); const project = join(String(dir), "project"); await write( join(project, "package.json"), diff --git a/test/cli/install/migrate-bun-lockb-v2.test.ts b/test/cli/install/migrate-bun-lockb-v2.test.ts index 3c4a4d141589..765dedd262ac 100644 --- a/test/cli/install/migrate-bun-lockb-v2.test.ts +++ b/test/cli/install/migrate-bun-lockb-v2.test.ts @@ -1,12 +1,12 @@ import { file, spawn } from "bun"; import { install_test_helpers } from "bun:internal-for-testing"; import { expect, test } from "bun:test"; -import { bunEnv, bunExe, tempDir } from "harness"; +import { bunEnv, bunExe, tempDir, type DirectoryTree } from "harness"; import { cp } from "node:fs/promises"; import { join } from "node:path"; const { parseLockfile } = install_test_helpers; -const tests = [ +const tests: { name: string; lockfile: string; files: DirectoryTree }[] = [ { name: "migrate-bun-lockb-v2", lockfile: "bun.lockb.v2", diff --git a/test/cli/install/migration/pnpm-lock-v9.test.ts b/test/cli/install/migration/pnpm-lock-v9.test.ts index bfc0afca6f13..eaef60b484e1 100644 --- a/test/cli/install/migration/pnpm-lock-v9.test.ts +++ b/test/cli/install/migration/pnpm-lock-v9.test.ts @@ -2390,7 +2390,7 @@ snapshots: `; const goneRegistry = () => Bun.serve({ port: 0, fetch: () => new Response("gone", { status: 404 }) }); - const project = (registry: Bun.Server, group: string) => + const project = (registry: Bun.Server, group: string) => tempDir("pnpm-v9-manifest-gone", { "package.json": JSON.stringify({ name: "manifest-gone", [group]: { "no-deps": "1.0.1" } }), "bunfig.toml": `[install]\nregistry = "${registry.url.href}"\n`, diff --git a/test/cli/install/migration/pnpm-migration.test.ts b/test/cli/install/migration/pnpm-migration.test.ts index 40e8b5e4ff8d..b6d79dda159b 100644 --- a/test/cli/install/migration/pnpm-migration.test.ts +++ b/test/cli/install/migration/pnpm-migration.test.ts @@ -1,6 +1,6 @@ import { file, spawn } from "bun"; import { afterAll, beforeAll, describe, expect, test } from "bun:test"; -import { bunExe, bunEnv as env, nodeModulesPackages, tempDir, VerdaccioRegistry } from "harness.js"; +import { bunExe, bunEnv as env, nodeModulesPackages, tempDir, VerdaccioRegistry } from "harness"; import { join } from "path"; let verdaccio = new VerdaccioRegistry(); diff --git a/test/cli/install/minimum-release-age.test.ts b/test/cli/install/minimum-release-age.test.ts index 1f7a0f934640..7f464650c96b 100644 --- a/test/cli/install/minimum-release-age.test.ts +++ b/test/cli/install/minimum-release-age.test.ts @@ -13,7 +13,7 @@ setDefaultTimeout(1000 * 60 * 5); * prerelease handling, 7-day give-up threshold, and edge cases. */ describe("minimum-release-age", () => { - let mockRegistryServer: Server; + let mockRegistryServer: Server; let mockRegistryUrl: string; const currentTime = Date.now(); const SECONDS_PER_DAY = 24 * 60 * 60; @@ -39,7 +39,7 @@ describe("minimum-release-age", () => { }; let tarSize = 0; - const entries = []; + const entries: Buffer[] = []; for (const [path, content] of Object.entries(files)) { const contentBuf = Buffer.from(content, "utf8"); diff --git a/test/cli/install/npmrc.test.ts b/test/cli/install/npmrc.test.ts index 7b0675b1c5c4..b86111c962ea 100644 --- a/test/cli/install/npmrc.test.ts +++ b/test/cli/install/npmrc.test.ts @@ -177,7 +177,7 @@ registry = http://localhost:${registry.port}/ // bunEnv spreads process.env and CI runners commonly export XDG_CONFIG_HOME, so it // is removed here and each case passes back exactly the value it is testing. async function publishDryRun(dir: string, envOverride: Record) { - const spawnEnv = { ...env, HOME: join(dir, "home"), USERPROFILE: join(dir, "home") }; + const spawnEnv: typeof env = { ...env, HOME: join(dir, "home"), USERPROFILE: join(dir, "home") }; delete spawnEnv.XDG_CONFIG_HOME; await using proc = Bun.spawn({ diff --git a/test/cli/install/simple-dummy-registry.ts b/test/cli/install/simple-dummy-registry.ts index 8efb61d324ad..551e35739ec3 100644 --- a/test/cli/install/simple-dummy-registry.ts +++ b/test/cli/install/simple-dummy-registry.ts @@ -5,7 +5,7 @@ const __dirname = dirname(Bun.fileURLToPath(import.meta.url)); export class SimpleRegistry { private debugLogs: boolean; - private server: Server | null = null; + private server: Server | null = null; private port: number = 0; public requestedUrls: string[] = []; private scannerBehavior: "clean" | "warn" | "fatal" = "clean"; diff --git a/test/cli/run/esm-defineProperty.test.ts b/test/cli/run/esm-defineProperty.test.ts index 5ddadabbccf2..69e4eec18541 100644 --- a/test/cli/run/esm-defineProperty.test.ts +++ b/test/cli/run/esm-defineProperty.test.ts @@ -7,7 +7,7 @@ test("defineProperty", () => { expect(CJS.a).toBe(1); expect(CJS.b).toBe(2); // non-enumerable getter/setter are not copied, matching node.js - expect(CJS.c).toBe(undefined); + expect(CJS.c as number | undefined).toBe(undefined); expect(Bun.inspect(CJS.default)).toBe(`{\n a: 1,\n b: 2,\n c: [Getter],\n}`); }); diff --git a/test/cli/run/markdown-entrypoint.test.ts b/test/cli/run/markdown-entrypoint.test.ts index 653046cf8457..b27b69446d60 100644 --- a/test/cli/run/markdown-entrypoint.test.ts +++ b/test/cli/run/markdown-entrypoint.test.ts @@ -218,7 +218,7 @@ describe("bun ", () => { using dir = tempDir("md-no-color-", { "doc.md": "# Hello\n\n**world**\n", }); - const env = { ...bunEnv, NO_COLOR: "1" }; + const env: NodeJS.Dict = { ...bunEnv, NO_COLOR: "1" }; // FORCE_COLOR set to anything (even "") forces colors on, so drop it. delete env.FORCE_COLOR; await using proc = Bun.spawn({ diff --git a/test/cli/run/no-orphans.test.ts b/test/cli/run/no-orphans.test.ts index 9ebcddfed0d2..77bc114b0484 100644 --- a/test/cli/run/no-orphans.test.ts +++ b/test/cli/run/no-orphans.test.ts @@ -1,6 +1,6 @@ import { dlopen, FFIType } from "bun:ffi"; import { describe, expect, setDefaultTimeout, test } from "bun:test"; -import { bunEnv, bunExe, isLinux, isMusl, isWindows, tempDir } from "harness"; +import { bunEnv, bunExe, isLinux, isMusl, isWindows, tempDir, type DirectoryTree } from "harness"; import { chmodSync, readFileSync } from "node:fs"; import { setTimeout as sleep } from "node:timers/promises"; @@ -80,7 +80,7 @@ const fixture = tempDir("no-orphans", { }); async function spawnTree(noOrphans: string | undefined, childScript = "child.js") { - const env: Record = { ...bunEnv }; + const env: NodeJS.Dict = { ...bunEnv }; // bunEnv spreads process.env; make sure an ambient BUN_FEATURE_FLAG_NO_ORPHANS // from the test runner doesn't leak into the "unset" case. delete env.BUN_FEATURE_FLAG_NO_ORPHANS; @@ -282,7 +282,7 @@ describe.concurrent.each([ process.exit(0); `, }); - const env: Record = { ...bunEnv, ...extraEnv }; + const env: NodeJS.Dict = { ...bunEnv, ...extraEnv }; if (!("BUN_FEATURE_FLAG_NO_ORPHANS" in extraEnv)) delete env.BUN_FEATURE_FLAG_NO_ORPHANS; const proc = Bun.spawn({ cmd: [bunExe(), ...argv, "clean-exit.js"], @@ -332,8 +332,8 @@ describe.concurrent.each([ }, ])("bun run --no-orphans $label: supervisor SIGKILLed", ({ runArgs, files }) => { test.concurrent.skipIf(!isPosix)("bun run and the script exit", async () => { - using dir = tempDir("no-orphans-run", files); - const env: Record = { ...bunEnv }; + using dir = tempDir("no-orphans-run", files as DirectoryTree); + const env: NodeJS.Dict = { ...bunEnv }; delete env.BUN_FEATURE_FLAG_NO_ORPHANS; const sh = Bun.spawn({ cmd: ["/bin/sh", "-c", `"${bunExe()}" run --no-orphans ${runArgs} & wait`], @@ -599,7 +599,7 @@ test.concurrent.skipIf(!isPosix)("bun run --no-orphans