I perform some unit-tests with Karma
, Sinon
and Mocha
. It was working fine and for one month, I have some issues running these unit-tests. I have an error with HeadlessChrome. Indeed, it shows this error:
HeadlessChrome 83.0.4103 (Windows 10.0.0) ERROR
Disconnected, because no message in 30000 ms.
I have this karma configuration:
module.exports = function (config) {
config.set({
// Others configs
...
port: 9876,
browsers: ['ChromeHeadlessNoSandbox'],
customLaunchers: {
ChromeHeadlessNoSandbox: {
base: 'ChromeHeadless',
flags: [
'--no-sandbox', // required to run without privileges in docker
'--user-data-dir=/tmp/chrome-test-profile',
'--disable-web-security'
]
}
},
captureTimeout: 10000,
plugins: [
'karma-mocha', 'karma-mocha-reporter', 'karma-junit-reporter', 'karma-chrome-launcher',
'karma-typescript', 'karma-html-reporter'
]
});
};
I found two ways to fix it:
- Downgrade to version 81.
- Open a page in localhost:9876 in the browser.
- Change the karma config (browsers and flags property):
module.exports = function (config) {
config.set({
// Others configs
...
port: 9876,
browsers: ['Chrome'],
flags: [
'--no-sandbox', // required to run without privileges in docker
'--user-data-dir=/tmp/chrome-test-profile',
'--disable-web-security'
],
captureTimeout: 10000,
plugins: [
'karma-mocha', 'karma-mocha-reporter', 'karma-junit-reporter', 'karma-chrome-launcher',
'karma-typescript', 'karma-html-reporter'
]
});
};
How could I use ChromeHeadless again ? Indeed, it was nice because all unit-tests was running in background whereas now it opens the browsers, performs the tests and closes it.