Search code examples
angulartypescriptangular6karma-coverageangular-test

Angular 6 npm run test command failed


I am trying to execute angular test cases but I am getting disconnect error whenever I am executing it.

Currently I have more than 1500 test cases written so might be it is taking time to execute it so is there any way to fix the disconnect error while executing larger amount of test cases.

Following is the error I am getting while executing it.

26 02 2021 10:36:47.160:DEBUG [Chrome 88.0.4324.150 (Linux x86_64)]: Disconnected during run, waiting 910000ms for reconnecting.
26 02 2021 10:36:47.160:DEBUG [Chrome 88.0.4324.150 (Linux x86_64)]: EXECUTING -> EXECUTING_DISCONNECTED
26 02 2021 10:51:57.169:WARN [Chrome 88.0.4324.150 (Linux x86_64)]: Disconnected (0 times)reconnect failed before timeout of 910000ms (ping timeout)
26 02 2021 10:51:57.170:DEBUG [Chrome 88.0.4324.150 (Linux x86_64)]: EXECUTING_DISCONNECTED -> DISCONNECTED

I tried to to increase the wait time but still it didnt worked for me.

following is the command I ran:

ng test --code-coverage --watch=false --browsers=Chrome

And my Karma file config is as follows:

// 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-jasmine'),
      require('karma-chrome-launcher'),
      require('karma-jasmine-html-reporter'),
      require('karma-coverage-istanbul-reporter'),
      require('@angular-devkit/build-angular/plugins/karma'),
    ],
    client: {
      config: {
        browserConsoleLogOptions: true,
      },
      captureConsole: true,
      mocha: {
        bail: true
      },
      clearContext: false // leave Jasmine Spec Runner output visible in browser
    },
    coverageIstanbulReporter: {
      dir: require('path').join(__dirname, '../coverage'),
      reports: ['html', 'lcovonly'],
      fixWebpackSourcePaths: true
    },

    reporters: ['progress', 'kjhtml'],
    // reporters: ['progress', 'mocha', 'coverage'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_DEBUG,
    autoWatch: true,
    browsers: ['Chrome'],
    captureTimeout: 210000,
    browserDisconnectTolerance: 3, 
    browserDisconnectTimeout : 910000,
    browserNoActivityTimeout : 910000,
    singleRun: false
  });
};

SO, Is there any solution to execute more than 1500 test cases in angular application.

Thanks in advance.


Solution

  • Try this.

    Globally install version 6.2.9 of @angular/cli and scaffold a new Angular 6 project. Run npm test on this new scaffolded project and see if it works. If it does, see what it has in karma.conf.js and package.json and the version numbers in package.json. If it doesn't, then I suspect something is wrong with your system.

    Here are the versions of @angular/cli: Angular CLI versions