-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
console.log doens't work when there is an infinite loop after it. #1405
Comments
Yes, this is because logging is delegated to the main process on the last tick of the event loop, but infinite loop prevents us from reaching it. |
is there any way to disable this process when debugging ? |
No |
Even if the logging output isn't available, it seems like the infinite looping should be constrained by the timeout value. So the expected behavior would be that the loop runs for as long as the timeout value allows and then fails. Does this make sense? Would this be something easier to implement? |
We can probably add an option to not intercept
|
I think you can patch https://stackblitz.com/edit/vitest-dev-vitest-aff1ys?file=repro.test.ts import { it, beforeAll } from 'vitest';
beforeAll(async () => {
const { Console } = await import("node:console");
globalThis.console = new Console(process.stdout, process.stderr);
});
it ('repro', () => {
console.log("@@ before-loop");
let i = 0;
while (true) {
console.log("@@ inside-loop", i++);
}
}) One caveat is that (On stackblitz, the terminal gets stuck sometimes, so I also tested locally on my PC and the behavior regarding |
Describe the bug
I noticed that
console.log
doesn't print anything when there's an infinite loop after it. Here is the test:Here is the output after running
yarn run vitest
in the terminalAs you can see,
abc
isn't pointed out.It should print something because sometimes we write infinite loop by accident, and we want to know where the error is.
console.log
gives a way to inspect the reason.Reproduction
https://stackblitz.com/edit/vitest-dev-vitest-mrqmmn?file=test%2Fbasic.test.ts
System Info
Used Package Manager
yarn
Validations
The text was updated successfully, but these errors were encountered: