-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Labels
Description
Describe the bug
If a decorator is declared in a separate file, scary warnings are printed when running coverage with istanbul provider. Reported previously as a comment in #7805 (comment).
> [email protected] test
> vitest run --coverage
RUN v3.1.2 F:/Projects/vitest-test
Coverage enabled with istanbul
✓ foo.spec.ts (1 test) 3ms
✓ test 1ms
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Error ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯SyntaxError: F:\Projects\vitest-test\foo.ts: Support for the experimental syntax 'decorators' isn't currently enabled (4:3):
2 |
3 | export class Foo {
> 4 | @MyDecorator()
| ^
5 | bar?: string;
6 | }
7 |
Add @babel/plugin-proposal-decorators (https://github.com/babel/babel/tree/main/packages/babel-plugin-proposal-decorators) to the 'plugins' section of your Babel config to enable transformation.
If you want to leave it as-is, add @babel/plugin-syntax-decorators (https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-decorators) to the 'plugins' section 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=F:\Projects\vitest-test\foo.ts <your build command>
See https://babeljs.io/docs/configuration#print-effective-configs for more info.
2 |
3 | export class Foo {
4 | @MyDecorator()
| ^
5 | bar?: string;
6 | }
Test Files 1 passed (1)
Tests 1 passed (1)
Start at 20:54:42
Duration 840ms
Reproduction
https://github.com/orgads/cov-test/tree/decorator
System Info
System:
OS: Windows 10 10.0.19045
CPU: (8) x64 Intel(R) Core(TM) i7-6700 CPU @ 3.40GHz
Memory: 8.43 GB / 31.89 GB
Binaries:
Node: 22.14.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.22 - C:\ProgramData\npm\yarn.CMD
npm: 10.9.2 - C:\Program Files\nodejs\npm.CMD
pnpm: 10.7.1 - C:\Program Files\nodejs\pnpm.CMD
Browsers:
Chrome: 135.0.7049.114
Edge: Chromium (135.0.3179.54)
Internet Explorer: 11.0.19041.4355
npmPackages:
@vitest/coverage-istanbul: ^3.1.2 => 3.1.2
vitest: ^3.1.2 => 3.1.2Used Package Manager
npm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.