mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
feat(test): implement onTestFinished hook for bun:test (#24038)
## Summary Implements `onTestFinished()` for `bun:test`, which runs after all `afterEach` hooks have completed. ## Implementation - Added `onTestFinished` export to the test module in `jest.zig` - Modified `genericHook` in `bun_test.zig` to handle `onTestFinished` as a special case that: - Can only be called inside a test (not in describe blocks or preload) - Appends hooks at the very end of the execution sequence - Added comprehensive tests covering basic ordering, multiple callbacks, async callbacks, and interaction with other hooks ## Execution Order When called inside a test: 1. Test body executes 2. `afterAll` hooks (if added inside the test) 3. `afterEach` hooks 4. `onTestFinished` hooks ✨ ## Test Plan - ✅ All new tests pass with `bun bd test` - ✅ Tests correctly fail with `USE_SYSTEM_BUN=1` (feature not in released version) - ✅ Verifies correct ordering with `afterEach`, `afterAll`, and multiple `onTestFinished` calls - ✅ Tests async `onTestFinished` callbacks 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude Bot <claude-bot@bun.sh> Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: pfg <pfg@pfg.pw>
This commit is contained in:
@@ -257,12 +257,13 @@ $ bun test --watch
|
||||
|
||||
Bun supports the following lifecycle hooks:
|
||||
|
||||
| Hook | Description |
|
||||
| ------------ | --------------------------- |
|
||||
| `beforeAll` | Runs once before all tests. |
|
||||
| `beforeEach` | Runs before each test. |
|
||||
| `afterEach` | Runs after each test. |
|
||||
| `afterAll` | Runs once after all tests. |
|
||||
| Hook | Description |
|
||||
| ---------------- | -------------------------------------------------------- |
|
||||
| `beforeAll` | Runs once before all tests. |
|
||||
| `beforeEach` | Runs before each test. |
|
||||
| `afterEach` | Runs after each test. |
|
||||
| `afterAll` | Runs once after all tests. |
|
||||
| `onTestFinished` | Runs after a test finishes, including after `afterEach`. |
|
||||
|
||||
These hooks can be defined inside test files, or in a separate file that is preloaded with the `--preload` flag.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user