import {
afterAll,
afterEach,
beforeAll,
beforeEach,
describe,
expect,
it,
} from "bun:test";
describe("test jest hooks in bun-test", () => {
describe("test beforeAll hook", () => {
let animal = "tiger";
beforeAll(() => {
animal = "lion";
});
it("string should be set by hook", () => {
expect(animal).toEqual("lion");
});
});
describe("test beforeEach hook", () => {
let animal = "tiger";
beforeEach(() => {
animal = "lion";
});
it("string should be set by hook", () => {
expect(animal).toEqual("lion");
animal = "dog";
});
it("string should be re-set by hook", () => {
expect(animal).toEqual("lion");
});
});
describe("test afterEach hook", () => {
let animal = "tiger";
afterEach(() => {
animal = "lion";
});
it("string should not be set by hook", () => {
expect(animal).toEqual("tiger");
animal = "dog";
});
it("string should be set by hook", () => {
expect(animal).toEqual("lion");
});
});
describe("test afterAll hook", () => {
let animal = "tiger";
describe("test afterAll hook", () => {
afterAll(() => {
animal = "lion";
});
it("string should not be set by hook", () => {
expect(animal).toEqual("tiger");
animal = "dog";
});
});
it("string should be set by hook", () => {
expect(animal).toEqual("lion");
});
});
describe("test async hooks", async () => {
let beforeAllCalled = 0;
let beforeEachCalled = 0;
let afterAllCalled = 0;
let afterEachCalled = 0;
beforeAll(async () => {
beforeAllCalled += await 1;
});
beforeEach(async () => {
beforeEachCalled += await 1;
});
afterAll(async () => {
afterAllCalled += await 1;
});
afterEach(async () => {
afterEachCalled += await 1;
});
it("should run after beforeAll()", () => {
expect(beforeAllCalled).toBe(1);
expect(beforeEachCalled).toBe(1);
expect(afterAllCalled).toBe(0);
expect(afterEachCalled).toBe(0);
});
it("should run after beforeEach()", () => {
expect(beforeAllCalled).toBe(1);
expect(beforeEachCalled).toBe(2);
expect(afterAllCalled).toBe(0);
expect(afterEachCalled).toBe(1);
});
});
describe("test done callback in hooks", () => {
let beforeAllCalled = 0;
let beforeEachCalled = 0;
let afterAllCalled = 0;
let afterEachCalled = 0;
beforeAll(done => {
setImmediate(() => {
beforeAllCalled++;
done();
});
});
beforeEach(done => {
setImmediate(() => {
beforeEachCalled++;
done();
});
});
afterAll(done => {
setImmediate(() => {
afterAllCalled++;
done();
});
});
afterEach(done => {
setImmediate(() => {
afterEachCalled++;
done();
});
});
it("should run after beforeAll()", () => {
expect(beforeAllCalled).toBe(1);
expect(beforeEachCalled).toBe(1);
expect(afterAllCalled).toBe(0);
expect(afterEachCalled).toBe(0);
});
it("should run after beforeEach()", () => {
expect(beforeAllCalled).toBe(1);
expect(beforeEachCalled).toBe(2);
expect(afterAllCalled).toBe(0);
expect(afterEachCalled).toBe(1);
});
});
describe("test async hooks with done()", () => {
let beforeAllCalled = 0;
let beforeEachCalled = 0;
let afterAllCalled = 0;
let afterEachCalled = 0;
beforeAll(async done => {
beforeAllCalled += await 1;
setTimeout(done, 1);
});
beforeEach(async done => {
beforeEachCalled += await 1;
setTimeout(done, 1);
});
afterAll(async done => {
afterAllCalled += await 1;
setTimeout(done, 1);
});
afterEach(async done => {
afterEachCalled += await 1;
setTimeout(done, 1);
});
it("should run after beforeAll()", () => {
expect(beforeAllCalled).toBe(1);
expect(beforeEachCalled).toBe(1);
expect(afterAllCalled).toBe(0);
expect(afterEachCalled).toBe(0);
});
it("should run after beforeEach()", () => {
expect(beforeAllCalled).toBe(1);
expect(beforeEachCalled).toBe(2);
expect(afterAllCalled).toBe(0);
expect(afterEachCalled).toBe(1);
});
});
});
ndencies'>dylan/github-dependencies
dylan/import-file-path
dylan/non-enumerable-export-values
dylan/resolve-rope-in-string
dylan/set-exit-code
dylan/source-map-names-property
eventstream
feat/ecosystem
feat/npm
fix
fix-prepare-stack-trace
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
* check if key can be printed as an identifier
* possibly escape
We already run the GC automatically whenever heap size grows, so this is mostly unnecessary
In one benchmark, this is an 83% performance improvement at a cost of 9% more memory
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
* Support setting a timezone via `process.env.TZ`
* Implement `setTimeZone` in `bun:jsc` module
* [breaking] `bun:test` now defaults to `Etc/UTC` timezone
---------
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
* fix extra/ArbitraryModuleNamespaceIdentifiers2
* remove assert
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
* start work drafting how builtins will work
* work on ts builtin
* builtins stuff so far
* builtins
* done for today
* continue work
* working on it
* bindings so far
* well, it builds. doesnt run
* IT RUNS
* still lots of ts errors but it is functional
* sloppy mode
cc @paperdave
This changes `publishToSelf` to be `false` by default instead of `true`.
This is a breaking change because it means that `ws.publish("foo", "bar")` will exclude `ws` from the list of websockets to broadcast.
We are making this change because many people asked for this and were confused by the status quo - that `w.publish` publishes to self.
Previously, this defaulted to "uint8array", so this shouldn't be a breaking change unless you make use of `.slice()` in which case it will now be a reference to the same ArrayBuffer rather than a clone.
The rationale for this change is most usages of Uint8Array on the server need a little more than just the bytes. Many npm packages expect Buffer rather than Uint8Array. Directly returning it for binary websocket messages is faster than creating another one.
* Fix memory leak in `fetch(url)`
* Bump those numbers up
---------
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
No performance or memory usage change
Just removing some duplicate code
* WS send with callback
* add opts.compress support
* fmt
* compress is the only option we care
* add ws client options
* only change ws client when using blob
* fmt
* fix errors
* fixup
* fixup
* fmt