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

Support import attributes in istanbul coverage #5537

Open
4 tasks done
ghost opened this issue Apr 14, 2024 · 4 comments
Open
4 tasks done

Support import attributes in istanbul coverage #5537

ghost opened this issue Apr 14, 2024 · 4 comments
Labels
feat: coverage Issues and PRs related to the coverage feature pending triage

Comments

@ghost
Copy link

ghost commented Apr 14, 2024

Clear and concise description of the problem + Suggested solution

Written in next message.

Alternative

No response

Additional context

No response

Validations

@hi-ogawa
Copy link
Contributor

The log looks like a babel, but I don't think Vite or Vitest uses babel transform internally. The issue might be in one of your plugins which is running babel.

Can you provide a reproduction?

@ghost
Copy link
Author

ghost commented Apr 16, 2024

Hello @hi-ogawa
Here it is your StackBlitz: https://stackblitz.com/edit/vitest-dev-vitest-rwmclk

Some comments:

  1. I want to use Vitest Browser Mode.
  2. The setup is a Vanilla JavaScript environment, without transpilations.
  3. I wanted to use "@vitest/coverage-v8" instead of "@vitest/coverage-istanbul". However, unfortunately, Vitest Browser Mode requires "@vitest/coverage-istanbul". =/

Error message:

  1. Run the script "test:run". It runs tests in Vitest Browser Mode.
  2. Although the test passes, the console complains with a big error, reproduced after this line. It suggests to install babel, but that is not necessary and not wanted.
00:09:00 [vite] Pre-transform error: /address/file.json: Support for the experimental syntax 'importAttributes' isn't currently enabled (1:61):

Add @babel/plugin-syntax-import-attributes (https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-import-attributes) to the 'plugins' section of your Babel config to enable parsing.

If you already added the plugin for this syntax to your config, it's possible that your config isn't being loaded.
You can re-run Babel with the BABEL_SHOW_CONFIG_FOR environment variable to show the loaded configuration:
npx cross-env BABEL_SHOW_CONFIG_FOR=/address/file.json
See https://babeljs.io/docs/configuration#print-effective-configs for more info.
  1. Vite and Vitest work well with json imports, so I don't see why Vitest Browser Mode should complain about json imports. Although it is a specification in progress, it is native.

I expect this error to be gone. In other words: I expect Vitest Browser Mode to support importing .json files.

@hi-ogawa hi-ogawa added the feat: coverage Issues and PRs related to the coverage feature label Apr 17, 2024
@hi-ogawa hi-ogawa changed the title Support importing json files in browser mode Support import attributes in istanbul coverage Apr 17, 2024
@hi-ogawa
Copy link
Contributor

hi-ogawa commented Apr 17, 2024

Thanks for the reproduction. Yeah, I couldn't find babel anywhere in vite, vitest or vitest browser, but indeed there's one in @vitest/coverage-istanbul.

It looks like a minimal repro is to run @vitest/coverage-istanbul with import/assert/with somewhere in the code. https://github.com/hi-ogawa/reproductions/tree/main/vitest-coverage-babel
https://stackblitz.com/github/hi-ogawa/reproductions/tree/main/vitest-coverage-babel?file=README.md

This could be a bug or probably just an unfortunate limitation, so you might really need to deal with babel yourself.

@AriPerkkio
Copy link
Member

AriPerkkio commented Apr 17, 2024

This is the Istanbul part using Babel that Vitest uses: https://github.com/istanbuljs/istanbuljs/blob/main/packages/istanbul-lib-instrument/src/instrumenter.js

Getting new improvements on Istanbul packages can be really slow - even impossible. Maybe we need to patch istanbul-lib-instrument and bundle it in @vitest/coverage-istanbul.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: coverage Issues and PRs related to the coverage feature pending triage
Projects
None yet
Development

No branches or pull requests

2 participants