[Feature Proposal][circus] Add assertion events to jest-circus or event custom events
See original GitHub issue🚀 Feature Proposal
Add assertion events to jest circus, and expose api for custom assertion libraries to emit events as-well
Motivation
Jest circus events provide valuable info during test execution. I believe that adding events for assertions will give even a better picture of what’s going on during the event execution. My personal motivation is that I’m writing a tool that extends jest to show additional information on test runs & during test runs, and to be able to also show successful assertions. Without standard way from jest side, I would have to wrap the assertion library myself.
That can be helpful to various tools, And maybe even solve things like: https://github.com/facebook/jest/issues/6295#issuecomment-578438566
Example
I don’t have something very solid in mind, but if we take a look at:
Very crud dump of jest circus events during test run:
setup
add_hook
start_describe_definition hey
add_test yo
add_test oops
finish_describe_definition hey
run_start
run_describe_start
run_describe_start
test_start yo
hook_start
hook_success yo
test_fn_start yo
test_fn_success yo
test_done yo
test_start oops
hook_start
hook_success oops
test_fn_start oops
test_fn_failure oops
test_done oops
run_describe_finish
run_describe_finish
run_finish
teardown
The events i’m thinking about are (They must be sync, the return promise api is not applicable here unfortunately):
assertion_start
assertion_failure / assertion_success
assertion_end
With additional metadata that would make sense there
Pitch
I think the power of jest-circus is the best pitch 😃 Exposing more information as events from the test runs and even custom events, will give more power to external tools without the need to to integrate with the core directly, monkey patch or wrap things etc
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:12 (3 by maintainers)
Top GitHub Comments
While some sort of hook for adding custom events might make sense at some point, I think assertions are such an integral part of test runners that
assertion
events makes sense as a first-class feature of Circus. While I don’t think we should couple Circus directly toexpect
, creating some sort of binding that allows expect to emit those events to circus which can then decorate and re-emit them sounds good to me. If you’ve used Cypress it lists out every single assertion made, and I think it’s a valuable feature. I think this ties nicely into #6616 (although that’s scoped to tests and not assertions) & #8840.Not sure how to best make
expect
emit events and such. It already has astate
(where it keeps number of assertions), but that quickly gets wonky with concurrent tests sinceexpect
is not bound to a specific test making it hard (if not impossible) to know which test is currently running. I think that would be an issue here as well. Concurrent tests is experimental and not documented though, so maybe not a huge deal? That state could possibly keep an event emitter instance (not that since it needs to work in the browser, but conceptually) or some such?Sorry for diverging from the main topic, but: What do you think about adding api to add opaque data to reporting, So custom reporters can read on the other side?
(In a separate proposal & PR)
Both the events api & report api may be exposed to the jest environment, or even the test itself