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

fix(vitest): show rollup error details as test error #6686

Merged

Conversation

hi-ogawa
Copy link
Contributor

@hi-ogawa hi-ogawa commented Oct 11, 2024

Description

fixture test run
  • environment: happy-dom
$ pnpm -C test/config test -- --root fixtures/rollup-error --environment happy-dom

> @vitest/test-config@ test /home/hiroshi/code/others/vitest/test/config
> vitest --typecheck.enabled "--root" "fixtures/rollup-error" "--environment" "happy-dom"

Testing types with tsc and vue-tsc is an experimental feature.
Breaking changes might not follow SemVer, please pin Vitest's version when using it.

 DEV  v2.1.2 /home/hiroshi/code/others/vitest/test/config/fixtures/rollup-error

 ❯ not-found-export.test.ts (0)
 ❯ not-found-package.test.ts (0)

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Suites 2 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

 FAIL  not-found-export.test.ts [ not-found-export.test.ts ]
Error: Missing "./no-such-export" specifier in "vite" package
  Plugin: vite:import-analysis
  File: /home/hiroshi/code/others/vitest/test/config/fixtures/rollup-error/not-found-export.test.ts
 ❯ e ../../../../node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/vite/dist/node/chunks/dep-NjL7WTE1.js:45942:25
 ❯ n ../../../../node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/vite/dist/node/chunks/dep-NjL7WTE1.js:45942:627
 ❯ o ../../../../node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/vite/dist/node/chunks/dep-NjL7WTE1.js:45942:1297
 ❯ resolveExportsOrImports ../../../../node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/vite/dist/node/chunks/dep-NjL7WTE1.js:46563:18
 ❯ resolveDeepImport ../../../../node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/vite/dist/node/chunks/dep-NjL7WTE1.js:46586:25
 ❯ tryNodeResolve ../../../../node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/vite/dist/node/chunks/dep-NjL7WTE1.js:46351:16
 ❯ ResolveIdContext.resolveId ../../../../node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/vite/dist/node/chunks/dep-NjL7WTE1.js:46101:19
 ❯ PluginContainer.resolveId ../../../../node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/vite/dist/node/chunks/dep-NjL7WTE1.js:48893:17
 ❯ TransformPluginContext.resolve ../../../../node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/vite/dist/node/chunks/dep-NjL7WTE1.js:49053:15

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/2]⎯

 FAIL  not-found-package.test.ts [ not-found-package.test.ts ]
Error: Failed to resolve import "@vitejs/no-such-package" from "fixtures/rollup-error/not-found-package.test.ts". Does the file exist?
  Plugin: vite:import-analysis
  File: /home/hiroshi/code/others/vitest/test/config/fixtures/rollup-error/not-found-package.test.ts:1:7
  1  |  import "@vitejs/no-such-package";
     |          ^
  2  |  
 ❯ TransformPluginContext._formatError ../../../../node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/vite/dist/node/chunks/dep-NjL7WTE1.js:49133:41
 ❯ TransformPluginContext.error ../../../../node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/vite/dist/node/chunks/dep-NjL7WTE1.js:49128:16
 ❯ normalizeUrl ../../../../node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/vite/dist/node/chunks/dep-NjL7WTE1.js:63910:23
 ❯ ../../../../node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/vite/dist/node/chunks/dep-NjL7WTE1.js:64042:39
 ❯ TransformPluginContext.transform ../../../../node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/vite/dist/node/chunks/dep-NjL7WTE1.js:63969:7
 ❯ PluginContainer.transform ../../../../node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/vite/dist/node/chunks/dep-NjL7WTE1.js:48974:18
 ❯ loadAndTransform ../../../../node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/vite/dist/node/chunks/dep-NjL7WTE1.js:51796:27

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[2/2]⎯

 Test Files  2 failed (2)
      Tests  no tests
Type Errors  no errors
   Start at  15:52:03
   Duration  274ms (transform 9ms, setup 0ms, collect 0ms, tests 0ms, environment 269ms, prepare 79ms)


 FAIL  Tests failed. Watching for file changes...
       press h to show help, press q to quit
Cancelling test run. Press CTRL+c again to exit forcefully.
  • environment: node
$ pnpm -C test/config test -- --root fixtures/rollup-error --environment node

> @vitest/test-config@ test /home/hiroshi/code/others/vitest/test/config
> vitest --typecheck.enabled "--root" "fixtures/rollup-error" "--environment" "node"

Testing types with tsc and vue-tsc is an experimental feature.
Breaking changes might not follow SemVer, please pin Vitest's version when using it.

 DEV  v2.1.2 /home/hiroshi/code/others/vitest/test/config/fixtures/rollup-error

 ❯ not-found-export.test.ts (0)
 ❯ not-found-package.test.ts (0)

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Suites 2 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

 FAIL  not-found-export.test.ts [ not-found-export.test.ts ]
Error: Missing "./no-such-export" specifier in "vite" package
  Plugin: vite:import-analysis
  File: /home/hiroshi/code/others/vitest/test/config/fixtures/rollup-error/not-found-export.test.ts
 ❯ e ../../../../node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/vite/dist/node/chunks/dep-NjL7WTE1.js:45942:25
 ❯ n ../../../../node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/vite/dist/node/chunks/dep-NjL7WTE1.js:45942:627
 ❯ o ../../../../node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/vite/dist/node/chunks/dep-NjL7WTE1.js:45942:1297
 ❯ resolveExportsOrImports ../../../../node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/vite/dist/node/chunks/dep-NjL7WTE1.js:46563:18
 ❯ resolveDeepImport ../../../../node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/vite/dist/node/chunks/dep-NjL7WTE1.js:46586:25
 ❯ tryNodeResolve ../../../../node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/vite/dist/node/chunks/dep-NjL7WTE1.js:46351:16
 ❯ ResolveIdContext.resolveId ../../../../node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/vite/dist/node/chunks/dep-NjL7WTE1.js:46101:19
 ❯ PluginContainer.resolveId ../../../../node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/vite/dist/node/chunks/dep-NjL7WTE1.js:48893:17
 ❯ TransformPluginContext.resolve ../../../../node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/vite/dist/node/chunks/dep-NjL7WTE1.js:49053:15

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/2]⎯

 FAIL  not-found-package.test.ts [ not-found-package.test.ts ]
Error: Failed to load url @vitejs/no-such-package (resolved id: @vitejs/no-such-package) in /home/hiroshi/code/others/vitest/test/config/fixtures/rollup-error/not-found-package.test.ts. Does the file exist?
 ❯ loadAndTransform ../../../../node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/vite/dist/node/chunks/dep-NjL7WTE1.js:51787:17

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[2/2]⎯

 Test Files  2 failed (2)
      Tests  no tests
Type Errors  no errors
   Start at  15:52:56
   Duration  142ms (transform 23ms, setup 0ms, collect 0ms, tests 0ms, environment 0ms, prepare 76ms)


 FAIL  Tests failed. Watching for file changes...
       press h to show help, press q to quit
Cancelling test run. Press CTRL+c again to exit forcefully.

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

Copy link

netlify bot commented Oct 11, 2024

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 201121b
🔍 Latest deploy log https://app.netlify.com/sites/vitest-dev/deploys/6708c2f1aefca8000826c116
😎 Deploy Preview https://deploy-preview-6686--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@hi-ogawa hi-ogawa marked this pull request as ready for review October 11, 2024 07:17
@sheremet-va
Copy link
Member

There is only a stack frame for @vitejs/no-such-package. Is this intended?

@hi-ogawa
Copy link
Contributor Author

Yes, that's intended for now. Vite doesn't show code frame either for the error Error: Missing "./no-such-export" specifier in "vite" package as I wrote in #4011 (comment).

From what I can guess, this error is thrown byresolve.exports https://github.com/lukeed/resolve.exports. Vite adds pos info to this.error("Failed to resolve import ...", pos), but this is only when this.resolve(...) gracefully returned undefined. https://github.com/vitejs/vite/blob/4c5cf91d124d423fe028beecda952125698c1d5d/packages/vite/src/node/plugins/importAnalysis.ts#L361-L366

We can probably improve this on Vite by wrapping try/catch, so I'll plan to test that later. If we can fix this on Vite, then that should be automatically available on Vitest too with the same logic here.

@sheremet-va
Copy link
Member

We can probably improve this on Vite by wrapping try/catch, so I'll plan to test that later.

Good idea! We can merge this for now then 👍🏻

@sheremet-va sheremet-va merged commit 47dde76 into vitest-dev:main Oct 11, 2024
16 of 17 checks passed
@sheremet-va
Copy link
Member

Would also be nice to find a way to show the code frame for environment: node

@hi-ogawa hi-ogawa deleted the fix-preserve-rollup-error-metadata branch October 12, 2024 05:50
renovate bot added a commit to mmkal/eslint-plugin-mmkal that referenced this pull request Oct 14, 2024
##### [v2.1.3](https://github.com/vitest-dev/vitest/releases/tag/v2.1.3)

