Vitest terminal stops completely (exit code 1) and error message aren't very helpful #1200
ghiscoding
started this conversation in
General
Replies: 1 comment 1 reply
-
I'm on Windows with a Vue 3/CompositionAPI project and every time I make a small error it constantly crashes. Even deleting a or forgetting to close a TypeError: Cannot read properties of undefined (reading 'write')
error Command failed with exit code 1. I'm hopeful that this latest PR #1202 will at least show the full error stack because it's quite annoying that it crashes so easily without error stack. I tried to reproduce in Stackblitz or a small project but unfortunately can't, so there might be something about my project but I'm not sure what |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm a typical Jest user and I recently added Vitest in a Vue 3 installed with Vite and I'm running Vitest in watch mode and currently in the process of adding unit tests, I have some previous unit tests that were written for Jest in Vue 2 and I understand that it could be quite different (also because Vue
test-utils
changed from 1.x to 2.0-rc) but the thing is that writing failing unit tests in Jest that crashes the application isn't very common in Jest but it seems to happen very easily in Vitest and when that happens there are 0 unit tests that are executed and it just exit with code 1 without much help in the error message.The error that I saw from Vitest was
I search for the code
.write
in my entire solution and nothing came up. If I delete the failing spec file, which I have to guess which one it is, then everything is back to normal. Typically I would want Vitest to tell me where this error came from, the current error gives no clue of where it failed and also none of the working unit test even run (again if I do the same in Jest, it would ran all working spec file but only fail with better console error and show me which spec file it originated from).Basically I don't understand why Vitest crashes completely (exiting with code 1) when Jest would not (the only time Jest would actually crash in similar fashion would be if I was running 1 spec file via a filename pattern via the CLI) and second these error message aren't very helpful.
I wish that Vitest could improve their error message and not exit the application that easily (I don't expect 1 spec file to crash the entire Vitest application).
EDIT
So I found out that it happened every time I copied a previous and small spec file which only had 1 unit test inside with a
mount
of a Vue 3 app with Composition API and I also had a Vitest snapshot expectation and I found that if I comment out that expectation then I finally see a proper error and Vitest doesn't crash and exit.simple code crashing Vitest
it just throws the error like it should:
SyntaxError: Need to install with `app.use` function ❯ Module.createCompileError node_modules/@intlify/message-compiler/dist/message-compiler.cjs.js:58:19 ❯ createI18nError node_modules/vue-i18n/dist/vue-i18n.esm-bundler.js:100:11 ... [... rest of the error stack]
and yes that is now much more helpful and a simpe search got me to this SO solution Jest error "SyntaxError: Need to install with
app.use
function" when using vue-i18n plugin for Vue3](https://stackoverflow.com/questions/66348369/jest-error-syntaxerror-need-to-install-with-app-use-function-when-using-vue) and that fixed my original problem... but the thing is, why wasn't this error propagated to the parent unit test? Why did the application crash so badly without showing the error stack? That would have been a lot more helpfulBeta Was this translation helpful? Give feedback.
All reactions