cypress-io / cypress-io/code-coverage
[ViteJS] Empty coverage for all files not covered by tests
- Dominant language
- TypeScript
- Stars
- 445
- Forks
- 115
- PR merge metrics
- No merged PRs in 30d
Description
**Versions**
- What is this plugin's version? 3.9.12
- What is Cypress version? 9.1.0
- What is your operating system? MacOS
- How do you instrument your application? Instanbul
- Is there `.nyc_output` folder? Yes, not empty
- Do you have any custom NYC settings? Yes, `all`
- Do you run Cypress tests in a Docker container? No
**Describe the bug**
Despite using the `all` setting of NYC, it seems like only files touched by tests have their line numbers included in the report.
The other files are present but show 0 lines thus are ignored in the final computation of the code coverage.
Using the debug flag, I see them added:
```
code-coverage adding empty coverage for file /Users/Sytten/Projects/*****/src/main.ts +0ms
code-coverage adding empty coverage for file /Users/Sytten/Projects/*****/src/composables/index.ts +0ms
code-coverage adding empty coverage for file /Users/Sytten/Projects/*****/src/composables/useId.ts +0ms
code-coverage adding empty coverage for file /Users/Sytten/Projects/*****src/composables/useName.ts +0ms
```
But I would expect them to get line numbers at some point. But they only get:
```
TN:
SF:src/main.ts
FNF:0
FNH:0
LF:0
LH:0
BRF:0
BRH:0
end_of_record
```
I use ViteJS and my plugins looks like:
```js
const path = require("path");
const { startDevServer } = require("@cypress/vite-dev-server");
const codeCoverageTask = require("@cypress/code-coverage/task");
const istanbul = require("vite-plugin-istanbul");
module.exports = (on, config) => {
on("dev-server:start", (options) =>
startDevServer({
options,
viteConfig: {
logLevel: "warn",
configFile: path.resolve(__dirname, "..", "..", "vite.config.js"),
plugins: [istanbul({})],
},
})
);
codeCoverageTask(on, config);
return config;
};
```
Support contains:
```js
// Import commands.js using ES2015 syntax:
import "./commands";
// Alternatively you can use CommonJS syntax:
// require('./commands')
import "@cypress/code-coverage/support";
```
The coverage for files under test works fine.
**Link to the repo**
This is not an open-source project, but happy to provide a reproduction if that can help debug it.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.