I'm trying to run unit tests for an Angular CLI project on a TeamCity build server.
If I use the command:
ng test --single-run --code-coverage
then, as expected, I get a test coverage report but the individual test results don't show up in TeamCity.
If I turn on TeamCity reporting:
ng test --single-run --code-coverage --reporters teamcity
then the tests pass and TeamCity reporting works perfectly, but it silently fails to produce a code coverage report. This behaviour is reproducible on my local machine, so it's nothing to do with how the build server is configured.
Is there any reason why these two options should be mutually exclusive?
Note - this isn't the same problem as Configuring code coverage report for Karma on TeamCity. If the report is there then TeamCity shows it correctly, but if I turn on the TeamCity reporting flag then the coverage folder simply doesn't exist.
Additional info:
Karma configuration:
// Karma configuration file, see link for more information
// https://karma-runner.github.io/0.13/config/configuration-file.html
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular/cli'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular/cli/plugins/karma'),
require('karma-teamcity-reporter')
],
client:{
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
files: [
{ pattern: './src/test.ts', watched: false }
],
preprocessors: {
'./src/test.ts': ['@angular/cli']
},
mime: {
'text/x-typescript': ['ts','tsx']
},
coverageIstanbulReporter: {
reports: [ 'html', 'lcovonly' ],
fixWebpackSourcePaths: true
},
angularCli: {
environment: 'dev'
},
reporters: config.angularCli && config.angularCli.codeCoverage
? ['progress', 'coverage-istanbul']
: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false
});
};
I raised this as an issue on GitHub and the Angular-CLI team pointed out the solution:
ng test --single-run --code-coverage --reporters=teamcity,coverage-istanbul
--code-coverage
option only works if the reporters list includes a coverage tool. If no coverage reporter is present, it fails silently.--reporters
switch replaces the default reporters list, so coverage-istanbul
has to be explicitly re-added.coverage-istanbul
reporter does not produce a report on its own; the --code-coverage
switch is still required.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With