Karma Disconnected, because no message in 10000 ms

35.9k Views Asked by At

The Karma test suite fails with the message:

Disconnected, because no message in 10000 ms.

No tests are executed at all.

"@angular/core": "7.1.3",
"jasmine-core": "3.3.0",
"karma-jasmine": "1.1.2",

There is no apparent reason for the failure, it just started after a new test was introduced.

7

There are 7 best solutions below

5
chris On BEST ANSWER

When the --module compiler option for TypeScript in tsconfig.spec.json is set to commonjs Karma fails internally before any tests are executed and shows the timeout error above.

The import ordering can let Karma fail:

import CustomerTypeEnum = CustomerDto.CustomerTypeEnum;
import {CustomerDto} from '../api/CustomerDto';

While this order works as expected:

import {CustomerDto} from '../api/CustomerDto';
import CustomerTypeEnum = CustomerDto.CustomerTypeEnum;

The problem can also be fixed by changing the module compiler option to e.g. es2015.

3
AlokeT On

You can add this where you have need greater time than jasmine default time.

  beforeEach(async(() => {
    jasmine.DEFAULT_TIMEOUT_INTERVAL = <whatever time your test need to complete>;
  }));

and also you can check this answer if this not working. https://stackoverflow.com/a/37969873/1931563

2
Victor Bredihin On

I had the same problem and tried everything - nothing works except adding this option to my karma.conf.js:

browserNoActivityTimeout: 400000
0
Rafał Polak On

I had a similar problem on Chrome 85.0.4183. I don't know why Karma lose connection with browser and I get "Disconnected, because of no message in 30000 ms."

I've added this to Karma.conf:

captureTimeout: 210000,
browserDisconnectTolerance: 3, 
browserDisconnectTimeout : 210000,
browserNoActivityTimeout : 210000

now it works, hope this will help you

0
tschumann On

It failed for me because I was setting window.location.href in my component, but the test run just hung at random times rather than failing in the test for my component.

0
Abdessattar NOISSI On

Check the log of karma, when there is a compilation errors in test files, the karma server return as a timeout error and not the real error

0
Olha Ivanova On

In my case after updating basic angular libraries chrome driver started to work properly.

"devDependencies": {
        "@angular-devkit/build-angular": "15.1.1", #was
        "@angular-devkit/build-angular": "^15.2.10", #became
        "@angular/cli": "15.1.1",   #was
        "@angular/cli": "^15.2.10", #became