Skip to content

Add autoWatchDelay option #2331

@danielcompton

Description

@danielcompton
Contributor

Problem

When incrementally recompiling ClojureScript, many files are changed as the compilation process runs. Currently, it is difficult to use Karma to autorun tests after detecting a ClojureScript recompile, because as soon as the first file is changed, Karma wants to rerun the tests.

Current behaviour

There is a config option autoWatchBatchDelay available which at first seems like it would be ideal for this use case. It starts a timer after it detects the first file system change, and waits n milliseconds before running tests. It is possible to use this option, but it is suboptimal.

The timer starts from the first change detected, so when configuring this parameter, I need to specify what the maximum time my ClojureScript compile could take, so it doesn't start rerunning while recompiling. I can shoot for a low number that my app will recompile in (say 1 second), but then will hit problems if an incremental recompile takes longer (which happens from time to time when editing certain files).

Proposed behaviour

I propose that there is a new option autoWatchDelay (or perhaps changing the behaviour of the current option) to start the delay timer from the last filesystem change detected, waiting n more milliseconds before starting the tests. In practice this might look like resetting the timer, each time a new file change was detected.

IMHO this behaviour is probably closer to what most people are wanting when they use autoWatchBatchDelay.

Activity

nschipperbrainsmith

nschipperbrainsmith commented on Sep 22, 2016

@nschipperbrainsmith

Think the thing most of us would like to have is a system that allows us to debounce the incoming changes till no further changes have occurred for an x amount of ms.

A perfect example of this is illustrated within RXJS:
http://reactivex.io/documentation/operators/debounce.html

Having an option like that would be very useful.

Stand alone version of debounce:
https://davidwalsh.name/javascript-debounce-function

Which would mean the following function probably would have to be modified:

https://github.com/karma-runner/karma/blob/master/lib/watcher.js#L93

Once i change the bind function to this i have the desired behaviour:

    function bind(func, wait, immediate) {
        var timeout;
        return function(path) {
            var context = this, args = arguments;
            var later = function() {
                timeout = null;
                if (!immediate) func.call(fileList, helper.normalizeWinPath(path));// func.apply(context, args);
            };
            var callNow = immediate && !timeout;
            clearTimeout(timeout);
            timeout = setTimeout(later, wait);
            if (callNow) func.call(fileList, helper.normalizeWinPath(path));
        };
    };

    chokidarWatcher.on('add', bind(fileList.addFile, 1000))
        .on('change', bind(fileList.changeFile, 1000))
        .on('unlink', bind(fileList.removeFile, 1000))
danielcompton

danielcompton commented on Sep 22, 2016

@danielcompton
ContributorAuthor

@schippie this is exactly what I'm after.

dignifiedquire

dignifiedquire commented on Sep 22, 2016

@dignifiedquire
Member

Sounds good to me. I agree it does make sense to change the option to this behaviour.

ghost
danielcompton

danielcompton commented on Oct 25, 2016

@danielcompton
ContributorAuthor

awaitWriteFinish looks useful and may be helpful, but wouldn't solve this problem on it's own probably. I still need to handle the case where multiple files are written in one recompile cycle.

ghost
added a commit that references this issue on Feb 8, 2017
4e4cdb0
added a commit that references this issue on Feb 9, 2017
0b99191
added 4 commits that reference this issue on May 7, 2017
5ae3254
64ee461
7d906f7
7acc12c

7 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Add autoWatchDelay option · Issue #2331 · karma-runner/karma