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

Respect Jest flag --noStackTrace #30

Open
isaiahshiner opened this issue Jan 10, 2023 · 2 comments
Open

Respect Jest flag --noStackTrace #30

isaiahshiner opened this issue Jan 10, 2023 · 2 comments

Comments

@isaiahshiner
Copy link

Is it possible for this library to support the --noStackTrace Jest flag out of the box? That is, all console.x should still cause an error, and print expected not to call... but have no stack trace? It looks like this might be possible with a custom error message, but it might make sense for it to work automatically. I also might like to always have no stack traces for fail on console, but that's a stretch goal. I could also consider a PR if you could point me in the right direction.

If it should work and I have something wrong, let me post my exact behavior. Jest is run as a script through pnpm, so my actual command and output looks like this: pnpm jest -- TheTestToRun

TheTestToRun

Expected test not to call console.warn().

If the warn is expected, test for it explicitly by mocking it out using jest.spyOn(console, 'warn') and test that the warning occurs.

Unmatched GET to /logout/expire_if_idle
    at console.newMethod (/Users/.../node_modules/.pnpm/jest-fail-on-console@2.1.1/node_modules/jest-fail-on-console/index.js:20:25)
... continues for ~20 more lines

When using pnpm jest -- --silent --noStackTrace TheTestToRun, I get the exact same output.

@ValentinH
Copy link
Owner

The important thing for this to work automatically is to know if there is a way to detect that this flag was passed. I couldn't find any info about this topic.

Otherwise, not outputting the stack trace doesn't require much change. Here's the place where we output it: https://github.com/ValentinH/jest-fail-on-console/blob/main/index.js#L27

@isaiahshiner
Copy link
Author

Thanks for the quick response! I see that it's not nearly as much code as I was picturing, I'll see if I can get a pull request together, maybe later in the month. I'll also see if I can find out if Jest makes the flag status available anywhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants