cypress-io / cypress-io/code-coverage

start-server-and-test preview 'cypress run --e2e' not outputting expected code coverage when testing against vite preview server

Open
#578 3 comments 3 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
445
Forks
115
PR merge metrics
No merged PRs in 30d

Description

**Debug Logs**

```
code-coverage combined NYC options { 'report-dir': './coverage', reporter: [ 'lcov', 'clover', 'json', 'json-summary' ], extension: [ '.js', '.cjs', '.mjs', '.ts', '.tsx', '.jsx' ], excludeAfterRemap: false } +0ms
code-coverage parsed sent coverage +0ms
code-coverage wrote coverage file /Users/jankordbrett/repos/open-source/vite-vue-cypress-code-coverage-example/.nyc_output/out.json +4ms
code-coverage NYC file /Users/jankordbrett/repos/open-source/vite-vue-cypress-code-coverage-example/.nyc_output/out.json has 13 key(s) +3s
code-coverage 1 key /Users/jankordbrett/repos/open-source/vite-vue-cypress-code-coverage-example/src/components/HelloWorld.vue file path /Users/jankordbrett/repos/open-source/vite-vue-cypress-code-coverage-example/src/components/HelloWorld.vue +0ms
code-coverage 2 key /Users/jankordbrett/repos/open-source/vite-vue-cypress-code-coverage-example/src/App.vue file path /Users/jankordbrett/repos/open-source/vite-vue-cypress-code-coverage-example/src/App.vue +0ms
code-coverage 3 key /Users/jankordbrett/repos/open-source/vite-vue-cypress-code-coverage-example/src/components/WelcomeItem.vue file path /Users/jankordbrett/repos/open-source/vite-vue-cypress-code-coverage-example/src/components/WelcomeItem.vue +0ms
code-coverage in file /Users/jankordbrett/repos/open-source/vite-vue-cypress-code-coverage-example/.nyc_output/out.json all files are not found? false +1ms
code-coverage NYC file /Users/jankordbrett/repos/open-source/vite-vue-cypress-code-coverage-example/.nyc_output/out.json has 13 key(s) +1ms
code-coverage calling NYC reporter with options { 'report-dir': '/Users/jankordbrett/repos/open-source/vite-vue-cypress-code-coverage-example/coverage', reporter: [ 'lcov', 'clover', 'json', 'json-summary' ], extension: [ '.js', '.cjs', '.mjs', '.ts', '.tsx', '.jsx' ], excludeAfterRemap: false, 'temp-dir': '/Users/jankordbrett/repos/open-source/vite-vue-cypress-code-coverage-example/.nyc_output', tempDir: '/Users/jankordbrett/repos/open-source/vite-vue-cypress-code-coverage-example/.nyc_output', reportDir: '/Users/jankordbrett/repos/open-source/vite-vue-cypress-code-coverage-example/coverage' } +27ms
code-coverage current working directory is /Users/jankordbrett/repos/open-source/vite-vue-cypress-code-coverage-example +1ms
code-coverage after reporting, returning the report folder name /Users/jankordbrett/repos/open-source/vite-vue-cypress-code-coverage-example/coverage +160ms
code-coverage Final coverage in /Users/jankordbrett/repos/open-source/vite-vue-cypress-code-coverage-example/coverage/coverage-final.json +1ms
code-coverage There are 2 key(s) in /Users/jankordbrett/repos/open-source/vite-vue-cypress-code-coverage-example/coverage/coverage-final.json +0ms
code-coverage ✅ /Users/jankordbrett/repos/open-source/vite-vue-cypress-code-coverage-example/src/main.js statements covered 4/4 +0ms
code-coverage ⚠️ /Users/jankordbrett/repos/open-source/vite-vue-cypress-code-coverage-example/src/router/index.js statements covered 1/2 +0ms
```

**Versions**

- What is this plugin's version? If this is NOT the latest [released version](https://github.com/cypress-io/code-coverage/releases) can you try the latest version, please?
- 3.10.0
- If the plugin worked before in version X, but stopped after upgrading to version Y, please try the [released versions](https://github.com/cypress-io/code-coverage/releases) between X and Y to see where the breaking change was.
- What is Cypress version?
- 10.0.3
- What is your operating system?
- macOS Monterey v12.4
- What is the shell?
- zsh
- What is the Node version?
- 16.3.1
- What is the NPM version?
- 6.14.4
- How do you instrument your application? Cypress [does not instrument web application code](https://github.com/cypress-io/code-coverage#instrument-your-application), so you need to do it yourself.
- Instrumentation is done via https://github.com/iFaxity/vite-plugin-istanbul. I'm using the following config for the vite-plugin-istanbul:
```
istanbul({
include: 'src/*',
exclude: ['node_modules'],
extension: ['.js', '.ts', '.vue'],
/**
* This allows us to omit the INSTRUMENT_BUILD env variable when running the production build via
* npm run build.
* More details below.
*/
requireEnv: false,
/**
* If forceBuildInstrument is set to true, this will add coverage instrumentation to the
* built dist files and allow the reporter to collect coverage from the (built files).
* However, when forceBuildInstrument is set to true, it will not collect coverage from
* running against the dev server: e.g. npm run dev.
*
* To allow collecting coverage from running cypress against the dev server as well as the
* preview server (built files), we use an env variable, INSTRUMENT_BUILD, to set
* forceBuildInstrument to true when running against the preview server via the
* pretest:dist:e2e npm script.
*
* When you run `npm run build`, the INSTRUMENT_BUILD env variable is omitted from the npm
* script which will result in forceBuildInstrument being set to false, ensuring your
* dist/built files for production do not include coverage instrumentation code.
*/
forceBuildInstrument: Boolean(process.env.INSTRUMENT_BUILD)
}),
```
I use the following npm scripts:
```
"preview": "vite preview --port 4173",
"instrument-build": "INSTRUMENT_BUILD=true vite build",
"test:dist:e2e": "npm run instrument-build && start-server-and-test preview http://127.0.0.1:4173/ 'cypress run --e2e'",
```
- When running tests, if you open the web application in regular browser, and open DevTools, do you see `window.__coverage__` object? Can you paste a screenshot?
- Yes

Screen Shot 2022-06-08 at 7 04 10 PM

- Is there `.nyc_output` folder? Is there `.nyc_output/out.json` file. Is it empty? Can you paste at least part of it so we can see the keys and file paths?
- Yes. Here is partial contents of `.nyc_output/out.json`

Contents

```
{
"/Users/jankordbrett/repos/open-source/vite-vue-cypress-code-coverage-example/src/components/HelloWorld.vue": {
"path": "/Users/jankordbrett/repos/open-source/vite-vue-cypress-code-coverage-example/src/components/HelloWorld.vue",
"statementMap": {
"0": {
"start": {
"line": 3,
"column": 21
},
"end": {
"line": 3,
"column": 81
}
},
"1": {
"start": {
"line": 3,
"column": 27
},
"end": {
"line": 3,
"column": 80
}
},
"2": {
"start": {
"line": 4,
"column": 19
},
"end": {
"line": 4,
"column": 41
}
},
"3": {
"start": {
"line": 5,
"column": 19
},
"end": {
"line": 5,
"column": 37
}
},
"4": {
"start": {
"line": 6,
"column": 33
},
"end": {
"line": 18,
"column": 7
}
},
"5": {
"start": {
"line": 6,
"column": 65
},
"end": {
"line": 18,
"column": 6
}
},
"6": {
"start": {
"line": 21,
"column": 18
},
"end": {
"line": 41,
"column": 1
}
},
"7": {
"start": {
"line": 33,
"column": 0
},
"end": {
"line": 38,
"column": 1
}
},
"8": {
"start": {
"line": 34,
"column": 2
},
"end": {
"line": 37,
"column": 5
}
}
},
"fnMap": {
"0": {
"name": "(anonymous_0)",
"decl": {
"start": {
"line": 3,
"column": 21
},
"end": {
"line": 3,
"column": 22
}
},
"loc": {
"start": {
"line": 3,
"column": 27
},
"end": {
"line": 3,
"column": 80
}
},
"line": 3
},
"1": {
"name": "(anonymous_1)",
"decl": {
"start": {
"line": 6,
"column": 46
},
"end": {
"line": 6,
"column": 47
}
},
"loc": {
"start": {
"line": 6,
"column": 65
},
"end": {
"line": 18,
"column": 6
}
},
"line": 6
},
"2": {
"name": "(anonymous_2)",
"decl": {
"start": {
"line": 29,
"column": 2
},
"end": {
"line": 29,
"column": 3
}
},
"loc": {
"start": {
"line": 29,
"column": 17
},
"end": {
"line": 39,
"column": 1
}
},
"line": 29
},
"3": {
"name": "(anonymous_3)",
"decl": {
"start": {
"line": 33,
"column": 7
},
"end": {
"line": 33,
"column": 8
}
},
"loc": {
"start": {
"line": 33,
"column": 25
},
"end": {
"line": 38,
"column": 1
}
},
"line": 33
}
},
"branchMap": {},
"s": {
"0": 1,
"1": 1,
"2": 1,
"3": 1,
"4": 1,
"5": 1,
"6": 1,
"7": 1,
"8": 1
},
"f": {
"0": 1,
"1": 1,
"2": 1,
"3": 1
},
"b": {},
"inputSourceMap": {
"version": 3,
"file": null,
"sources": [
"/Users/jankordbrett/repos/open-source/vite-vue-cypress-code-coverage-example/src/components/HelloWorld.vue"
],
"names": [],
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAc;AAMZ;;;;;;;;;;"
},
"_coverageSchema": "1a1c01bbd47fc00a2c39e90264f33305004495a9",
"hash": "f710a38f152bbed0d4b1e1ff74ea0cca9668c0fa"
},
"/Users/jankordbrett/repos/open-source/vite-vue-cypress-code-coverage-example/src/App.vue": {
"path": "/Users/jankordbrett/repos/open-source/vite-vue-cypress-code-coverage-example/src/App.vue",
"statementMap": {
"0": {
"start": {
"line": 5,
"column": 32
},
"end": {
"line": 11,
"column": 12
}
},
"1": {
"start": {
"line": 12,
"column": 19
},
"end": {
"line": 12,
"column": 39
}
},
"2": {
"start": {
"line": 13,
"column": 32
},
"end": {
"line": 13,
"column": 56
}
},
"3": {
"start": {
"line": 14,
"column": 32
},
"end": {
"line": 14,
"column": 57
}
},
"4": {
"start": {
"line": 19,
"column": 18
},
"end": {
"line": 51,
"column": 1
}
},
"5": {
"start": {
"line": 24,
"column": 0
},
"end": {
"line": 48,
"column": 1
}
},
"6": {
"start": {
"line": 25,
"column": 2
},
"end": {
"line": 47,
"column": 9
}
},
"7": {
"start": {
"line": 32,
"column": 36
},
"end": {
"line": 34,
"column": 13
}
},
"8": {
"start": {
"line": 38,
"column": 36
},
"end": {
"line": 40,
"column": 13
}
}
},
"fnMap": {
"0": {
"name": "(anonymous_0)",
"decl": {
"start": {
"line": 21,
"column": 2
},
"end": {
"line": 21,
"column": 3
}
},
"loc": {
"start": {
"line": 21,
"column": 17
},
"end": {
"line": 49,
"column": 1
}
},
"line": 21
},
"1": {
"name": "(anonymous_1)",
"decl": {
"start": {
"line": 24,
"column": 7
},
"end": {
"line": 24,
"column": 8
}
},
"loc": {
"start": {
"line": 24,
"column": 25
},
"end": {
"line": 48,
"column": 1
}
},
"line": 24
},
"2": {
"name": "(anonymous_2)",
"decl": {
"start": {
"line": 32,
"column": 30
},
"end": {
"line": 32,
"column": 31
}
},
"loc": {
"start": {
"line": 32,
"column": 36
},
"end": {
"line": 34,
"column": 13
}
},
"line": 32
},
"3": {
"name": "(anonymous_3)",
"decl": {
"start": {
"line": 38,
"column": 30
},
"end": {
"line": 38,
"column": 31
}
},
"loc": {
"start": {
"line": 38,
"column": 36
},
"end": {
"line": 40,
"column": 13
}
},
"line": 38
}
},
"branchMap": {},
"s": {
"0": 1,
"1": 1,
"2": 1,
"3": 1,
"4": 1,
"5": 1,
"6": 1,
"7": 2,
"8": 2
},
"f": {
"0": 1,
"1": 1,
"2": 2,
"3": 2
},
"b": {},
"inputSourceMap": {
"version": 3,
"file": null,
"sources": [
"/Users/jankordbrett/repos/open-source/vite-vue-cypress-code-coverage-example/src/App.vue"
],
"names": [],
"mappings": ";;;;;;;;;;;;;;;AACA,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACnD,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;;;;;AAFtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"
},
"_coverageSchema": "1a1c01bbd47fc00a2c39e90264f33305004495a9",
"hash": "0b4cf991df8ac6ed045ee01fa94c5627575a0eb3"
},
"/Users/jankordbrett/repos/open-source/vite-vue-cypress-code-coverage-example/src/router/index.js": {
"path": "/Users/jankordbrett/repos/open-source/vite-vue-cypress-code-coverage-example/src/router/index.js",
"statementMap": {
"0": {
"start": {
"line": 4,
"column": 15
},
"end": {
"line": 21,
"column": 2
}
},
"1": {
"start": {
"line": 18,
"column": 23
},
"end": {
"line": 18,
"column": 55
}
}
},
"fnMap": {
"0": {
"name": "(anonymous_0)",
"decl": {
"start": {
"line": 18,
"column": 17
},
"end": {
"line": 18,
"column": 18
}
},
"loc": {
"start": {
"line": 18,
"column": 23
},
"end": {
"line": 18,
"column": 55
}
},
"line": 18
}
},
"branchMap": {},
"s": {
"0": 1,
"1": 0
},
"f": {
"0": 0
},
"b": {},
"inputSourceMap": {
"version": 3,
"file": null,
"sources": [
"/Users/jankordbrett/repos/open-source/vite-vue-cypress-code-coverage-example/src/router/index.js"
],
"names": [],
"mappings": "AAAA,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC3D,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC5C;AACA,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC7B,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CA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264f33305004495a9",
"hash": "560bf5840da55511c282ef9773b61bdc32ad2097"
},
"/Users/jankordbrett/repos/open-source/vite-vue-cypress-code-coverage-example/src/main.js": {
"path": "/Users/jankordbrett/repos/open-source/vite-vue-cypress-code-coverage-example/src/main.js",
"statementMap": {
"0": {
"start": {
"line": 7,
"column": 12
},
"end": {
"line": 7,
"column": 26
}
},
"1": {
"start": {
"line": 9,
"column": 0
},
"end": {
"line": 9,
"column": 22
}
},
"2": {
"start": {
"line": 10,
"column": 0
},
"end": {
"line": 10,
"column": 15
}
},
"3": {
"start": {
"line": 12,
"column": 0
},
"end": {
"line": 12,
"column": 17
}
}
},
"fnMap": {},
"branchMap": {},
"s": {
"0": 1,
"1": 1,
"2": 1,
"3": 1
},
"f": {},
"b": {},
"inputSourceMap": {
"version": 3,
"file": null,
"sources": [
"/Users/jankordbrett/repos/open-source/vite-vue-cypress-code-coverage-example/src/main.js"
],
"names": [],
"mappings": "AAAA,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC/B,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACnC;AACA,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC3B,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC7B;AACA,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC1B;AACA,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACtB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACf;AACA,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;"
},
"_coverageSchema": "1a1c01bbd47fc00a2c39e90264f33305004495a9",
"hash": "538bc94b495e51823e3d624a823d5d6308c17cce"
},
}
```

You can view the full contents here:
https://github.com/bjankord/vite-vue-cypress-code-coverage-example/blob/main/.nyc_output/out.json

- Do you have any custom NYC settings in `package.json` (`nyc` object) or in other [NYC config files](https://github.com/istanbuljs/nyc#configuration-files)
- No, none that I'm aware of
- Do you run Cypress tests in a Docker container?
- No

**Describe the bug**
When instrumenting my [Vite + Vue project](https://github.com/bjankord/vite-vue-cypress-code-coverage-example) with https://github.com/iFaxity/vite-plugin-istanbul and running `start-server-and-test preview 'cypress run --e2e' ` I'd expect to see coverage reports for the following files:
* src/App.vue
* src/main.js
* src/components/HelloWorld.vue
* src/components/TheWelcome.vue
* src/components/WelcomeItem.vue
* src/components/icons/IconCommunity.vue
* src/components/icons/IconDocumentation.vue
* src/components/icons/IconEcosystem.vue
* src/components/icons/IconSupport.vue
* src/components/icons/IconTooling.vue
* src/router/index.js

What I actually see is coverage reports for the following files:
* src/main.js
* src/router/index.js

If I instead run the vite dev server instead of the preview server and then run `cypress run --e2e` in a separate terminal window, I am able to get coverage reports for the following files:
* src/App.vue
* src/main.js
* src/components/HelloWorld.vue
* src/components/TheWelcome.vue
* src/components/WelcomeItem.vue
* src/components/icons/IconCommunity.vue
* src/components/icons/IconDocumentation.vue
* src/components/icons/IconEcosystem.vue
* src/components/icons/IconSupport.vue
* src/components/icons/IconTooling.vue
* src/router/index.js

I believe this issue may span across [@cypress/code-coverage](https://github.com/cypress-io/code-coverage) and [vite](https://github.com/vitejs/vite) and may be more on the vite side with how it bundles JS for the preview server but I'd figured I'd post here incase anyone was able to help debug.

My original thought was that `vite build` was code splitting the JS files causing the code coverage report to not show all the files that I'd expect.

I've tried adding the following to my `vite.config.js` file to generate just 1 JS file:
```
build: {
sourcemap: true,
rollupOptions: {
output: {
manualChunks: () => 'bundle',
},
},
},
```
And while that does output just 1 index JS file, the coverage report did not change, I still see reports only for the following files when running the `test:dist:e2e` npm script in my example repo.
* src/main.js
* src/router/index.js

I see in my there are 13 keys matching the files I'd expect to see coverage reports in `.nyc_out/out.json`, but there are only 2 keys in `coverage/coverage-final.json`, the 2 files that actually get a coverage report. I'm unsure what causes this difference though.

**Link to the repo**
https://github.com/bjankord/vite-vue-cypress-code-coverage-example

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.