Karma Disconnected, because no message in 10000 ms
Solution 1
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
.
Solution 2
I had the same problem and tried everything - nothing works except adding this option to my karma.conf.js
:
browserNoActivityTimeout: 400000
Solution 3
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.
Solution 4
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 add this to Karma.conf:
captureTimeout: 210000,
browserDisconnectTolerance: 3,
browserDisconnectTimeout : 210000,
browserNoActivityTimeout : 210000
now it works, hope this will help you
chris
Updated on June 08, 2022Comments
-
chris almost 2 years
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.
-
Aluan Haddad over 5 yearsNo. It isn't a bug at all.
import CustomerTypeEnum = CustomerDto.CustomerTypeEnum;
is not an import at all. It is a syntax for aliasing a member of a TypeScript namespace. Such namespaces can exist in both the value space and the types space. SinceCustomerTypeEnum
is a value as well as a type, a variable assignment is emitted by the compiler with an initializer referencing a property of an object it isn't defined yet. This depends to some extent on your output module format. Look at the actual compiled code and you'll see exactly what is happening and why. -
Aluan Haddad over 5 yearsThe TypeScript compiler should probably flag this as an error, but it will only fail in certain module formats.
-
chris over 5 yearsThanks for this input, I adjusted my answer based on your input. I agree that the TypeScript compiler should flag this as an error or at least give a warning.
-
Aluan Haddad over 5 yearsIt's actually not related to
--moduleResolution
or--target
but to--module
. But the possible difference based on that flag is really a side issue. Ultimately, what you're doing is using the value before it is available, and the compiler should warn you, but the order that works is also the logical order - imports should be lexically before their usage if for no other reason than clarity. -
chris over 5 yearsTried that already, didn't work in my case. It failed during karma initialization (see my answer below).
-
chris over 5 yearsYes I have, it's definately not a timing issue. It took me a whole day to figure it out because Karma did not report the compiler issue. Changing the
commonjs
module compilerOption toes2015
resolves the problem. -
chris over 5 yearsChanged the answer again: Actually changing
--module
fromcommonjs
toes2015
worked in my codebase and is definately the nicer solution. -
Anshita Singh almost 4 yearsI don't think so its DEFAULT_TIMEOUT_INTERVAL issue. Because sometimes I am seeing even though my test cases have not even started running and after just karma launcher I am seeing Disconnected issue.