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 }
    ]
};

RSS Feed

To get a notification each time a new article gets published, type the following command on your Slack: /feed subscribe https://pracucci.com/feed.xml

Comments