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"
},
That's a long time for that many tests to run. For comparison,
I suspect that the tests themselves are doing something you are not expecting. You can try the following
karma.conf.jsline for browsers tobrowsers: ['Chrome'],ng testYour output is showing that you have 24 failed tests
describetoxdescribein the files with failed tests.