Reputation: 2353
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:
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.
Upvotes: 7
Views: 13402
Reputation: 41
I've check the issue on my end, we can fix this issue by using puppeteer
's chrome bin instead !
Check out https://github.com/karma-runner/karma-chrome-launcher#headless-chromium-with-puppeteer for how !
That way, we rely on something a little more stable made by the Chrome's Dev team.
Be aware through that this will install a new Chrome binary on everyone one's computer when doing npm install
, but will also make sure every tests against the same version.
Upvotes: 0
Reputation: 41
We had the same surprise at my job. Our tests started to fail at the end of June which was a new Chrome 83 stable release.
They definitely broke something, you can follow-up here : https://bugs.chromium.org/p/chromium/issues/detail?id=1090988
EDIT:
So to answer properly, if you can go back to before Chrome 83, that will fix it for now. However, I don't know for our side of things, I would need to find a new docker image, which is not nice.
Upvotes: 3