Add after-each test hook for hawk#47
Draft
iethree wants to merge 1 commit into
Draft
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds an optional mb.hawk.hooks/after-each hook that runs after each individual clojure.test var, enabling consumers to run per-test side effects with access to captured output and report context while keeping a no-hook fast path.
Changes:
- Introduces
mb.hawk.hooks/after-eachmultimethod andafter-each-hooks-registered?detection. - Extends the test runner to (optionally) capture per-test output + report events and invoke
after-eachbefore:end-test-varis reported. - Adds comprehensive tests and README documentation for the new per-test hook behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/mb/hawk/hooks.clj |
Adds the after-each hook multimethod and hook-registration detection helper. |
src/mb/hawk/core.clj |
Implements the optional per-test capture + hook invocation path in the test-var runner. |
test/mb/hawk/hooks_test.clj |
Adds tests validating context capture, error attribution, parallel behavior, and the no-hook fast path. |
README.md |
Documents how to register and use after-each per-test hooks and the provided context keys. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+83
to
+85
| If a hook throws (or a `clojure.test` assertion inside it fails), it is reported as a test error/failure attributed | ||
| to the test var -- it will fail the test suite and show up in the JUnit output -- and other after-each hooks for that | ||
| test may not run. Hooks run on the same thread as the test, so for `^:parallel` tests they may run concurrently. |
Comment on lines
+95
to
+99
| dispatch value -- but you should probably make it a namespaced keyword to avoid conflicts, and give it a docstring so | ||
| people know why it's there. The orders the hooks are run in is indeterminate. The docstring for [[after-each]] is | ||
| updated automatically as new hooks are added; you can check it to see which hooks are in use. Note that hooks will | ||
| not be ran unless the namespace they live in is loaded; this may be affected by `:only` options passed to the test | ||
| runner. |
| (try | ||
| (do-with-after-each-hook | ||
| (fn [_options _context] | ||
| ;; clojure.test attributes a report event to the var in (last *testing-vars*); verify it is still set |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds an optional mb.hawk.hooks/after-each hook that runs arbitrary code after each test var, receiving that test's full output and report context, with zero overhead when no hooks are registered.