-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(jest-circus): add onTestCaseStart
hook Reporter
#14174
feat(jest-circus): add onTestCaseStart
hook Reporter
#14174
Conversation
…nd transparent approach - clean previous approach - add `test_started` event to Circus runner - fix tests for `test_started` event
✅ Deploy Preview for jestjs ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site settings. |
onTestCaseStart
hook Reporter
@SimenB Would you please take a look at this review? |
Is someone even assigned to this pull request? What's happening? It's Jest's problem, I guess, but at the moment it means jest-circus is unusable in my IDE, and so I'm not using it. |
Oh yeah I know. The two of you are really stepping up here. That was my way of putting pressure on the Jest people. You've been talking to them about the issue for a long time, and they're a pretty significant bottleneck. |
Hey folks! Sorry about the slow answer. I'm currently preparing for a new job, so open source doesn't get much attention atm. Thanks for pinging - anything that helps IDE integration (especially intellij which I use myself 😀) should be prioritized. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
(are you on open js slack? That forum would work better to ping me on than GitHub tags or emails. (If there's some other forum you like prefer, I'd be happy to join. The open ones doesn't really work)) |
Hey @SimenB, Thank you so much 🙏
Have awesome time with new job ✨
Thanks. Nice to hear.
I joined after you mentioned it and I'm interesting to try it.
I don't know of any suitable forum, however I'll think about it. |
I'll release this after landing #14062 (unless it takes a long time). That might be useful for your cases as well? |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
test
orit
via reporter API #13112.onTestCaseStart
hook for Reporter API for giving ability to handle beginning of everytest
orit
via reporter for jest with Jest-Circus Runner.Test plan
Unit tests added
Detailed design
At start, I tried using the current
jest-circus
events to detect when a test case starts by listening to thetest_start
event and calling theonTestCaseStart
hook of theReporter
after it. However, when a test is marked astodo
or skipped for any reason,jest-circus
still dispatches thetest_start
event, followed by thetest_skip
ortest_todo
events, which makes it incorrect to call theonTestCaseStart
hook on thetest_start
event, because the test suite hasn't actually started yet. This behavior forces tools that will handle theonTestCaseStart
hook to filter out the tests that have actually started. Unfortunately, also ontest_start
event we don't have full information about test skipping, because most reasons for skipping a test resolve after the event dispatching.Moving the
test_start
event after thetest_skip
andtest_todo
events could be a solution, but it could also break things, because jest has an internal handler that listens to thetest_start
event and modifies global state. Therefore, I decided not to move thetest_start
event.I investigated other events that are dispatched after the
test_skip
andtest_todo
events and found thehook_start
event dispatching and thetest_fn_start
event dispatching. Calling theonTestCaseStart
hook on thetest_fn_start
event would skip thebefore*
hooks calling phase, which is not suitable for the feature request this PR is solving, because catching output from thebefore*
hooks calling phase is important.Calling the
onTestCaseStart
hook on thehook_start
event also looks incorrect, because thehook_start
event will be avoided for most tests and can be called many times for one test. This requires listening to a combination ofhook_start
andtest_fn_start
events, which makes the solution stateful and less stable.So after all these investigations and discussing with colleagues, I decided to add a new event called
test_started
to thejest-circus
test's run flow, which is dispatched after thetest_skip
andtest_todo
events and before thehook_start
andtest_fn_start
events. This is the best place in the test's running flow to understand when a test case really starts, and connecting theonTestCaseStart
hook of theReporter
to this event is simple and transparent.I found this solution. If you have any other suggestions, you are welcome.