#####    🐞 Bug Fixes

-   Fix error diff of `toBeNaN, toBeUndefined, toBeNull, toBeTruthy, toBeFalsy`  -  by [@hi-ogawa](https://github.com/hi-ogawa) in vitest-dev/vitest#6697 [<samp>(e0027)</samp>](vitest-dev/vitest@e002758c)
-   **browser**:
    -   Provide aria role intellisense  -  by [@sheremet-va](https://github.com/sheremet-va) in vitest-dev/vitest#6629 [<samp>(f36ea)</samp>](vitest-dev/vitest@f36eac77)
    -   Not.toBeInTheDocument works with locators API  -  by [@sheremet-va](https://github.com/sheremet-va) in vitest-dev/vitest#6634 [<samp>(8bef5)</samp>](vitest-dev/vitest@8bef5d2b)
    -   Use `/mockServiceWorker.js` instead of `/__vitest_msw__`  -  by [@sheremet-va](https://github.com/sheremet-va) in vitest-dev/vitest#6687 [<samp>(4b2ce)</samp>](vitest-dev/vitest@4b2ce07f)
    -   Don't override the esbuild option in the browser mode  -  by [@sheremet-va](https://github.com/sheremet-va) in vitest-dev/vitest#6692 [<samp>(d131f)</samp>](vitest-dev/vitest@d131fd64)
-   **expect**:
    -   Preserve prototype in `toMatchObject` diff  -  by [@hi-ogawa](https://github.com/hi-ogawa) in vitest-dev/vitest#6620 [<samp>(d289e)</samp>](vitest-dev/vitest@d289e7eb)
-   **mocker**:
    -   Specify correct spy dependency  -  by [@sheremet-va](https://github.com/sheremet-va) [<samp>(7e958)</samp>](vitest-dev/vitest@7e9584aa)
-   **runner**:
    -   Ensure sequential suite overrides sequence.concurrent  -  by [@dsyddall](https://github.com/dsyddall) and [@hi-ogawa](https://github.com/hi-ogawa) in vitest-dev/vitest#6653 [<samp>(5e6de)</samp>](vitest-dev/vitest@5e6de274)
-   **vitest**:
    -   Deprecate UserConfig in favor of ViteUserConfig  -  by [@sheremet-va](https://github.com/sheremet-va) in vitest-dev/vitest#6626 [<samp>(496bd)</samp>](vitest-dev/vitest@496bd251)
    -   Don't hang with maxConcurrency 0  -  by [@sheremet-va](https://github.com/sheremet-va) in vitest-dev/vitest#6627 [<samp>(946d8)</samp>](vitest-dev/vitest@946d8bb1)
    -   Deprecate old task types and node-reliant types  -  by [@sheremet-va](https://github.com/sheremet-va) in vitest-dev/vitest#6632 [<samp>(00045)</samp>](vitest-dev/vitest@000459a9)
    -   Fix `<empty line>` logs when interleaving `console.log/error`  -  by [@hi-ogawa](https://github.com/hi-ogawa) in vitest-dev/vitest#6644 [<samp>(9ece3)</samp>](vitest-dev/vitest@9ece3952)
    -   Show rollup error details as test error  -  by [@hi-ogawa](https://github.com/hi-ogawa) in vitest-dev/vitest#6686 [<samp>(47dde)</samp>](vitest-dev/vitest@47dde76f)
    -   Always inline setup files  -  by [@sheremet-va](https://github.com/sheremet-va) in vitest-dev/vitest#6689 [<samp>(19d64)</samp>](vitest-dev/vitest@19d64e20)
    -   Use `fast-glob` instead of `tinyglobby` in Vitest  -  by [@sheremet-va](https://github.com/sheremet-va) in vitest-dev/vitest#6688 [<samp>(70baa)</samp>](vitest-dev/vitest@70baaaa9)
-   **web-worker**:
    -   Share mocker with main executor  -  by [@hi-ogawa](https://github.com/hi-ogawa) in vitest-dev/vitest#6623 [<samp>(fe7b8)</samp>](vitest-dev/vitest@fe7b8aee)

#####    🏎 Performance

-   Reuse full name in reported tasks, update generator types  -  by [@sheremet-va](https://github.com/sheremet-va) in vitest-dev/vitest#6666 [<samp>(7a0de)</samp>](vitest-dev/vitest@7a0de0a7)

#####     [View changes on GitHub](vitest-dev/vitest@v2.1.2...v2.1.3)
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

Successfully merging this pull request may close these issues.

Better error messages
2 participants