question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
SimenBcommented, Jun 8, 2020

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 to expect, 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 a state (where it keeps number of assertions), but that quickly gets wonky with concurrent tests since expect 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?

3reactions
Bnayacommented, Jun 7, 2020

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

jest-circus | Yarn - Package Manager
Circus allows you to bind to events via an optional event handler on any custom environment. See the type definitions for more information...
Read more >
How do I assert element events using Jest and React Testing ...
I want to ensure correct events are passed into handlers. eg. A Button component passes the entire event object and not just an...
Read more >
Jest-circus NPM
Circus allows you to bind to events via an optional event handler on any custom environment. See the type definitions for more information...
Read more >
Test Properties and Custom Events in Vue.js Components ...
Custom events solve just the opposite, they send data out to the direct parent via an event. They both combined are the wires...
Read more >
How to check the CustomEvent detail in a Jest test for an LWC?
Is there a way capture the detail of the event and assert its value? lightning-web-components · lightning-events · lwc-jest · custom-event.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found