karma: AutoWatch doesn't work

If I run:

karma start karma.conf.js --auto-watch --browsers Chrome --runner-port 9090 --no-single-run

Karma doesn’t react to file changes. Here are relevant files: package.json:

{
    "name": "test-app",
    "version": "0.1.0",
    "devDependencies": {
        "connect-modrewrite": "0.5.11",
        "findup-sync": "0.1.2",
        "grunt": "0.4.2",
        "grunt-angular-templates": "0.5.1",
        "grunt-autoprefixer": "0.6.4",
        "grunt-check-dependencies": "0.3.0",
        "grunt-concurrent": "0.4.3",
        "grunt-continue": "0.0.1",
        "grunt-contrib-clean": "0.5.0",
        "grunt-contrib-compass": "0.7.0",
        "grunt-contrib-concat": "0.3.0",
        "grunt-contrib-connect": "0.6.0",
        "grunt-contrib-copy": "0.5.0",
        "grunt-contrib-htmlmin": "0.1.3",
        "grunt-contrib-jshint": "0.7.2",
        "grunt-contrib-uglify": "0.3.1",
        "grunt-contrib-watch": "0.5.3",
        "grunt-csso": "0.5.3",
        "grunt-ddescribe-iit": "0.0.4",
        "grunt-defs": "0.6.1",
        "grunt-jsonlint": "1.0.4",
        "grunt-karma": "0.6.2",
        "grunt-merge-conflict": "0.0.2",
        "grunt-newer": "0.6.1",
        "grunt-ng-annotate": "0.0.4",
        "grunt-notify": "0.2.17",
        "grunt-protractor-runner": "0.2.1",
        "grunt-rev": "0.1.0",
        "grunt-shell": "0.6.2",
        "grunt-usemin": "2.0.2",
        "jasmine-reporters": "0.2.1",
        "karma": "0.10.9",
        "karma-chrome-launcher": "0.1.2",
        "karma-coverage": "0.1.4",
        "karma-firefox-launcher": "0.1.3",
        "karma-jasmine": "0.1.5",
        "karma-junit-reporter": "0.2.1",
        "karma-ng-json2js-preprocessor": "0.0.5",
        "karma-opera-launcher": "0.1.0",
        "libxmljs": "0.8.1",
        "load-grunt-tasks": "0.2.1",
        "protractor": "0.16.1"
    }
}

karma.conf.js:

'use strict';

module.exports = function (config) {
    require('./karma-shared.conf')(config);

    config.set({
        // list of files / patterns to load in the browser
        files: config.files.concat([
            'app/vendor/l20n-*/l20n.js',
            'app/vendor/jquery-*/jquery.js',
            'app/vendor/lodash-*/lodash.custom.js',
            'app/vendor/modernizr-*/modernizr-custom.js',
            'app/vendor/bootstrap-*/bootstrap.js',
            'app/vendor/bootstrap-tagsinput/bootstrap-tagsinput.js',
            'app/vendor/typeahead.js-*/typeahead.js',
            'app/vendor/seadragon/seadragon.js',

            'app/vendor/angular-*/angular/angular.js',
            'app/vendor/angular-*/angular-*/angular-*.js',

            'app/vendor/placeholders-*/placeholders-*.js',
            'app/vendor/ng-l20n/ng-l20n.js',
            'app/vendor/google-analytics/tracking-code.js',
            'app/vendor/angulartics-0.8.5/angulartics.js',
            'app/vendor/ng-tags-input-8d243e5ad0-fork/ng-tags-input.js',

            'app/lib/polyfill.defs.js',
            'app/lib/key_codes.defs.js',
            'app/lib/jquery.dotdotdot-1.5.6-modified.defs.js',

            'app/cbn-modules/**/*.defs.js',
            'app/app.defs.js',

            'test/templates.js',
        ]).concat(config.bottomFiles),

        exclude: config.exclude.concat([
            'app/**/*.min.js',
        ]),
    });
};

karma-shared.conf.js:

'use strict';

module.exports = function (config) {
    var preprocessors = config.preprocessors;
    preprocessors['**/*.json'] = 'json2js';

    config.set({
        frameworks: ['jasmine'],
        basePath: '',
        files: [
            'test/settings.js',
        ],
        bottomFiles: [
            'test/mocks-inlined/*.json',
            'test/vendor/**/*.js',
            'test/{lib,mock,unit}/**/*.defs.js',
        ],
        exclude: [],
        preprocessors: preprocessors,
        plugins: config.plugins.concat([
            'karma-ng-json2js-preprocessor',
        ]),
        reporters: ['progress'],
        port: 8080,
        runnerPort: 9100,
        colors: true,
        logLevel: config.LOG_INFO,
        autoWatch: false,
        browsers: ['Chrome', 'Firefox'],
        captureTimeout: 60000,
        singleRun: true,
    });
};

Watched *.defs.js files are generated via grunt-defs. Once a file is generated, Karma doesn’t pick up the change and doesn’t dispatch the tests.

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 33 (11 by maintainers)

Commits related to this issue

Most upvoted comments

Hello all! I was searching why karma doesnt reload when file is changed. Now after 3-5 days of deep research i finally found a reason for this.

It’s not autoWatch, nor usePolling, nor singleRun, nor atomic_save for me.

It’s glob characters in the full path to watched file (in my case it was like C:\!JS\foo\bar.js, notice ‘!’ in the beggining of JS). Reason for this here (https://github.com/paulmillr/chokidar/issues/300 (issue from chokidar, which karma has in dependencies)). So consider to check names of your current working directory and files for ‘!’, ‘*’, ‘[’, ‘{’ and etc.

Hope it helps to save a lot of time for someone because i would be really glad to find my message in the past.

p.s. I decided to write message exactly here because it was the most common page which i was landing during my research 😃

I had the same issue on Intellij. It looks like you have to disable Use ‘safe write’ setting.

@maksimr mentions this is fixed in canary branch, however. I still experience the issue. Here is my workaround. Please let me know if this resolves the issue for anyone else. I’ve only tested this on Chrome, I’m sure similar approaches would work for the other browsers. Once you enter karma start and the browser launches, enable dev tools, check disable cache from the network tab. With the cache completely disabled, chrome no longer gets a cached version of the spec files.

Here’s what breaking it, imho: https://github.com/karma-runner/karma/commit/e88fbc24dd34e7976cae2547bad07e6f044a768b

If I set usePolling to true it works.

Now I just have to understand why it doesn’t work with usePolling=false;