Karma Test Error: Disconnected, because no message in 60000 ms

166 Views Asked by At

I'm running "ng test" command to implement Unit Testing in an Angular project.

Chrome Headless 120.0.6099.130 (Windows 10) ERROR
  Disconnected , because no message in 60000 ms.
Chrome Headless 120.0.6099.130 (Windows 10): Executed 404 of 134 (24 FAILED) (skipped 4) DISCONNECTED (5 mins 32.639 secs / 8.279 secs)
Chrome Headless 120.0.6099.130 (Windows 10) ERROR
Chrome Headless 120.0.6099.130 (Windows 10): Executed 404 of 134 (24 FAILED) (skipped 4) DISCONNECTED (5 mins 32.639 secs / 8.279 secs)

Testing is going on for a while, but it's facing a disconnected issue like the above.

I've tried changing configuration in karma.conf.js such as captureTimeout, brosweDisconnectTimeOut, browserDisconnectTolearnce, browserNoActivityTimeout, and flags in ChromeHeadlessNosandbox. Also, I've tried updating the latest version of Angular 16 (16 is a requirement).

karma.conf..js

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'),
      require('karma-sonarqube-reporter'),
      require('@angular-devkit/build-angular/plugins/karma')
    ],
    client: {
      jasmine: {
      },
      clearContext: false, 
    },
    jasmineHtmlReporter: {
      suppressAll: true
    },
    coverageReporter: {
      dir: require('path').join(__dirname, './coverage/r3p-ui'),
      subdir: '.',
      reporters: [
        { type: 'html', subdir: 'text-summary'},
        { type: 'text-summary', subdir: 'lcov-report' }
      ],
      check: {
        global: {
          statements: 20,
          branches: 1,
          functions: 20,
          lines: 20,
        },
      },
      watermarks: {
        statements: [ 10, 20 ],
        functions: [ 10, 20 ],
        branches: [ 10, 20 ],
        lines: [ 10, 20 ]
      },
    },
    reporters: ['coverage', 'progress', 'kjhtml', 'sonarqube'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['ChromeHeadlessNoSandbox'],
    singleRun: true,
    restartOnFileChange: false,
    sonarqubeReporter: {
      basePath: 'src',
      filePattern: '**/*spec.ts',
      encoding: 'utf-8',
      outputFolder: 'reports',
      legacyMode: false,
      reportName: 'test-report.xml'
    },    
    customLaunchers: {
      ChromeHeadlessNoSandbox: {
        base: 'ChromeHeadless',
        flags: [
          '--no-sandbox',
          // '--disable-gpu',
          // '--enable-logging',
          // '--no-default-browser-check',
          // '--no-first-run',
          // '--disable-default-apps',
          // '--disable-popup-blocking',
          // '--disable-translate',
          // '--disable-background-timer-throttling',
          // '--disable-renderer-backgrounding',
          // '--disable-device-discovery-notifications',
          // '--remote-debugging-port=9222',
          // '--disable-web-security'
  ]
      }
    },
    captureTimeout: 300000,
    browseDisconnectTimeOut: 40000,
    browserDisconnectTolerance: 4,
    browserNoActivityTimeout: 60000
  });
};

package.json

  "devDependencies": {
    "@angular-devkit/build-angular": "^16.1.1",
    "@angular/cli": "~16.1.1",
    "@angular/compiler-cli": "^16.1.0",
    "@babel/core": "^7.23.3",
    "@okta/okta-angular": "^6.3.0",
    "@types/file-saver": "^2.0.7",
    "@types/jasmine": "~4.3.0",
    "@types/pdfmake": "^0.2.4",
    "file-saver": "^2.0.5",
    "jasmine-core": "~4.6.0",
    "karma": "~6.4.0",
    "karma-chrome-launcher": "~3.2.0",
    "karma-coverage": "~2.2.0",
    "karma-jasmine": "~5.1.0",
    "karma-jasmine-html-reporter": "~2.1.0",
    "karma-sonarqube-reporter": "~1.4.0",
    "tslib": "^2.6.2",
    "typescript": "~5.1.3"
  },
1

There are 1 best solutions below

0
Wesley Trantham On

That's a long time for that many tests to run. For comparison,

Chrome 120.0.0.0 (Windows 10): Executed 307 of 343 (skipped 36) SUCCESS (3.966 secs / 3.666 secs)
TOTAL: 307 SUCCESS

I suspect that the tests themselves are doing something you are not expecting. You can try the following

  • change karma.conf.js line for browsers to browsers: ['Chrome'],
  • run ng test
  • in the Chrome window that comes up open DevTools and take a look at the console
  • the errors/warnings listed should indicate some issues

Your output is showing that you have 24 failed tests

  • suggest changing the top describe to xdescribe in the files with failed tests.
  • once you have excluded those tests take another glance at the console in DevTools to see if there is anything remaining
  • if it now works as expected, start to include the excluded tests and fix them