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

Code coverage getting dropped when we combine code coverage from karma unit test case and from cypress integration test case #591

Open
rk011219 opened this issue Oct 3, 2022 · 2 comments

Comments

@rk011219
Copy link

rk011219 commented Oct 3, 2022

Logs and screenshots
I have angular 14 project where I am using karma framework for unit testing and cypress for integration test. I have separate code coverage for karma unit test and cypress integration test and I have combined both code coverage json files but code coverage got dropped after merging. I think code coverage is taking delta of them.

Karma Unit test case coverage:-

karma

Cypress Integration code coverage:-

cypress

Combined Code coverage:-

combine

If you see above reports, I am expecting combine report should show 100 % code coverage for components/sym-ui-sedr-actions because I have covered the component in integration test but it was showing delta. Is there any solution?

Versions

Cypress 10.8.0
"cypress-parallel": "0.9.1",
"@cypress/code-coverage": "3.10.0",
Angular 12.1.3
os : windows 10, linux
Node v12.22.3
npm v6.14.13
application instrumented using istambul and followed below lnk
https://lukas-klement.medium.com/implementing-code-coverage-with-angular-and-cypress-6ed08ed7e617

window.coverage : yes

Is there .nyc_output folder? Is there .nyc_output/out.json file.
-yes
Do you have any custom NYC settings in package.json (nyc object) or in other [NYC config files]
yes
{
"extends": "@istanbuljs/nyc-config-typescript",
"all": true,
"excludeAfterRemap": true,
"reporter": ["html"],
"exclude": [
"./coverage/",
"cypress/",
"./dist/",
"/.spec.ts",
"/projects//test.ts",
"/projects//.js",
"./.js",
"./.config.ts",
"/projects//*.html",
"./src/**"
]
}
Do you run Cypress tests in a Docker container?
NO

Describe the bug
If you see above reports, I am expecting combine report should show 100 % code coverage for components/sym-ui-sedr-actions because I have covered the component in integration test but it was showing delta. Is there any solution?

FYI I am using Istanbul for instrumenting code for karma as well as for cypress

Example
.nycrc.json
{
"extends": "@istanbuljs/nyc-config-typescript",
"all": true,
"excludeAfterRemap": true,
"exclude": [
"./coverage/",
"cypress/
",
"./dist/",
"
/.spec.ts",
"/projects//test.ts",
"/projects//
.js",
"./.js",
"./
.config.ts",
"/projects//*.html",
"./src/**"
]
}

Krama.config.js
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-firefox-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-json-reporter'),
require('karma-coverage'),
require('karma-spec-reporter'),
require('@angular-devkit/build-angular/plugins/karma'),
],
client: {
jasmine: {
random: false,
seed: '4321',
oneFailurePerSpec: true,
failFast: true,
timeoutInterval: 30 * 1000,
},
clearContext: false, // leave Jasmine Spec Runner output visible in browser
},
jasmineHtmlReporter: {
suppressAll: true, // removes the duplicated traces
},
coverageReporter: {
check: {
emitWarning: false,
global: {
statements: 85.42,
branches: 70,
functions: 84.37,
lines: 81.76,
excludes: ['src/**/*.js'],
},
},
dir: require('path').join(__dirname, '../../../coverage/sym-ui/sedr'),
instrumenterOptions: {
istanbul: { noCompact: true },
},
reporters: [{ type: 'html' },{ type: 'json' }, { type: 'text-summary' }],
subdir: '.',
watermarks: {
statements: [60, 85],
functions: [60, 85],
branches: [60, 85],
lines: [60, 85],
},
},
reporters: ['spec', 'progress', 'kjhtml', 'json'],
port: 0,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
// Start these browsers, currently available:
// - ChromeHeadlessNoSandbox
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - IE (only Windows)
browsers: ['ChromeHeadlessNoSandbox'],
customLaunchers: {
ChromeHeadlessNoSandbox: {
base: 'ChromeHeadless',
flags: [
'--disable-web-security',
'--disable-gpu',
'--no-sandbox'
]
},
},
captureTimeout: 100 * 1000,
reportSlowerThan: 5000,
singleRun: false,
restartOnFileChange: true,
browserDisconnectTimeout: 100 * 1000,
browserDisconnectTolerance: 8,
browserNoActivityTimeout: 100 * 1000,
});
};

@Scott-Fischer
Copy link

I'm seeing this as well with combined reports from Jest and Cypress

@maciek-ibm
Copy link

When running only Cypress the coverage i.e. in statements is 86.29% but after merging coverage from Cypress & Jest it drops to 80.17%. Does anyone here know how to fix this?

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

No branches or pull requests

3 participants