-
-
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
Better error messages #4011
Comments
Technically we can always mark errors with current suite to show it. Especially if error happened outside of test context in the main thread. But what might be even better is to rethrow the error with stack trace in the test thread |
I made a simple example to compare Vitest and Vite https://stackblitz.com/edit/vitest-dev-vitest-z8mdl3?file=src%2Fentry.js There might be a few factor to this issue. For example, Vitest's transform mode (web vs. ssr) affects import analysis and the throw error might depend on that. This is an error when Vitest failed by $ vitest /repro-web
FAIL test/repro-web.test.js [ test/repro-web.test.js ]
Error: Failed to resolve import "not-found" from "src/entry.js". Does the file exist?
❯ TransformPluginContext._formatError node_modules/vite/dist/node/chunks/dep-CDnG8rE7.js:49242:41
❯ TransformPluginContext.error node_modules/vite/dist/node/chunks/dep-CDnG8rE7.js:49237:16
...
$ vitest /repro-ssr
FAIL test/repro-ssr.test.js [ test/repro-ssr.test.js ]
Error: Failed to load url not-found (resolved id: not-found) in /home/projects/vitest-dev-vitest-z8mdl3/src/entry.js. Does the file exist?
❯ loadAndTransform node_modules/vite/dist/node/chunks/dep-CDnG8rE7.js:51907:17 Vite shows a code frame for the same error on terminal and error overlay: $ vite dev
1:24:34 PM [vite] Internal server error: Failed to resolve import "not-found" from "src/entry.js". Does the file exist?
Plugin: vite:import-analysis
File: /home/projects/vitest-dev-vitest-z8mdl3/src/entry.js:2:9
1 | // vite shows frame
2 | import 'not-found';
| ^
3 |
4 | //
at TransformPluginContext._formatError (file:///home/projects/vitest-dev-vitest-z8mdl3/node_modules/vite/dist/node/chunks/dep-CDnG8rE7.js:49242:41)
at TransformPluginContext.error (file:///home/projects/vitest-dev-vitest-z8mdl3/node_modules/vite/dist/node/chunks/dep-CDnG8rE7.js:49237:16)
... Another factor is that, for some resolution error, even Vite is not showing a code frame, so this probably requires a fix on Vite. A following is the error on Vite with the code $ vite dev
1:25:43 PM [vite] Internal server error: Missing "./not-found" specifier in "vite" package
Plugin: vite:import-analysis
File: /home/projects/vitest-dev-vitest-z8mdl3/src/entry.js
at e (file:///home/projects/vitest-dev-vitest-z8mdl3/node_modules/vite/dist/node/chunks/dep-CDnG8rE7.js:46028:25)
at n (file:///home/projects/vitest-dev-vitest-z8mdl3/node_modules/vite/dist/node/chunks/dep-CDnG8rE7.js:46028:627)
at o (file:///home/projects/vitest-dev-vitest-z8mdl3/node_modules/vite/dist/node/chunks/dep-CDnG8rE7.js:46028:1297)
at resolveExportsOrImports (file:///home/projects/vitest-dev-vitest-z8mdl3/node_modules/vite/dist/node/chunks/dep-CDnG8rE7.js:46649:18)
at resolveDeepImport (file:///home/projects/vitest-dev-vitest-z8mdl3/node_modules/vite/dist/node/chunks/dep-CDnG8rE7.js:46672:25) Nonetheless, I'll try to make it work for the case for the first case on web transform mode. |
Clear and concise description of the problem
Currently when an issue arises inside a test the error message receives give no information as to which test failed. So manually having to comment every test one by one until the issue is found is time consuming.
One line of code caused the following:
Very frustrating. At least give the line where the issue arose.
Suggested solution
Tell us which test has the code which is faulty. Preferably the line in the file.
Alternative
No response
Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: