Skip to content
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

Add async stack traces for circus #6281

Merged
merged 5 commits into from
May 26, 2018
Merged

Conversation

SimenB
Copy link
Member

@SimenB SimenB commented May 26, 2018

Summary

A first pass at making jest-circus support the same async stack traces that jest-jasmine does. I'm not totally happy with the implementation, so happy to take feedback.

Test plan

See #4362 for instructions on how to run with circus.

Note that jest-circus will still fail the test because of #6277, but all other tests are green

/cc @captbaritone I'm not allowed to assign you

at __tests__/during_tests.test.js:36:3

● returned promise rejection

Failed: Object {
thrown: Object {

This comment was marked as resolved.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stderr.replace(/thrown|Failed/, 'REPLACED');
😛

}
event.test.errors = event.test.errors.map(errors => {
let error;
if (Array.isArray(errors)) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this part is really hairy (even though I removed the react native hack).

Ideas welcome!

Copy link
Contributor

@aaronabramov aaronabramov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😍

at __tests__/during_tests.test.js:36:3

● returned promise rejection

Failed: Object {
thrown: Object {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stderr.replace(/thrown|Failed/, 'REPLACED');
😛

@@ -43,33 +43,42 @@ const handler: EventHandler = (event, state): void => {
}
case 'add_hook': {
const {currentDescribeBlock} = state;
const {fn, hookType: type, timeout} = event;
const {asyncError, fn, hookType: type, timeout} = event;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i was thinking that maybe we can name it somehow differently?
when i see asyncError i assume that it already happened, but in this case we're just capturing it to use in the future?

not in this PR, but maybe something to change in the future

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's just so we can keep the stack across async boundaries

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Open to naming suggestions


const asyncError = new Error();
if (Error.captureStackTrace) {
Error.captureStackTrace(asyncError, test);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is stack captured here but not in the other ones?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly because I'm lazy.

Error.captureStackTrace removes the frame (function) from the second argument, so this in practice removes this function from the stack, meaning users don't get circus in their output.

return error.stack;
} else if (error.message) {
return error.message;
const _formatError = (errors: ?Exception | [?Exception, Exception]): string => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?Exception | {error: Exception, asyncError?: Exception}

?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried this, but I failed horribly... Feel free to fix it if you want, my in progress stuff is here: 8a8d362

@@ -7,12 +7,13 @@
* @flow strict-local
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should probably import the one in jest-jasmine rather than copy it...

@github-actions
Copy link

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.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants