You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On a Vue 3 + Vite + Vitest project, when an error is thrown from any of my unit tests it goes into the try/catch from the collect.ts file, it tries to use process.stdout.write but on my Windows platform stdout seems to always be undefined and so I never really see my code error but instead I see Vitest error of stdout being undefined. So it's really hard to work from my hand when I can't see the real error. The error thrown from Vitest itself comes from process.stdout.write('\0') from this line
I found a fix that works on Windows and we can simply use console._stdout and that solution is used by WinstonJS in their code base which you can find at this line in which they say the following:
"Node.js maps process.stdout to console._stdout."
with that in mind we can do this quick change:
catch (e) {
//...
// not sure thy, this line is needed to trigger the error
- process.stdout.write('\0')+ if (console._stdout) {+ // Node.js maps `process.stdout` to `console._stdout`.+ console._stdout.write('\0')+ } else {+ process.stdout.write('\0')+ }
}
and voilà, I'm finally able see my own error instead of Vitest internal code complaining about stdout being undefined.
I tried to create a PR with the fix but I'm having problem with pnpm so, can someone apply this fix and create a PR for me? 🙏
Thank you.
Reproduction
The error I'm getting on Windows platform comes from Vitest code itself and throws before it has a chance to show the real error:
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Errors ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Vitest catched 1 unhandled error during the test run. This might cause false positive tests.
Please, resolve all the errors to make sure your tests are not affected.
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Error ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯TypeError: Cannot read properties of undefined (reading 'write')
❯ collectTests node_modules/vitest/dist/vendor-entry.17835032.js:682:22
680| // process.stdout.write("\0");
681| // }
682| process.stdout.write("\0");| ^
683| }
684| calculateHash(file);
❯ async startTests node_modules/vitest/dist/vendor-entry.17835032.js:961:17
❯ async node_modules/vitest/dist/vendor-entry.17835032.js:992:7
❯ async withEnv node_modules/vitest/dist/vendor-entry.17835032.js:529:5
❯ async run node_modules/vitest/dist/vendor-entry.17835032.js:991:5
❯ async ../../../file:/C:/sourcecode/PSX-Selector-greener/node_modules/tinypool/dist/esm/worker.js:96:20
with console._stdout Fix (shown in previous paragraph), I can finally see the real error coming from my code instead of Vites's internal code and that becomes a lot more useful :)
SyntaxError: Unexpected token 'export'
❯ Object.compileFunction ../../../node:vm:352:18
Module C:\sourcecode\PSX-Selector-greener\node_modules\@bundled-es-modules\axios\axios.js:2545 seems to be an ES Module but shipped in a CommonJS package. You might want to create an issue
to the package "C:\sourcecode\PSX-Selector-greener\node_modules\@bundled-es-modules\axios\axios.js:2545" asking them to ship the file in .mjs extension or add "type": "module"in their package.json.
As a temporary workaround you can try to inline the package by updating your config:
// vitest.config.js
export default {
test: {
deps: {
inline: [
"C:\sourcecode\PSX-Selector-greener\node_modules\@bundled-es-modules\axios\axios.js:2545"
]
}
}
}
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[6/7]⎯
Describe the bug
On a Vue 3 + Vite + Vitest project, when an error is thrown from any of my unit tests it goes into the try/catch from the
collect.ts
file, it tries to useprocess.stdout.write
but on my Windows platformstdout
seems to always beundefined
and so I never really see my code error but instead I see Vitest error ofstdout
being undefined. So it's really hard to work from my hand when I can't see the real error. The error thrown from Vitest itself comes fromprocess.stdout.write('\0')
from this linehttps://github.com/vitest-dev/vitest/blob/main/packages/vitest/src/runtime/collect.ts#L58-L65
if I add this line to Vitest codebase, I see it as
undefined
and is most probably a Windows platform specific problemFix
I found a fix that works on Windows and we can simply use
console._stdout
and that solution is used by WinstonJS in their code base which you can find at this line in which they say the following:with that in mind we can do this quick change:
and voilà, I'm finally able see my own error instead of Vitest internal code complaining about
stdout
being undefined.I tried to create a PR with the fix but I'm having problem with pnpm so, can someone apply this fix and create a PR for me? 🙏
Thank you.
Reproduction
The error I'm getting on Windows platform comes from Vitest code itself and throws before it has a chance to show the real error:
with
console._stdout
Fix (shown in previous paragraph), I can finally see the real error coming from my code instead of Vites's internal code and that becomes a lot more useful :)System Info
Used Package Manager
yarn
Validations
The text was updated successfully, but these errors were encountered: