Conversation
✅ Deploy Preview for rstest-dev ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for an onTestFailed hook that executes after a test has failed, providing access to test results and errors for cleanup or logging purposes.
Key changes:
- Introduces
onTestFailedhook API with consistent signature matchingonTestFinished - Updates existing hook signatures to include test result context
- Adds comprehensive documentation and test coverage
Reviewed Changes
Copilot reviewed 10 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
packages/core/src/types/api.ts |
Defines OnTestFailedHandler type and adds hook to RunnerAPI and TestContext |
packages/core/src/types/testSuite.ts |
Updates type signatures for hooks to include test result context |
packages/core/src/runtime/runner/runner.ts |
Implements core logic for onTestFailed hook execution and context binding |
packages/core/src/runtime/runner/runtime.ts |
Initializes onFailed array in test case creation |
packages/core/src/runtime/runner/index.ts |
Exposes onTestFailed in runner API |
packages/core/src/runtime/api/public.ts |
Exports onTestFailed for public API |
e2e/lifecycle/onTestFailed.test.ts |
End-to-end test verifying hook execution on test failure |
e2e/lifecycle/fixtures/onTestFailed.test.ts |
Test fixture demonstrating hook usage |
website/docs/en/api/test-api/hooks.mdx |
English documentation for the new hook |
website/docs/zh/api/test-api/hooks.mdx |
Chinese documentation for the new hook |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| try { | ||
| for (const fn of afterEachFns) { | ||
| await fn(); | ||
| await fn({ task: { result } }); |
There was a problem hiding this comment.
This change breaks backward compatibility for existing afterEach hooks. The original signature was () => MaybePromise<void>, but now it requires a parameter. Existing code that uses afterEach(() => {}) will fail at runtime.
| await fn({ task: { result } }); | |
| if (fn.length === 0) { | |
| await fn(); | |
| } else { | |
| await fn({ task: { result } }); | |
| } |
Summary
onTestFailedhook will be called after the test has failed.Related Links
Checklist