import { unsafe } from "bun";
import { expect, it, test } from "bun:test";
import { withoutAggressiveGC } from "harness";
test("exists", () => {
expect(typeof URL !== "undefined").toBe(true);
expect(typeof URLSearchParams !== "undefined").toBe(true);
expect(typeof DOMException !== "undefined").toBe(true);
expect(typeof Event !== "undefined").toBe(true);
expect(typeof EventTarget !== "undefined").toBe(true);
expect(typeof AbortController !== "undefined").toBe(true);
expect(typeof AbortSignal !== "undefined").toBe(true);
expect(typeof CustomEvent !== "undefined").toBe(true);
expect(typeof Headers !== "undefined").toBe(true);
expect(typeof ErrorEvent !== "undefined").toBe(true);
expect(typeof CloseEvent !== "undefined").toBe(true);
expect(typeof MessageEvent !== "undefined").toBe(true);
expect(typeof TextEncoder !== "undefined").toBe(true);
expect(typeof WebSocket !== "undefined").toBe(true);
expect(typeof Blob !== "undefined").toBe(true);
expect(typeof FormData !== "undefined").toBe(true);
});
test("CloseEvent", () => {
var event = new CloseEvent("close", { reason: "world" });
expect(event.type).toBe("close");
const target = new EventTarget();
var called = false;
target.addEventListener("close", ({ type, reason }) => {
expect(type).toBe("close");
expect(reason).toBe("world");
called = true;
});
target.dispatchEvent(event);
expect(called).toBe(true);
});
test("MessageEvent", () => {
var event = new MessageEvent("message", { data: "world" });
expect(event.type).toBe("message");
const target = new EventTarget();
var called = false;
target.addEventListener("message", ({ type, data }) => {
expect(type).toBe("message");
expect(data).toBe("world");
called = true;
});
target.dispatchEvent(event);
expect(called).toBe(true);
});
it("crypto.getRandomValues", () => {
var foo = new Uint8Array(32);
// run it once buffered and unbuffered
{
var array = crypto.getRandomValues(foo);
expect(array).toBe(foo);
expect(array.reduce((sum, a) => (sum += a === 0), 0) != foo.length).toBe(true);
}
// disable it for this block because it tends to get stuck here running the GC forever
withoutAggressiveGC(() => {
// run it again to check that the fast path works
for (var i = 0; i < 9000; i++) {
var array = crypto.getRandomValues(foo);
expect(array).toBe(foo);
}
});
// run it on a large input
expect(!!crypto.getRandomValues(new Uint8Array(8096)).find(a => a > 0)).toBe(true);
{
// any additional input into getRandomValues() makes it unbuffered
var array = crypto.getRandomValues(foo, "unbuffered");
expect(array).toBe(foo);
expect(array.reduce((sum, a) => (sum += a === 0), 0) != foo.length).toBe(true);
}
});
// not actually a web global
it("crypto.timingSafeEqual", () => {
const crypto = import.meta.require("node:crypto");
var uuidStr = crypto.randomUUID();
expect(uuidStr.length).toBe(36);
expect(uuidStr[8]).toBe("-");
expect(uuidStr[13]).toBe("-");
expect(uuidStr[18]).toBe("-");
expect(uuidStr[23]).toBe("-");
const uuid = Buffer.from(uuidStr);
expect(crypto.timingSafeEqual(uuid, uuid)).toBe(true);
expect(crypto.timingSafeEqual(uuid, uuid.slice())).toBe(true);
try {
crypto.timingSafeEqual(uuid, uuid.slice(1));
expect(false).toBe(true);
} catch (e) {}
try {
crypto.timingSafeEqual(uuid, uuid.slice(0, uuid.length - 2));
expect(false).toBe(true);
} catch (e) {
expect(e.message).toBe("Input buffers must have the same length");
}
try {
expect(crypto.timingSafeEqual(uuid, crypto.randomUUID())).toBe(false);
expect(false).toBe(true);
} catch (e) {
expect(e.name).toBe("TypeError");
}
var shorter = uuid.slice(0, 1);
for (let i = 0; i < 9000; i++) {
if (!crypto.timingSafeEqual(shorter, shorter)) throw new Error("fail");
}
});
it("crypto.randomUUID", () => {
var uuid = crypto.randomUUID();
expect(uuid.length).toBe(36);
expect(uuid[8]).toBe("-");
expect(uuid[13]).toBe("-");
expect(uuid[18]).toBe("-");
expect(uuid[23]).toBe("-");
withoutAggressiveGC(() => {
// check that the fast path works
for (let i = 0; i < 9000; i++) {
var uuid2 = crypto.randomUUID();
expect(uuid2.length).toBe(36);
expect(uuid2[8]).toBe("-");
expect(uuid2[13]).toBe("-");
expect(uuid2[18]).toBe("-");
expect(uuid2[23]).toBe("-");
}
});
});
it("URL.prototype.origin", () => {
const url = new URL("https://html.spec.whatwg.org/");
const { origin, host, hostname } = url;
expect(hostname).toBe("html.spec.whatwg.org");
expect(host).toBe("html.spec.whatwg.org");
expect(origin).toBe("https://html.spec.whatwg.org");
});
test("navigator", () => {
expect(globalThis.navigator !== undefined).toBe(true);
const version = process.versions.bun;
const userAgent = `Bun/${version}`;
expect(navigator.hardwareConcurrency > 0).toBe(true);
expect(navigator.userAgent).toBe(userAgent);
});
e='fix-websocket-upgrade'>fix-websocket-upgrade
fs-watch-file
got
guides-3
improve-docker
insensitive-pkg-names
integration-tests
jarred/5859
jarred/actions
jarred/add-git
jarred/analytics
jarred/arenas
jarred/ast
jarred/ast-again
jarred/async_bio
jarred/bench
jarred/brotli
jarred/bump-uws
jarred/bundle-workspace-packages
jarred/bunfig
jarred/callable
jarred/canvas
jarred/ci-check
jarred/cjs2
jarred/cleanup-error
jarred/clipboard-objc
jarred/direct
jarred/dump
jarred/edgecase
jarred/esbuild-plugin-api
jarred/escapeHTML
jarred/esm-conditions
jarred/experiment-bsp
jarred/export-star-flat
jarred/exports-map
jarred/faster-error-capturestacktrace
jarred/faster-ordered-properties
jarred/fastmalloc
jarred/fetch-experiment
jarred/fetchheaders
jarred/fix-blob-slice-test
jarred/fix-bunbun-on-wsl
jarred/fix-crash
jarred/fix-http-compression
jarred/fix-issue-with-tsconfig-run
jarred/fix-proxy-regression
jarred/fixes-3129
jarred/gen
jarred/htmlrewriter
jarred/improve-testing
jarred/inquirer
jarred/isolation
jarred/jsc
jarred/land
jarred/landing
jarred/linux
jarred/live-bindings
jarred/make-strings-better
jarred/mdx-thrwawy
jarred/move
jarred/napi
jarred/new-bund
jarred/new-bund-ressurected-branch
jarred/new-http
jarred/no-more-npm
jarred/package-mapper
jarred/pg
jarred/port
jarred/possibly-2732
jarred/postgresql
jarred/precompile-linux-dependencies
jarred/prepare-for-libuv
jarred/profiled-call
jarred/read-tsconfig-jsx
jarred/redo-evaluation-order
jarred/redo-zigstring-for-utf16
jarred/relay
jarred/rename
jarred/repl
jarred/request-finalizer
jarred/rewrite-router
jarred/run
jarred/simdjson
jarred/simplify
jarred/some-fixes-for-eventsource
jarred/standalone-repro1
jarred/start
jarred/strong
jarred/subprocess
jarred/support-tee
jarred/tcc
jarred/throw-if
jarred/update-install-stuff
jarred/update-zig1
jarred/upgrade-zig-2
jarred/uws
jarred/webkit-upgrade-may-17
jarred/wip-more-reliable
jarred/workers
jarred/zlib
jarred/zls
lithdew/picohttp-mimalloc
main
move-templates
nestjs-guide
next-cleanup
origin/main
plugin/plugindata
plugin/resolvedir
postinstall_3
repl
request-body-stream
reserve-commands
revert-5167-dylan/decode-regex-if-needed
rfc/bun-bundler-api
rfc/bunfig-overhaul
save-in-update
sdl
test/action
types/mock
types/readable-stream-default
types/tty
u/vjpr/zig-0.10
xHyroM/types/expose-Bun-Env
Unnamed repository; edit this file 'description' to name the repository.
Age Commit message (Collapse ) Author Files Lines
fetch errors (#6390)
* fix abort signal and fetch error
* fix fetch error and lock behavior
added commands to install unzip package and to check Linux kernel version
fixed some minor documentation.
The exit code support is between 0-255 and not only in the signed positive range
(0-127).
Node.js does not seam to throw on a bigger integer and just wraps around,
but throwing a error is a good approach and makes the behaviour more defined.
This allows the range to be 0-255
Fixes: https://github.com/oven-sh/bun/issues/6284
* oops
* createSecretKey but weird error
* use the right prototype, do not add a function called export lol
* HMAC JWT export + base64 fix
* Fix Equals, Fix Get KeySize, add complete export RSA
* fix RSA export
* add EC exports
* X25519 and ED25519 export + fixes
* fix default exports
* better asymmetricKeyType
* fix private exports
* fix symmetricKeySize
* createPublicKey validations + refactor
* jwt + der fixes
* oopsies
* add PEM into createPublicKey
* cleanup
* WIP
* bunch of fixes
* public from private + private OKP
* encrypted keys fixes
* oops
* fix clear tls error, add some support to jwk and other formats on publicEncrypt/publicDecrypt
* more fixes and tests working
* more fixes more tests
* more clear hmac errors
* more tests and fixes
* add generateKeyPair
* more tests passing, some skips
* fix EC key from private
* fix OKP JWK
* nodejs ignores ext and key_ops on KeyObject.exports
* add EC sign verify test
* some fixes
* add crypto.generateKeyPairSync(type, options)
* more fixes and more tests
* fix hmac tests
* jsonwebtoken tests
* oops
* oops2
* generated files
* revert package.json
* vm tests
* todos instead of failues
* toBunString -> toString
* undo simdutf
* improvements
* unlikely
* cleanup
* cleanup 2
* oops
* move _generateKeyPairSync checks to native
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Returning undefined simply falls through to the next plugin, or to the default loader.
This is defined by esbuild, and supported by Bun, but the types don't reflect it properly.