DEV Community

Arup Karan
Arup Karan

Posted on

How to fix-Chrome Headless 115.0.5790.110 (Windows 10) ERROR Disconnected, because no message in 10000 ms of karma unit testing?

We have a project with Angular15 and used Jasmine and Karma for uniting.
While we executing the test case we are getting the error as per the image below. Some time its run properly but maximum time showing the error. We have not found any solution for this problem.

Has anyone else come across this and possibly found a solution?

Image description

Our karma.conf.js :

module.exports = function (config) {
  config.set({
    basePath: '',
    frameworks: ['parallel', 'jasmine', '@angular-devkit/build-angular'],
    plugins: [
      require('karma-parallel'),
      require('karma-jasmine'),
      require('karma-chrome-launcher'),
      require('karma-coverage'),
      require('@angular-devkit/build-angular/plugins/karma'),
      require('karma-spec-reporter'),
    ],
    parallelOptions: {
      executors: 4, // Defaults to cpu-count - 1
      shardStrategy: 'round-robin'
    },
    client: {
      clearContext: false, // leave Jasmine Spec Runner output visible in browser
      jasmine: {
        random: false
      },
      captureConsole: false
    },
    jasmineHtmlReporter: {
      suppressAll: true // removes the duplicated traces
    },
    coverageReporter: {
      dir: require('path').join(__dirname, './coverage'),
      subdir: '.',
      reporters: [
        { type: 'html' },
        { type: 'text-summary' },
        { type : 'lcovonly'}
      ]
    },
    
    reporters: ["spec"],
    specReporter: {
      maxLogLines: 5,             // limit number of lines logged per test
      suppressSummary: false,      // do not print summary
      suppressErrorSummary: false, // do not print error summary
      suppressFailed: false,      // do not print information about failed tests
      suppressPassed: false,      // do not print information about passed tests
      suppressSkipped: true,      // do not print information about skipped tests
      showBrowser: false,         // print the browser for each spec
      showSpecTiming: true,      // print the time elapsed for each spec
      failFast: false             // test would finish with error when a first fail occurs
    },
    port: 9876,
    colors: true,
    logLevel: config.LOG_DISABLE,
    autoWatch: true,
    browsers: ['ChromeHeadless'],
    browserDisconnectTimeout: 10000,
    browserDisconnectTolerance: 3,
    singleRun: true,
    restartOnFileChange: true,
    browserNoActivityTimeout: 1000000
  });
};
Enter fullscreen mode Exit fullscreen mode

Our test.ts :

import 'zone.js';
import 'zone.js/testing';
import { getTestBed } from '@angular/core/testing';
import {
  BrowserDynamicTestingModule,
  platformBrowserDynamicTesting
} from '@angular/platform-browser-dynamic/testing';

// First, initialize the Angular testing environment.
getTestBed().initTestEnvironment(
  BrowserDynamicTestingModule,
  platformBrowserDynamicTesting(),
  { teardown: { destroyAfterEach: false }},
);
Enter fullscreen mode Exit fullscreen mode

jasmine/karma packages in package.json:

    "@types/jasmine": "^4.3.2",
    "jasmine-core": "~3.10.1",
    "karma": "~6.3.9",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage": "~2.1.0",
    "karma-jasmine": "~4.0.1",
    "karma-parallel": "^0.3.1",
Enter fullscreen mode Exit fullscreen mode

Top comments (0)