Open applecool opened 7 years ago
Mine gets stuck on this
12 01 2021 06:39:24.090:INFO [launcher]: Launching browsers ChromeHeadless with concurrency unlimited
12 01 2021 06:39:24.095:INFO [launcher]: Starting browser ChromeHeadless
✔ Browser application bundle generation complete.
12 01 2021 06:39:58.593:INFO [Chrome Headless 88.0.4298.0 (Mac OS 10.15.6)]: Connected on socket ... with id ...
ChromeHeadless gets stuck never endet after finish test
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-istanbul-reporter'),
require('karma-coverage'),
require('@angular-devkit/build-angular/plugins/karma'),
require('karma-mocha-reporter')
],
client: {
clearContext: false, // leave Jasmine Spec Runner output visible in browser
jasmine: {
random: false
}
},
coverageIstanbulReporter: {
dir: path.join(__dirname, '../../coverage/all'),
reports: ['html', 'lcovonly', 'text-summary'],
fixWebpackSourcePaths: true,
skipFilesWithNoCoverage: true,
combineBrowserReports: true,
thresholds: {
emitWarning: true, // set to `true` to not fail the test command when thresholds are not met
// thresholds for all files
global: {
statements: 80,
lines: 80,
branches: 80,
functions: 80
},
// thresholds per file
each: {
statements: 80,
lines: 80,
branches: 80,
functions: 80
}
}
},
// reporters: ['mocha', 'coverage', 'kjhtml'],
captureTimeout: 210000,
browserDisconnectTolerance: 3,
browserDisconnectTimeout : 210000,
browserNoActivityTimeout : 210000,
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_DEBUG,
autoWatch: true,
browsers: ['ChromeHeadlessNoSandbox'],
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'
]
}
},
autoWatch: true,
singleRun: false,
restartOnFileChange: false
});
};
` Chrome Headless 80.0.3987.0 (Windows 10): Executed 538 of 721 (skipped 171) SUCCESS (0 secs / 1 min 28.659 secs) Chrome Headless 80.0.3987.0 (Windows 10): Executed 545 of 721 (skipped 176) SUCCESS (1 min 33.621 secs / 1 min 28.814 secs) [INFO] TOTAL: 545 SUCCESS [INFO] TOTAL: 545 SUCCESS
`
It seems that running with --watch=false
did work, but I don't know why since another branch mine it's working. I don't get it.
I have a similar problem trying to test a large angular application:
- Generating browser application bundles...
28 01 2021 13:47:34.031:ERROR [launcher]: Chrome failed 2 times (timeout). Giving up.
28 01 2021 13:47:34.038:ERROR [launcher]: Chrome failed 2 times (timeout). Giving up.
as you can see, the browser is started before the application bundle is done generating. if the project is large and takes long to compile, this will eventually run into a timeout.
I was able to trace the issue by setting logLevel: config.LOG_DEBUG
in karma.conf.js
In my case there was an error FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
. For me before running karma, I set export NODE_OPTIONS="--max-old-space-size=8192"
which solved my issue
I have one single component and 5 tests. So it's very light project but facing the issue. I have tried with different node versions:
10.15.3
11.14.0
12.2.0
But no luck.
Not sure where to start debug.
The below is error message with LOG.DEBUG
20 02 2021 01:23:11.656:DEBUG [plugin]: Loading plugin /Users/MY_PROJECT_PATH/node_modules/@open-wc/karma-esm/karma-esm.js.
20 02 2021 01:23:12.174:DEBUG [plugin]: Loading plugin /Users/MY_PROJECT_PATH/node_modules/@open-wc/testing-karma/node_modules/karma-mocha/lib/index.js.
20 02 2021 01:23:12.175:DEBUG [plugin]: Loading plugin /Users/MY_PROJECT_PATH/node_modules/@open-wc/testing-karma/node_modules/karma-mocha-reporter/index.js.
20 02 2021 01:23:12.185:DEBUG [plugin]: Loading plugin /Users/MY_PROJECT_PATH/node_modules/karma-source-map-support/lib/index.js.
20 02 2021 01:23:12.186:DEBUG [plugin]: Loading plugin /Users/MY_PROJECT_PATH/node_modules/karma-coverage/lib/index.js.
20 02 2021 01:23:12.301:DEBUG [plugin]: Loading plugin /Users/MY_PROJECT_PATH/node_modules/karma-snapshot/lib/index.js.
20 02 2021 01:23:12.339:DEBUG [plugin]: Loading plugin /Users/MY_PROJECT_PATH/node_modules/karma-mocha-snapshot/lib/index.js.
20 02 2021 01:23:12.339:DEBUG [plugin]: Loading plugin /Users/MY_PROJECT_PATH/node_modules/karma-chrome-launcher/index.js.
20 02 2021 01:23:12.342:DEBUG [plugin]: Loading karma-* from /Users/MY_PROJECT_PATH/node_modules
20 02 2021 01:23:12.344:DEBUG [plugin]: Loading plugin /Users/MY_PROJECT_PATH/node_modules/karma-chrome-launcher.
20 02 2021 01:23:12.344:DEBUG [plugin]: Loading plugin /Users/MY_PROJECT_PATH/node_modules/karma-coverage.
20 02 2021 01:23:12.344:DEBUG [plugin]: Loading plugin /Users/MY_PROJECT_PATH/node_modules/karma-mocha.
20 02 2021 01:23:12.346:DEBUG [plugin]: Loading plugin /Users/MY_PROJECT_PATH/node_modules/karma-mocha-snapshot.
20 02 2021 01:23:12.346:DEBUG [plugin]: Loading plugin /Users/MY_PROJECT_PATH/node_modules/karma-snapshot.
20 02 2021 01:23:12.346:DEBUG [plugin]: Loading plugin /Users/MY_PROJECT_PATH/node_modules/karma-source-map-support.
20 02 2021 01:23:12.346:DEBUG [plugin]: Loading inline plugin defining launcher:ChromeHeadlessNoSandbox.
20 02 2021 01:23:12.355:DEBUG [web-server]: Instantiating middleware
20 02 2021 01:23:12.357:DEBUG [reporter]: Trying to load reporter: mocha
20 02 2021 01:23:12.411:DEBUG [reporter]: Trying to load color-version of reporter: mocha (mocha_color)
20 02 2021 01:23:12.411:DEBUG [reporter]: Couldn't load color-version.
START:
20 02 2021 01:23:12.429:WARN [filelist]: Pattern "/Users/MY_PROJECT_PATH/__snapshots__/**/*.md" does not match any file.
20 02 2021 01:23:12.460:INFO [karma-server]: Karma v6.1.1 server started at http://localhost:9876/
20 02 2021 01:23:12.461:INFO [launcher]: Launching browsers ChromeHeadlessNoSandbox with concurrency unlimited
20 02 2021 01:23:12.465:INFO [launcher]: Starting browser ChromeHeadless
20 02 2021 01:23:12.466:DEBUG [launcher]: null -> BEING_CAPTURED
20 02 2021 01:23:12.466:DEBUG [temp-dir]: Creating temp dir at /var/folders/m3/6jx6lrw56t5705kd43p1xthw0000gn/T/karma-86052018
20 02 2021 01:23:12.467:DEBUG [launcher]: /Applications/Google Chrome.app/Contents/MacOS/Google Chrome --user-data-dir=/var/folders/m3/6jx6lrw56t5705kd43p1xthw0000gn/T/karma-86052018 --enable-automation --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 --no-sandbox --disable-setuid-sandbox http://localhost:9876/?id=86052018 --headless --disable-gpu --disable-dev-shm-usage --remote-debugging-port=9222
20 02 2021 01:23:12.884:DEBUG [web-server]: serving: /Users/MY_PROJECT_PATH/node_modules/karma/static/client.html
20 02 2021 01:23:12.959:DEBUG [web-server]: serving: /Users/MY_PROJECT_PATH/node_modules/karma/static/karma.js
20 02 2021 01:23:13.039:DEBUG [karma-server]: A browser has connected on socket LSntSUnz0D5-0InJAAAB
20 02 2021 01:23:13.040:DEBUG [web-server]: upgrade /socket.io/?EIO=4&transport=websocket&sid=1AQA1ZLKZY_IOs5EAAAA
20 02 2021 01:23:13.058:DEBUG [Chrome Headless 88.0.4324.182 (Mac OS 10.14.6)]: undefined -> CONNECTED
20 02 2021 01:23:13.059:INFO [Chrome Headless 88.0.4324.182 (Mac OS 10.14.6)]: Connected on socket LSntSUnz0D5-0InJAAAB with id 86052018
20 02 2021 01:23:13.061:DEBUG [launcher]: BEING_CAPTURED -> CAPTURED
20 02 2021 01:23:13.062:DEBUG [launcher]: ChromeHeadless (id 86052018) captured in 0.6 secs
20 02 2021 01:23:13.063:DEBUG [Chrome Headless 88.0.4324.182 (Mac OS 10.14.6)]: CONNECTED -> CONFIGURING
20 02 2021 01:23:43.065:WARN [Chrome Headless 88.0.4324.182 (Mac OS 10.14.6)]: Disconnected (0 times) , because no message in 30000 ms.
Browser {
id: '86052018',
fullName: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) ' +
'AppleWebKit/537.36 (KHTML, like Gecko) ' +
'HeadlessChrome/88.0.4324.182 Safari/537.36',
name: 'Chrome Headless 88.0.4324.182 (Mac OS 10.14.6)',
lastResult: [BrowserResult],
disconnectsCount: 1,
activeSockets: [Array],
noActivityTimeout: 30000,
singleRun: true,
clientConfig: [Object],
collection: [BrowserCollection],
emitter: [Server],
socket: [Socket],
timer: [Object],
disconnectDelay: 2000,
log: [Logger],
noActivityTimeoutId: Timeout {
_idleTimeout: 30000,
_idlePrev: null,
_idleNext: null,
_idleStart: 1791,
_onTimeout: [Function],
_timerArgs: undefined,
_repeat: null,
_destroyed: false,
[Symbol(refed)]: true,
[Symbol(asyncId)]: 337,
[Symbol(triggerId)]: 329
},
pendingDisconnect: null,
state: 'CONFIGURING'
} ERROR
Disconnected , because no message in 30000 ms.
20 02 2021 01:23:43.069:DEBUG [Chrome Headless 88.0.4324.182 (Mac OS 10.14.6)]: CONFIGURING -> DISCONNECTED
20 02 2021 01:23:43.070:WARN [framework.snapshot]: Snapshot data is unavailable
20 02 2021 01:23:43.071:DEBUG [launcher]: CAPTURED -> BEING_KILLED
20 02 2021 01:23:43.071:DEBUG [launcher]: BEING_KILLED -> BEING_FORCE_KILLED
20 02 2021 01:23:43.071:DEBUG [Chrome Headless 88.0.4324.182 (Mac OS 10.14.6)]: DISCONNECTED -> DISCONNECTED
Finished in 30.007 secs / 0 secs @ 01:23:43 GMT+0100 (Central European Standard Time)
20 02 2021 01:23:43.073:DEBUG [karma-server]: Run complete, exiting.
20 02 2021 01:23:43.073:DEBUG [launcher]: Disconnecting all browsers
20 02 2021 01:23:43.073:DEBUG [launcher]: BEING_FORCE_KILLED -> BEING_FORCE_KILLED
20 02 2021 01:23:43.074:DEBUG [proxy]: Destroying proxy agents
20 02 2021 01:23:43.079:DEBUG [launcher]: Process ChromeHeadless exited with code null and signal SIGTERM
20 02 2021 01:23:43.079:DEBUG [temp-dir]: Cleaning temp dir /var/folders/m3/6jx6lrw56t5705kd43p1xthw0000gn/T/karma-86052018
20 02 2021 01:23:43.095:DEBUG [launcher]: Finished all browsers
20 02 2021 01:23:43.095:DEBUG [launcher]: BEING_FORCE_KILLED -> FINISHED
20 02 2021 01:23:43.095:DEBUG [launcher]: FINISHED -> FINISHED
Probably your test .html page failed to load, eg a syntax error You could try to enable logging https://www.chromium.org/for-testers/enable-logging
On Fri, Feb 19, 2021 at 4:42 PM Taehwa Kim notifications@github.com wrote:
I have one single component and 5 tests. So it's very light project but facing the issue. I have tried with different node versions:
- 10.15.3
- 11.14.0
- 12.2.0
But no luck.
Not sure where to start debug. The below is error message with LOG.DEBUG
20 02 2021 01:23:11.656:DEBUG [plugin]: Loading plugin /Users/MY_PROJECT_PATH/node_modules/@open-wc/karma-esm/karma-esm.js.20 02 2021 01:23:12.174:DEBUG [plugin]: Loading plugin /Users/MY_PROJECT_PATH/node_modules/@open-wc/testing-karma/node_modules/karma-mocha/lib/index.js.20 02 2021 01:23:12.175:DEBUG [plugin]: Loading plugin /Users/MY_PROJECT_PATH/node_modules/@open-wc/testing-karma/node_modules/karma-mocha-reporter/index.js.20 02 2021 01:23:12.185:DEBUG [plugin]: Loading plugin /Users/MY_PROJECT_PATH/node_modules/karma-source-map-support/lib/index.js.20 02 2021 01:23:12.186:DEBUG [plugin]: Loading plugin /Users/MY_PROJECT_PATH/node_modules/karma-coverage/lib/index.js.20 02 2021 01:23:12.301:DEBUG [plugin]: Loading plugin /Users/MY_PROJECT_PATH/node_modules/karma-snapshot/lib/index.js.20 02 2021 01:23:12.339:DEBUG [plugin]: Loading plugin /Users/MY_PROJECT_PATH/node_modules/karma-mocha-snapshot/lib/index.js.20 02 2021 01:23:12.339:DEBUG [plugin]: Loading plugin /Users/MY_PROJECT_PATH/node_modules/karma-chrome-launcher/index.js.20 02 2021 01:23:12.342:DEBUG [plugin]: Loading karma-* from /Users/MY_PROJECT_PATH/node_modules20 02 2021 01:23:12.344:DEBUG [plugin]: Loading plugin /Users/MY_PROJECT_PATH/node_modules/karma-chrome-launcher.20 02 2021 01:23:12.344:DEBUG [plugin]: Loading plugin /Users/MY_PROJECT_PATH/node_modules/karma-coverage.20 02 2021 01:23:12.344:DEBUG [plugin]: Loading plugin /Users/MY_PROJECT_PATH/node_modules/karma-mocha.20 02 2021 01:23:12.346:DEBUG [plugin]: Loading plugin /Users/MY_PROJECT_PATH/node_modules/karma-mocha-snapshot.20 02 2021 01:23:12.346:DEBUG [plugin]: Loading plugin /Users/MY_PROJECT_PATH/node_modules/karma-snapshot.20 02 2021 01:23:12.346:DEBUG [plugin]: Loading plugin /Users/MY_PROJECT_PATH/node_modules/karma-source-map-support.20 02 2021 01:23:12.346:DEBUG [plugin]: Loading inline plugin defining launcher:ChromeHeadlessNoSandbox.20 02 2021 01:23:12.355:DEBUG [web-server]: Instantiating middleware20 02 2021 01:23:12.357:DEBUG [reporter]: Trying to load reporter: mocha20 02 2021 01:23:12.411:DEBUG [reporter]: Trying to load color-version of reporter: mocha (mocha_color)20 02 2021 01:23:12.411:DEBUG [reporter]: Couldn't load color-version.
START:20 02 2021 01:23:12.429:WARN [filelist]: Pattern "/Users/MY_PROJECT_PATH/snapshots/*/.md" does not match any file.20 02 2021 01:23:12.460:INFO [karma-server]: Karma v6.1.1 server started at http://localhost:9876/20 02 2021 01:23:12.461:INFO [launcher]: Launching browsers ChromeHeadlessNoSandbox with concurrency unlimited20 02 2021 01:23:12.465:INFO [launcher]: Starting browser ChromeHeadless20 02 2021 01:23:12.466:DEBUG [launcher]: null -> BEING_CAPTURED20 02 2021 01:23:12.466:DEBUG [temp-dir]: Creating temp dir at /var/folders/m3/6jx6lrw56t5705kd43p1xthw0000gn/T/karma-8605201820 02 2021 01:23:12.467:DEBUG [launcher]: /Applications/Google Chrome.app/Contents/MacOS/Google Chrome --user-data-dir=/var/folders/m3/6jx6lrw56t5705kd43p1xthw0000gn/T/karma-86052018 --enable-automation --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 --no-sandbox --disable-setuid-sandbox http://localhost:9876/?id=86052018 --headless --disable-gpu --disable-dev-shm-usage --remote-debugging-port=922220 02 2021 01:23:12.884:DEBUG [web-server]: serving: /Users/MY_PROJECT_PATH/node_modules/karma/static/client.html20 02 2021 01:23:12.959:DEBUG [web-server]: serving: /Users/MY_PROJECT_PATH/node_modules/karma/static/karma.js20 02 2021 01:23:13.039:DEBUG [karma-server]: A browser has connected on socket LSntSUnz0D5-0InJAAAB20 02 2021 01:23:13.040:DEBUG [web-server]: upgrade /socket.io/?EIO=4&transport=websocket&sid=1AQA1ZLKZY_IOs5EAAAA20 02 2021 01:23:13.058:DEBUG [Chrome Headless 88.0.4324.182 (Mac OS 10.14.6)]: undefined -> CONNECTED20 02 2021 01:23:13.059:INFO [Chrome Headless 88.0.4324.182 (Mac OS 10.14.6)]: Connected on socket LSntSUnz0D5-0InJAAAB with id 8605201820 02 2021 01:23:13.061:DEBUG [launcher]: BEING_CAPTURED -> CAPTURED20 02 2021 01:23:13.062:DEBUG [launcher]: ChromeHeadless (id 86052018) captured in 0.6 secs20 02 2021 01:23:13.063:DEBUG [Chrome Headless 88.0.4324.182 (Mac OS 10.14.6)]: CONNECTED -> CONFIGURING20 02 2021 01:23:43.065:WARN [Chrome Headless 88.0.4324.182 (Mac OS 10.14.6)]: Disconnected (0 times) , because no message in 30000 ms.Browser { id: '86052018', fullName: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) ' + 'AppleWebKit/537.36 (KHTML, like Gecko) ' + 'HeadlessChrome/88.0.4324.182 Safari/537.36', name: 'Chrome Headless 88.0.4324.182 (Mac OS 10.14.6)', lastResult: [BrowserResult], disconnectsCount: 1, activeSockets: [Array], noActivityTimeout: 30000, singleRun: true, clientConfig: [Object], collection: [BrowserCollection], emitter: [Server], socket: [Socket], timer: [Object], disconnectDelay: 2000, log: [Logger], noActivityTimeoutId: Timeout { _idleTimeout: 30000, _idlePrev: null, _idleNext: null, _idleStart: 1791, _onTimeout: [Function], _timerArgs: undefined, _repeat: null, _destroyed: false,
[Symbol(asyncId)]: 337, [Symbol(triggerId)]: 329
}, pendingDisconnect: null, state: 'CONFIGURING'} ERROR Disconnected , because no message in 30000 ms.20 02 2021 01:23:43.069:DEBUG [Chrome Headless 88.0.4324.182 (Mac OS 10.14.6)]: CONFIGURING -> DISCONNECTED20 02 2021 01:23:43.070:WARN [framework.snapshot]: Snapshot data is unavailable20 02 2021 01:23:43.071:DEBUG [launcher]: CAPTURED -> BEING_KILLED20 02 2021 01:23:43.071:DEBUG [launcher]: BEING_KILLED -> BEING_FORCE_KILLED20 02 2021 01:23:43.071:DEBUG [Chrome Headless 88.0.4324.182 (Mac OS 10.14.6)]: DISCONNECTED -> DISCONNECTED Finished in 30.007 secs / 0 secs @ 01:23:43 GMT+0100 (Central European Standard Time) 20 02 2021 01:23:43.073:DEBUG [karma-server]: Run complete, exiting.20 02 2021 01:23:43.073:DEBUG [launcher]: Disconnecting all browsers20 02 2021 01:23:43.073:DEBUG [launcher]: BEING_FORCE_KILLED -> BEING_FORCE_KILLED20 02 2021 01:23:43.074:DEBUG [proxy]: Destroying proxy agents20 02 2021 01:23:43.079:DEBUG [launcher]: Process ChromeHeadless exited with code null and signal SIGTERM20 02 2021 01:23:43.079:DEBUG [temp-dir]: Cleaning temp dir /var/folders/m3/6jx6lrw56t5705kd43p1xthw0000gn/T/karma-8605201820 02 2021 01:23:43.095:DEBUG [launcher]: Finished all browsers20 02 2021 01:23:43.095:DEBUG [launcher]: BEING_FORCE_KILLED -> FINISHED20 02 2021 01:23:43.095:DEBUG [launcher]: FINISHED -> FINISHED
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/karma-runner/karma-chrome-launcher/issues/154#issuecomment-782481544, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABSGAQESXNLHCDYGRKJH23S74APPANCNFSM4D4NQNCQ .
@johnjbarton Thanks for the info. I have tested with enable-logging but couldn't find any meaningful clue.
But sudo
saved my life.
When I run as sudo npm run test
, it works as expected.
The remaining question is why suddenly I need sudo
while I didn't need it a couple of days ago.
Hello everyone!
We got the same issue in our CI pipeline when upgrading chromium from 87.0.4280 to 88.0.4324. In other words:
Works as expected When using chromium version 87.0.4280
Tests does not execute When using chromium version 88.0.4324
Has anyone else encountered the same issue? Thanks in advance! :)
We faced that issue about 2 years ago. I remember that this comment was the key for us
By default, Docker runs a container with a /dev/shm shared memory space 64MB. This is typically too small for Chrome and will cause Chrome to crash when rendering large pages. To fix, run the container with docker run --shm-size=1gb to increase the size of /dev/shm. Since Chrome 65, this is no longer necessary. Instead, launch the browser with the --disable-dev-shm-usage flag:
(source: https://developers.google.com/web/tools/puppeteer/troubleshooting)
Since then, this is how we configure the chrome part in karma
customLaunchers: {
ChromeBrowser: {
base: "ChromeHeadless",
flags: [
"--no-sandbox",
`--remote-debugging-port=${config.chromePort}`,
"--disable-dev-shm-usage",
],
},
},
later (since version 3.1.0) the karma-chrome-launcher
added the --disable-dev-shm-usage
flag to its default flags. We still did increase the shm-size
for our docker containers and kept the shown configuration.
@nguyenlam123 That might explain why suddenly karma testing stop working. I don't know when exactly my Chrome has updated to 88 but I know it was quite recent.
@giniedp @Taewa Thanks guys! We are currently trying it out and see if it works. :)
Unfortunately, the error still persists with Chrome Headless 89.0.4389.82.
Error:
15 03 2021 11:58:01.744:WARN [Chrome Headless 89.0.4389.82 (Linux x86_64)]: Disconnected (0 times)reconnect failed before timeout of 2000ms (transport close)
Chrome Headless 89.0.4389.82 (Linux x86_64) ERROR
Disconnectedreconnect failed before timeout of 2000ms (transport close)
We still experience this issue. Here is a log where the second attempt worked:
as you can see in the following log, this is the process:
depending on how long bundle creation takes (in big applications that can take some minutes), the second attempt may also fail.
for this to work properly, no matter the size of this project, the correct process should read like this:
19 03 2021 08:14:46.934:DEBUG [plugin]: Loading inline plugin defining launcher:OurChrome, launcher:DockerChrome.
19 03 2021 08:14:46.942:DEBUG [framework:karma-parallel]: adding "parallel" beforeMiddleware to configuration
19 03 2021 08:14:46.942:INFO [framework:karma-parallel]: sharding specs across 2 browsers
- Generating browser application bundles...
19 03 2021 08:15:24.971:DEBUG [web-server]: Instantiating middleware
19 03 2021 08:15:24.972:DEBUG [middleware:parallel]: reporter aggregation setup for junit, coverage
19 03 2021 08:15:24.973:DEBUG [reporter]: Trying to load reporter: @angular-devkit/build-angular--event-reporter
19 03 2021 08:15:24.974:DEBUG [reporter]: Trying to load color-version of reporter: @angular-devkit/build-angular--event-reporter (@angular-devkit/build-angular--event-reporter_color)
19 03 2021 08:15:24.975:DEBUG [reporter]: Couldn't load color-version.
19 03 2021 08:15:24.975:DEBUG [reporter]: Trying to load reporter: spec
19 03 2021 08:15:24.976:DEBUG [reporter]: Trying to load color-version of reporter: spec (spec_color)
19 03 2021 08:15:24.976:DEBUG [reporter]: Couldn't load color-version.
19 03 2021 08:15:24.976:DEBUG [reporter]: Trying to load reporter: parallel-coverage
19 03 2021 08:15:24.977:DEBUG [reporter:parallel-coverage]: instantiating reporter:junit
19 03 2021 08:15:24.978:DEBUG [reporter:parallel-coverage]: instantiating reporter:coverage
19 03 2021 08:15:24.978:DEBUG [reporter]: Trying to load color-version of reporter: parallel-coverage (parallel-coverage_color)
19 03 2021 08:15:24.979:DEBUG [reporter]: Couldn't load color-version.
19 03 2021 08:15:25.002:DEBUG [reporter:parallel-coverage]: relaying onRunStart() on reporter:junit
19 03 2021 08:15:25.003:DEBUG [reporter:parallel-coverage]: relaying onRunStart() on reporter:coverage
19 03 2021 08:15:25.950:INFO [karma-server]: Karma v6.2.0 server started at http://localhost:9878/
19 03 2021 08:15:25.950:INFO [launcher]: Launching browsers DockerChrome, DockerChrome with concurrency unlimited
19 03 2021 08:15:25.954:INFO [launcher]: Starting browser Chrome
19 03 2021 08:15:25.955:DEBUG [launcher]: null -> BEING_CAPTURED
19 03 2021 08:15:25.955:DEBUG [temp-dir]: Creating temp dir at /tmp/karma-6909294
19 03 2021 08:15:25.956:DEBUG [launcher]: /usr/bin/chromium-browser --user-data-dir=/tmp/karma-6909294 --enable-automation --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 --no-sandbox --headless --disable-gpu --remote-debugging-port=9222 http://localhost:9878/?id=6909294
19 03 2021 08:15:26.018:INFO [launcher]: Starting browser Chrome
19 03 2021 08:15:26.018:DEBUG [launcher]: null -> BEING_CAPTURED
19 03 2021 08:15:26.018:DEBUG [temp-dir]: Creating temp dir at /tmp/karma-3924522
19 03 2021 08:15:26.018:DEBUG [launcher]: /usr/bin/chromium-browser --user-data-dir=/tmp/karma-3924522 --enable-automation --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 --no-sandbox --headless --disable-gpu --remote-debugging-port=9222 http://localhost:9878/?id=3924522
19 03 2021 08:16:34.073:WARN [launcher]: Chrome have not captured in 60000 ms, killing.
19 03 2021 08:16:34.074:DEBUG [launcher]: BEING_CAPTURED -> BEING_KILLED
19 03 2021 08:16:34.074:WARN [launcher]: Chrome have not captured in 60000 ms, killing.
19 03 2021 08:16:34.075:DEBUG [launcher]: BEING_CAPTURED -> BEING_KILLED
19 03 2021 08:16:38.498:WARN [launcher]: Chrome was not killed in 2000 ms, sending SIGKILL.
19 03 2021 08:16:38.498:WARN [launcher]: Chrome was not killed in 2000 ms, sending SIGKILL.
19 03 2021 08:16:38.513:DEBUG [launcher]: Process Chrome exited with code null and signal SIGTERM
19 03 2021 08:16:38.514:DEBUG [temp-dir]: Cleaning temp dir /tmp/karma-6909294
19 03 2021 08:16:38.515:DEBUG [launcher]: Process Chrome exited with code null and signal SIGTERM
19 03 2021 08:16:38.516:DEBUG [temp-dir]: Cleaning temp dir /tmp/karma-3924522
19 03 2021 08:16:40.993:INFO [launcher]: Trying to start Chrome again (1/2).
19 03 2021 08:16:40.994:DEBUG [launcher]: BEING_KILLED -> RESTARTING
19 03 2021 08:16:40.994:DEBUG [launcher]: RESTARTING -> FINISHED
19 03 2021 08:16:40.994:DEBUG [launcher]: FINISHED -> FINISHED
19 03 2021 08:16:40.994:DEBUG [launcher]: Restarting Chrome
19 03 2021 08:16:40.994:DEBUG [launcher]: FINISHED -> BEING_CAPTURED
19 03 2021 08:16:40.995:DEBUG [temp-dir]: Creating temp dir at /tmp/karma-6909294
19 03 2021 08:16:40.995:DEBUG [launcher]: /usr/bin/chromium-browser --user-data-dir=/tmp/karma-6909294 --enable-automation --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 --no-sandbox --headless --disable-gpu --remote-debugging-port=9222 http://localhost:9878/?id=6909294
19 03 2021 08:16:41.097:INFO [launcher]: Trying to start Chrome again (1/2).
19 03 2021 08:16:41.098:DEBUG [launcher]: BEING_KILLED -> RESTARTING
19 03 2021 08:16:41.098:DEBUG [launcher]: RESTARTING -> FINISHED
19 03 2021 08:16:41.098:DEBUG [launcher]: FINISHED -> FINISHED
19 03 2021 08:16:41.098:DEBUG [launcher]: Restarting Chrome
19 03 2021 08:16:41.098:DEBUG [launcher]: FINISHED -> BEING_CAPTURED
19 03 2021 08:16:41.098:DEBUG [temp-dir]: Creating temp dir at /tmp/karma-3924522
19 03 2021 08:16:41.099:DEBUG [launcher]: /usr/bin/chromium-browser --user-data-dir=/tmp/karma-3924522 --enable-automation --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 --no-sandbox --headless --disable-gpu --remote-debugging-port=9222 http://localhost:9878/?id=3924522
19 03 2021 08:17:41.171:WARN [launcher]: Chrome have not captured in 60000 ms, killing.
19 03 2021 08:17:41.184:DEBUG [launcher]: BEING_CAPTURED -> BEING_KILLED
19 03 2021 08:17:41.184:WARN [launcher]: Chrome have not captured in 60000 ms, killing.
19 03 2021 08:17:41.185:DEBUG [launcher]: BEING_CAPTURED -> BEING_KILLED
19 03 2021 08:17:41.944:DEBUG [launcher]: Process Chrome exited with code null and signal SIGTERM
19 03 2021 08:17:41.944:DEBUG [temp-dir]: Cleaning temp dir /tmp/karma-6909294
19 03 2021 08:17:41.945:DEBUG [launcher]: Process Chrome exited with code null and signal SIGTERM
19 03 2021 08:17:41.945:DEBUG [temp-dir]: Cleaning temp dir /tmp/karma-3924522
19 03 2021 08:17:52.054:INFO [launcher]: Trying to start Chrome again (2/2).
19 03 2021 08:17:52.055:DEBUG [launcher]: BEING_KILLED -> RESTARTING
19 03 2021 08:17:52.055:DEBUG [launcher]: RESTARTING -> FINISHED
19 03 2021 08:17:52.055:DEBUG [launcher]: FINISHED -> FINISHED
19 03 2021 08:17:52.055:DEBUG [launcher]: Restarting Chrome
19 03 2021 08:17:52.055:DEBUG [launcher]: FINISHED -> BEING_CAPTURED
19 03 2021 08:17:52.055:DEBUG [temp-dir]: Creating temp dir at /tmp/karma-3924522
19 03 2021 08:17:52.056:DEBUG [launcher]: /usr/bin/chromium-browser --user-data-dir=/tmp/karma-3924522 --enable-automation --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 --no-sandbox --headless --disable-gpu --remote-debugging-port=9222 http://localhost:9878/?id=3924522
19 03 2021 08:17:52.178:INFO [launcher]: Trying to start Chrome again (2/2).
19 03 2021 08:17:52.178:DEBUG [launcher]: BEING_KILLED -> RESTARTING
19 03 2021 08:17:52.178:DEBUG [launcher]: RESTARTING -> FINISHED
19 03 2021 08:17:52.178:DEBUG [launcher]: FINISHED -> FINISHED
19 03 2021 08:17:52.178:DEBUG [launcher]: Restarting Chrome
19 03 2021 08:17:52.179:DEBUG [launcher]: FINISHED -> BEING_CAPTURED
19 03 2021 08:17:52.179:DEBUG [temp-dir]: Creating temp dir at /tmp/karma-6909294
19 03 2021 08:17:52.179:DEBUG [launcher]: /usr/bin/chromium-browser --user-data-dir=/tmp/karma-6909294 --enable-automation --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 --no-sandbox --headless --disable-gpu --remote-debugging-port=9222 http://localhost:9878/?id=6909294
✔ Browser application bundle generation complete.
19 03 2021 08:18:48.986:DEBUG [web-server]: serving: /builds/my-project/node_modules/karma/static/client.html
19 03 2021 08:18:48.988:DEBUG [web-server]: serving: /builds/my-project/node_modules/karma/static/client.html
19 03 2021 08:18:48.988:DEBUG [web-server]: serving: /builds/my-project/node_modules/karma/static/client.html
19 03 2021 08:18:48.989:DEBUG [web-server]: serving: /builds/my-project/node_modules/karma/static/client.html
19 03 2021 08:18:48.989:DEBUG [web-server]: serving: /builds/my-project/node_modules/karma/static/client.html
19 03 2021 08:18:48.990:DEBUG [web-server]: serving: /builds/my-project/node_modules/karma/static/client.html
19 03 2021 08:18:49.014:DEBUG [web-server]: serving: /builds/my-project/node_modules/karma/static/karma.js
19 03 2021 08:18:49.016:DEBUG [web-server]: serving: /builds/my-project/node_modules/karma/static/karma.js
19 03 2021 08:18:49.146:DEBUG [karma-server]: A browser has connected on socket y_VBj0M6-0Hj-WRzAAAC
19 03 2021 08:18:49.148:DEBUG [karma-server]: A browser has connected on socket rNgy4CU0y4gWwNedAAAD
19 03 2021 08:18:49.150:DEBUG [web-server]: upgrade /socket.io/?EIO=4&transport=websocket&sid=f-puLtF1b88TNUe6AAAB
19 03 2021 08:18:49.155:DEBUG [web-server]: upgrade /socket.io/?EIO=4&transport=websocket&sid=YripWcjyEhvV-BDaAAAA
19 03 2021 08:18:49.173:DEBUG [Chrome Headless 87.0.4280.66 (Linux x86_64)]: undefined -> CONNECTED
19 03 2021 08:18:49.174:INFO [Chrome Headless 87.0.4280.66 (Linux x86_64)]: Connected on socket rNgy4CU0y4gWwNedAAAD with id 6909294
19 03 2021 08:18:49.176:DEBUG [framework:karma-parallel]: registering browser id 6909294 with aggregated browser id 1472981494490 at shard index 0
19 03 2021 08:18:49.176:DEBUG [launcher]: BEING_CAPTURED -> CAPTURED
Could this be all caused by a port conflict?
Is there a posibility that this problem could be related to source maps. Because when I update the command to:
ng test --code-coverage --no-watch --source-map=false
Now everything works without any timeout. If I change the command to:
ng test --code-coverage --watch=false
It starts failing again.
??
Thanks for the comment. It helped me.
My karma.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('@angular-devkit/build-angular/plugins/karma'),
],
client: {
clearContext: false, // leave Jasmine Spec Runner output visible in browser
},
coverageReporter: {
dir: require('path').join(__dirname, '/coverage/'),
subdir: '.',
fixWebpackSourcePaths: true,
type: 'json-summary',
},
customLaunchers: {
ChromeHeadlessDocker: {
base: 'ChromeHeadless',
flags: ['--no-sandbox'],
},
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['ChromeHeadlessDocker'],
singleRun: true,
restartOnFileChange: true,
captureTimeout: 600000,
browserNoActivityTimeout: 120000,
browserDisconnectTolerance: 2,
});
Command: ng test --source-map=false --no-watch With --source-map=false it works on Docker. The command hags without it.
@c-goldschmidt hit the nail on the head. The test project isn't waiting for the build to complete before trying to start the browser and begin testing.
@NealAJohnson do you know how to make it to be waiting?
No clue, I don't even know if that's configurable.
For the ones that experience this issue with Angular.
The problem is that the Angular build (webpack) is running in parallel with launching the Chrome browser. In a simple Angular project that is no big deal as the build is fast, but in a big Angular project the build chokes the system and launching the browser takes longer than Karma's captureTimeout
.
The workaround using --source-map=false
is just putting less stress on the system. Similar to increasing the captureTimeout
or trying your luck with Chrome options it will just fail at some point.
A better solution is to run webpack and launching the browser serially.
I created a Karma framework type plugin that does just that. It makes sure Karma waits for the webpack build to complete before launching browsers.
karma.conf.js
plugins: [
require('./karma.waitwebpack'),
require('@angular-devkit/build-angular/plugins/karma'),
],
frameworks: ['waitwebpack', 'jasmine', '@angular-devkit/build-angular'], // waitwebpack must be before build-angular
karma.waitwebpack.js
function WebpackCompilerEventsPlugin(options) {
this.options = options;
}
WebpackCompilerEventsPlugin.prototype.apply = function(compiler) {
compiler.hooks.afterDone.tap('webpack-compiler-events-plugin', this.options.afterDone)
};
function waitWebpackFactory(config) {
return new Promise(resolve => {
let isFirstBuild = true;
config.buildWebpack.webpackConfig.plugins.push(new WebpackCompilerEventsPlugin({
afterDone: () => {
if (isFirstBuild) {
console.log('First webpack build done');
isFirstBuild = false;
resolve();
}
}
}));
});
}
waitWebpackFactory.$inject = ['config'];
module.exports = {
'framework:waitwebpack': ['factory', waitWebpackFactory]
};
With this plugin the output is always like:
✔ Browser application bundle generation complete.
First webpack build done
06 12 2021 11:50:07.581:INFO [karma-server]: Karma v6.3.2 server started at http://localhost:9876/
06 12 2021 11:50:07.587:INFO [launcher]: Launching browsers ChromeHeadless with concurrency unlimited
06 12 2021 11:50:07.595:INFO [launcher]: Starting browser ChromeHeadless
06 12 2021 11:50:08.348:INFO [Chrome Headless 96.0.4664.45 (Windows 10)]: Connected on socket nSjyH7dZhDllDpNPAAAB with id 79018619
I ran into this with my Angular project after upgrading to Angular 12, and no combination of the karma config recommended here was resolving it. I tried different browsers, both headless and non-headless, with no luck. Turns out, I had a compilation error in the test.ts
file Karma was using to load the spec files and initialize the angular environment. I copied over a clean test.ts
file generated with ng new
, and it all worked.
This error was only getting logged with I ran the Karma tests using Chrome then opened up the Console in the browser opened by Karma.
For us, we were getting the following:
17:32:38 14 12 2021 17:32:38.443:INFO [Chrome Headless 96.0.4664.93 (Windows 10)]: Connected on socket Nwq3Md9L_K7XgjRCAAAB with id 5799029
17:33:10 14 12 2021 17:33:10.269:WARN [Chrome Headless 96.0.4664.93 (Windows 10)]: Disconnected (0 times) reconnect failed before timeout of 2000ms (ping timeout)
17:33:10 Chrome Headless 96.0.4664.93 (Windows 10) ERROR
17:33:10 Disconnected reconnect failed before timeout of 2000ms (ping timeout)
I opened Chrome manually and checked to see if an update was pending. There was an update pending, we let it complete and the problem seems to have gone away.
For us, we were getting the following:
17:32:38 14 12 2021 17:32:38.443:INFO [Chrome Headless 96.0.4664.93 (Windows 10)]: Connected on socket Nwq3Md9L_K7XgjRCAAAB with id 5799029 17:33:10 14 12 2021 17:33:10.269:WARN [Chrome Headless 96.0.4664.93 (Windows 10)]: Disconnected (0 times) reconnect failed before timeout of 2000ms (ping timeout) 17:33:10 Chrome Headless 96.0.4664.93 (Windows 10) ERROR 17:33:10 Disconnected reconnect failed before timeout of 2000ms (ping timeout)
I opened Chrome manually and checked to see if an update was pending. There was an update pending, we let it complete and the problem seems to have gone away.
It started failing again, we increased browserDisconnectTimeout
from 2000 to 10000 and we got a successful build.
@jr01 Your solution works perfectly for our large Angular monorepo. Thanks!
@jr01 Hello,
By any chance, would you have an idea of why I would be receiving this error when utilizing your plugin? Thanks for your help!
Cannot read property 'tap' of undefined
at WebpackCompilerEventsPlugin.apply(karma.waitwebpack.js:6:28)
@aruballo - Perhaps a different webpack version. I was using Angular 13.0 at the time. If you upgrade to https://github.com/angular/angular-cli/releases/tag/13.2.3 you don't need the workaround.
@jr01 I am facing the same issue @aruballo raised. What workaround would you suggest?
I am on Angular 8.3
Thanks.
@aruballo @ArinzeOkorji
Just replace afterDone
with done
everywhere (inside waitWebpackFactory
too), should do the work
The most helpful suggestion is here . My setup information: Linux VM
karma: 4.4.1 karma-jasmine: 2.0.1 karmar-chrome-launcher: 3.1.0 jasmine-core: 3.0.0 puppeteer: 14.0.1
var absolute_path = process.cwd() + '/';
process.env.CHROME_BIN = require('puppeteer).executablePath();
customLaunchers: {
HeadlessChrome: {
base: 'ChromeHeadless',
flags: [
'--no-sandbox',
'--disable-translate',
'--disable-extensions'
]
}
}
I struggle for few days with this issue, hope it helps someone.
Hello guys I tried everything but not a single thing worked for me. Here is solution 👍 Please check if you are using window.location.href to change a application URL path. As soon as the path change it will disconnect from original application and there is not way to get responce back. that's why there is timeout issue.
You can try by commenting window.location.href. it will work. If this is not working for you please comment.
Hello guys I tried everything but not a single thing worked for me. Here is solution 👍 Please check if you are using window.location.href to change a application URL path. As soon as the path change it will disconnect from original application and there is not way to get responce back. that's why there is timeout issue.
You can try by commenting window.location.href. it will work. If this is not working for you please comment.
Ran into this same problem and commenting out window.location.href = ...
allows all tests to run to completion consistently. Oddly enough, when running just a single test that takes the path which includes window.location.href
, the test still completes normally.
I add (window as any)['global'] = window;
into my polyfills.ts
file and it solved the problem.
I had a very similar issue. I didn't think twice and made strict dependencies in package.json for everything related to tests and it worked
"jasmine": "3.4.0",
"jasmine-core": "3.3.0",
"jasmine-spec-reporter": "4.1.0",
"jest": "24.8.0",
"karma": "6.3.17",
"karma-chrome-launcher": "2.1.1",
"karma-cli": "1.0.1",
"karma-coverage": "1.1.2",
"karma-coverage-istanbul-reporter": "1.4.3",
"karma-jasmine": "2.0.0",
"karma-jasmine-html-reporter": "1.4.0",
I recently had this problem and what helped me was starting the browser without headless mode to see the real problem. In my case the browser was trying to reach http://localhost:9876/ but got an ERR_SOCKET_NOT_CONNECTED error. The clue was that it worked when I changed it to http://127.0.0.1:9876/
The fix in my case was changing the listen address and hostname in the karma.conf:
hostname: '127.0.0.1',
listenAddress: '127.0.0.1',
Faced the same issue with connections and fixed by downgrading karma package from 6.4.2
to previous major version 5.2.3
.
And adding
listenAddress: "localhost",
hostname: "localhost",
and "--remote-debugging-address=0.0.0.0" into ChromeHeadless flags in karma config file
I have configured the headless chrome in my project getting rid of Phantom. When I run the tests on my OSX machine, all the tests get executed with the test runner on the headless chrome. But the same doesn't happen on my linux server. It connects to the socket and then after some time, it disconnects and shows the error message saying "Karma tests failed". Error:
Here is my configuration:
Using
karma-chrome-launcher: "2.1.1"
. Tried with the latest2.2.0
version too. Tried withkarma: "1.5.0"
,"1.6.0"
, and the latest"1.7.1"
.I tried other flags like "
--no-sandbox
", "--disable-web-security
" as suggested on a bunch of issues on karma repo. But still no luck. Is there a fix or workaround for this issue? Is there a reason why it's not working on the Linux server [Ubuntu Server 14.04.5 LTS].