oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.05k stars 2.76k forks source link

[bun:test] ALL after* callbacks are not invoked when `--bail`ing #14574

Open mattfysh opened 2 weeks ago

mattfysh commented 2 weeks ago

What version of Bun is running?

1.1.30+7996d06b8

What platform is your computer?

Darwin 23.6.0 arm64 arm

What steps can reproduce the bug?

bunfig.toml

[test]
preload = ["./setup.ts"]

tests/my.test.ts

import { test } from 'bun:test'

test('fails', () => {
  throw new Error('no')
})

setup.ts

import { beforeAll, afterAll } from 'bun:test'

beforeAll(() => {
  console.log('running global setup')
})

afterAll(() => {
  console.log('running global teardown')
})

Run bun test --bail

What is the expected behavior?

the global teardown should be invoked, even if a test case failed

What do you see instead?

the global teardown is not invoked at the end of the test suite

Additional information

No response

mattfysh commented 2 weeks ago

for context - a global teardown might do things like shutting down a server, or clearing state from disk or db

mattfysh commented 1 day ago

workaround right now is to create a shell script, and do the beforeAll/afterAll there

but i've noticed that the afterAll for individual test files is also not invoked, which is considerably more problematic