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'
}
});
};
From a related answer I used the javascript-karma-verbose-reporter plugin to solve this.
The setup seems to differ quite a lot between different answers/comments. For me, running locally (not in Jenkins, Gulp etc), I ran
By installing this my current version of karma (v4.4.1) recognises that there is a plugin and I didn't need to use the
plugins
section ofkarma.conf.js
.Then add
karma-verbose-reporter
to thereporters
array inkarma.conf.js
:How this is relevant to your question is the output it gives (which isn't in the related answer). This is a section of my output, I'm using a screenshot as the colours are very helpful:
You can see that the
ERROR
gets repeated twice. The second time it is neatly bound to the name of the test where the error occurs: