Karma tests running twice on change
September 03, 2015
My current project’s been plagued with duplicate test runs on a single file change. We’re using webpack and karma, and it’s a documented problem. Someone pointed me to a solution that worked for browserify + karma setup, and it turned out to work for my situation too!
Since our karma-webpack config was processing any .js, .es6 or .jsx file, a change in a spec file was triggering a change there, on top of karma triggering a change on the files it was serving to the browser. A quick patch to the list of files karma handles disabled watching of the spec files, while continuing to serve them:
// in karma.conf.js
{
files: [
// ... other files paths
{
pattern: './path/to/tests/**/*.js',
watched: false,
included: true,
served: true,
},
]
}
And the rest was history.
Hey, I'm Ian. I build websites and write about what I learn as I go. Follow me on Twitter.