Search code examples
angularkarma-runnerfreezecobertura

Karma doesn't wait for build to finish before starting to test


After configuring karma to use cobertura and trx it does no longer wait for build to finish before attempting to start testing.

As a result this drowns out any error messages I can get from the build process, which means if I get an error in one of the .spec.ts files i get no feedback as to where it is, I just get chrome timeout after 60s

The changes here are from a standard karma.conf.js generated by angular cli

  config.set({
    basePath: '',
    frameworks: ['jasmine', '@angular-devkit/build-angular'],
    plugins: [
      require('karma-jasmine'),
      require('karma-chrome-launcher'),
      require('karma-jasmine-html-reporter'),
      require('karma-coverage-istanbul-reporter'),
      require('@angular-devkit/build-angular/plugins/karma'),
      require('karma-trx-reporter')
    ],
    client: {
      clearContext: false // leave Jasmine Spec Runner output visible in browser
    },
    coverageReporter: {
      type: 'cobertura'
    },
    remapIstanbulReporter: {
      reports: {
        cobertura: './coverage/cobertura-coverage.xml'
      }
    },
    remapCoverageReporter: {
      cobertura: './coverage/cobertura-coverage.xml'
    },
    coverageIstanbulReporter: {
      dir: require('path').join(__dirname, './coverage'),
      reports: ['html', 'lcovonly', 'text-summary', 'cobertura'],
      fixWebpackSourcePaths: true
    },
    reporters: ['progress', 'kjhtml', 'trx'],
    trxReporter: {
      outputFile: 'dist_test/test-results.trx',
      shortTestName: false,
      nameFormatter: (browser, result) => result.fullName
    },
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome'],
    singleRun: false,
    restartOnFileChange: true
  });
};

I get this in the output when running "ng test"

02 10 2019 18:11:04.309:INFO [karma-server]: Karma v4.0.1 server started at http://0.0.0.0:9876/
02 10 2019 18:11:04.309:INFO [launcher]: Launching browsers Chrome with concurrency unlimited
02 10 2019 18:11:04.315:INFO [launcher]: Starting browser Chrome

the last information is about a .scss file but in this case the problem was a class with the wrong name within a spec.ts file.


Solution

  • You're correct and it appears to be a known bug with an open issue. I know this issue is old but replying here for others who may come along like myself.

    https://github.com/karma-runner/karma-chrome-launcher/issues/154

    People have suggestions, but most of them are around how to get your build to go faster to avoid the issue.