4

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.

Stevie
  • 157
  • 12
  • I have the same problem and I get an error about not being able to connect to the browser because the build takes longer than the default 60 seconds it's willing to wait for the browser to connect back to karma :( – Ruan Mendes Jul 15 '20 at 15:56
  • Same problem here. Did you find any solutions? – RGe Jan 18 '21 at 08:12
  • unfortunately not, one option was to remove the coverage/reporters sections and run a build. That resulted in getting a build error cause of some recent changes, fixing it and when I would re-add the coverage/reporters sections it would work, but it's far from an ideal solution. – Stevie Jan 19 '21 at 09:09

1 Answers1

2

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.

Neal
  • 58
  • 5