I'm using karma along with karma-typescript (but this isn't an Angular project, so I'm not using angular-cli).
About half of my test runs generate an error after all of the tests have passed, and I'm stumped as to how to proceed. Here's the output.
$ karma start karma.conf.js --single-run --jenkins
21 02 2019 09:43:38.104:INFO [compiler.karma-typescript]: Compiling project using Typescript 3.2.4
21 02 2019 09:43:53.795:INFO [compiler.karma-typescript]: Compiled 21 files in 15446 ms.
21 02 2019 09:43:57.633:INFO [bundler.karma-typescript]: Bundled imports for 21 file(s) in 3328 ms.
21 02 2019 09:43:59.695:INFO [karma-server]: Karma v4.0.0 server started at http://0.0.0.0:9876/
21 02 2019 09:43:59.720:INFO [launcher]: Launching browsers ChromeHeadless with concurrency unlimited
21 02 2019 09:43:59.757:INFO [launcher]: Starting browser ChromeHeadless
21 02 2019 09:44:01.220:INFO [HeadlessChrome 72.0.3626 (Windows 10.0.0)]: Connected on socket 16JL3Xy0xm-ri3aBAAAA with id 59122393
HeadlessChrome 72.0.3626 (Windows 10.0.0): Executed 0 of 110 SUCCESS (0 secs / 0 secs)
[1A[2KHeadlessChrome 72.0.3626 (Windows 10.0.0): Executed 1 of 110 SUCCESS (0 secs / 0.061 secs)
...
[1A[2KHeadlessChrome 72.0.3626 (Windows 10.0.0): Executed 110 of 110 SUCCESS (2.695 secs / 2.341 secs)
TOTAL: 110 SUCCESS
21 02 2019 09:44:05.251:ERROR [karma-server]: { Error: read ECONNRESET
at TCP.onStreamRead (internal/stream_base_commons.js:111:27) errno: 'ECONNRESET', code: 'ECONNRESET', syscall: 'read' }
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command
(The --jenkins flag is used in my karma.conf.js primarily to determine whether ChromeHeadless is used instead of Chrome -- see below).
I'm fairly certain that this error isn't coming from my code.
Relevant packages:
"@types/jasmine": "^3.3.8",
"@types/jasminewd2": "^2.0.6",
"awesome-typescript-loader": "^5.2.1",
"jasmine": "^3.3.1",
"jasmine-core": "^3.3.0",
"karma": "^4.0.0",
"karma-chrome-launcher": "^2.2.0",
"karma-cli": "^2.0.0",
"karma-jasmine": "^2.0.1",
"karma-jasmine-html-reporter": "^1.4.0",
"karma-junit-reporter": "^1.2.0",
"karma-typescript": "^4.0.0",
"ts-loader": "^5.3.3",
"typescript": "^3.2.4"
Finally, here's my karma.conf.js:
module.exports = function(config) {
const jenkins = config.jenkins;
config.set({
basePath: '',
frameworks: ["jasmine", "karma-typescript"],
plugins: [
require('karma-jasmine'),
require("karma-chrome-launcher"),
require("karma-typescript"),
jenkins ? require('karma-junit-reporter') : require('karma-jasmine-html-reporter')
],
client:{
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
files: [
"src/**/*.ts"
],
preprocessors: {
"src/**/*.ts": "karma-typescript"
},
reporters: [
'progress', (jenkins ? 'junit' : 'kjhtml'), 'karma-typescript'
],
browsers: [jenkins ? 'ChromeHeadless' : 'Chrome'],
karmaTypescriptConfig: {
tsconfig: "./tsconfig.json",
coverageOptions: {
exclude: [/mock/, /\.spec\.ts$/, /testing-utils/]
}
},
colors: !jenkins,
logLevel: config.LOG_INFO,
autoWatch: !jenkins,
singleRun: jenkins,
junitReporter: {
outputDir: 'karma-results',
outputFile: 'karma-results.xml'
}
});
};

I apologize that I can't help with debugging errors in general from the karma-server. However, if anybody is experiencing a similar error message I can maybe provide a little extra insight based on my experience with this error.
I recently got a very similar error (with karma 6.3.4, and jasmine 3.9.0):
While the error message sadly doesn't point to a specific unit test. I determined that some of our unit tests were using a provider for WEBSOCKETs:
Simply changing these to use a mocked up provider instead of a real WebSocket seems to have solved the problem. Something along the lines of:
Since we still have some web sockets using the real provider that don't seem to cause this problem. It is also just a likely that we just need to make sure we are properly closing our web sockets during these particular units tests rather than waiting and letting Karma deal with our garbage.
On a side note, there is a pending pull request in the Karma repository to hide this error message. However, it appears that the submitter has abandoned making the changes recommended in the review so it might be a long time before the code makes it into the master.