Marco Pracucci

Avoid karma tests running twice on autoWatch

by Marco Pracucci Comments

I’m working on a new application since few weeks, whose tests run with karma. Karma is configured with autoWatch: true, so tests automatically run each time any file changes.

Unfortunately, tests did run twice each time I changed any file. It was quite annoying but I’ve always been too lazy to investigate it, until today.

After digging a bit on Google, I’ve found a GitHub issue with a PR fixing the same issue. The fix is actually straightforward: you should define files using the extended syntax and set watched: false for your tests / specs (they will still kept watched by autoWatch: true).

const karmaConfig = {
    autoWatch: true,
    files: [
        { pattern: "app/**/*_spec.js", watched: false, served: true, included: true }
    ]
};

Upcoming conferences

I will join the following conferences. Reach me out on Twitter if you wanna meet:
Incontro DevOps 2020 Virtual 22 October 2020

Comments