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

Repo: handle exceptions that occur while testing a rule better #8942

Open
kirkwaiblinger opened this issue Apr 17, 2024 · 2 comments
Open

Repo: handle exceptions that occur while testing a rule better #8942

kirkwaiblinger opened this issue Apr 17, 2024 · 2 comments
Labels
repo maintenance things to do with maintenance of the repo, and not with code/docs triage Waiting for maintainers to take a look

Comments

@kirkwaiblinger
Copy link
Member

Suggestion

If you throw an exception in a rule (within the RuleListener object handlers, not at the top level of the create() function), the whole test suite fails with an unhelpful error message, rather than failing just the individual test run and printing a useful error message. For instance, here's what happens when I throw an exception in a line affected by just one test case:

 FAIL  tests/rules/no-unnecessary-type-arguments.test.ts
  ● Test suite failed to run

    TypeError: Converting circular structure to JSON
        --> starting at object with constructor 'Object'
        |     property 'params' -> object with constructor 'Array'
        |     index 0 -> object with constructor 'Object'
        --- property 'parent' closes the circle
        at stringify (<anonymous>)

@JoshuaKGoldberg has a hacky workaround. Feel free to share in case that makes it easier to pinpoint the root cause?

@kirkwaiblinger kirkwaiblinger added triage Waiting for maintainers to take a look repo maintenance things to do with maintenance of the repo, and not with code/docs labels Apr 17, 2024
@bradzacher
Copy link
Member

The root causes is jest using worker threads and communicating things across threads.

Specifically when you throw an error in a selector eslint will include the current AST node in the error. The AST is cyclic and thus the error.

@JoshuaKGoldberg
Copy link
Member

Ha, yeah, I saw this recently and got around it hackily by adding to the file mentioned in the error:

      at messageParent (../../node_modules/jest-worker/build/workers/messageParent.js:29:19)
} else if (typeof parentProcess.send === 'function') {
+   console.log(message?.[1]?.[1]);
    parentProcess.send([_types.PARENT_MESSAGE_CUSTOM, message]); 

Is this a bug in Jest? If so, is it resolved by bumping to the latest version? Someone should look into this. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
repo maintenance things to do with maintenance of the repo, and not with code/docs triage Waiting for maintainers to take a look
Projects
None yet
Development

No branches or pull requests

3 participants