Skip to content

No coverage report generated for large project #434

@cklogs

Description

@cklogs

Hi there,

This library is now recommended for code coverage when using v11 of the angular-cli. We are currently using karma-coverage-istanbul-reporter because we have yet to get successful coverage reports with karma-coverage. Seeing, however, that there are deprecation warnings when using the istanbul reporter library with the v11 angular-cli, we would very much like to move off it.

Perhaps someone here can help discern what is wrong with our configuration or point us in the right direction.

I will include the karma.config, and test output debug logs for two different projects.

The first project (PROJECT-1) is a bare project that was initialized with ng new command. It was updated to Angular 11 using the ng update command from angular-cli. The point of including this project is to serve as a 'control' for the second project.

The second project (PROJECT-2) comes from a relatively large production codebase. In this codebase is roughly 5000 unit tests.

Important points

  1. The angular.json test configuration block, tsconfig.spec.ts, and karma.config for both PROJECT-1 and PROJECT-2 are exactly the same. I will post the shared karma.config below.
  2. v11 angular-cli still has memory management issues at build time, similar to those mentioned here. For build/run/test on PROJECT-2 we have to use the --max_old_space_size flag. Note that we are running with latest version of the angular-cli and node v12.x.

PROJECT-1 tests are run with: ng test.
PROJECT-2 tests are run with: node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng test.

  1. When running tests on PROJECT-1, I get consistent coverage reports. I never see coverage reports for PROJECT-2.
  2. The only discernable difference between PROJECT-1 and PROJECT-2 is the --max_old_space_size configuration property mentioned about.

Below is the karma config file shared by the two projects and the debug logs that are output when running tests.

Karma config

// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html

module.exports = function (config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine', '@angular-devkit/build-angular'],
    plugins: [
      require('karma-spec-reporter'),
      require('karma-jasmine'),
      require('karma-chrome-launcher'),
      require('karma-coverage'),
      require('@angular-devkit/build-angular/plugins/karma')
    ],
    client: {
      clearContext: false // leave Jasmine Spec Runner output visible in browser
    },
    coverage: {
      dir: require('path').join(__dirname, '../coverage/karma-coverage'),
      reports: ['html', 'lcovonly', 'text-summary']
    },
    reporters: ['dots', 'spec', 'coverage'],
    specReporter: {
	maxLogLines: 5, // limit number of lines logged per test
	suppressErrorSummary: true, // do not print error summary
	suppressFailed: false, // do not print information about failed tests
	suppressPassed: true, // do not print information about passed tests
	suppressSkipped: true, // do not print information about skipped tests
	showSpecTiming: false, // print the time elapsed for each spec
	failFast: false // test would finish with error when a first fail occurs.
     },
    customLaunchers: {
	'CustomChromeHeadless': {
		base: 'ChromeHeadless',
		flags: [
			'--disable-gpu',
			'--disable-web-security',
			'--no-sandbox',
			'--remote-debugging-port=9222'
		],
		debug: true
	}
    },
	browsers: ['CustomChromeHeadless'],
	browserDisconnectTolerance: 2,
	browserNoActivityTimeout: 300000, // five minutes
	browserDisconnectTimeout: 60000,
	captureTimeout: 300000,
	hostname: '127.0.0.1',
	port: 9876,
	colors: true,
	logLevel: config.LOG_DEBUG,
	autoWatch: false,
	singleRun: true,
	restartOnFileChange: false
  });
};

PROJECT-1-debug-output.txt
PROJECT-2-debug-output.txt

In the PROJECT-2 output you will see only ~20 tests ran. This is because I used an fdescribe to run a single test file so as to reduce the noise a little. The same result--no coverage--happens with or without this change.

The point of failure seems to be here:
image

Thanks in advance for your support.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions