Skip to content

Commit

Permalink
CLI: Add slight debounce to restarting tests on file watching
Browse files Browse the repository at this point in the history
  • Loading branch information
trentmwillis committed Sep 25, 2017
1 parent fe24c04 commit dd1c66c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
30 changes: 18 additions & 12 deletions bin/run.js
Expand Up @@ -9,6 +9,7 @@ const utils = require( "./utils" );
const IGNORED_GLOBS = [
"**/node_modules/**"
];
const RESTART_DEBOUNCE_LENGTH = 200;

let QUnit;

Expand Down Expand Up @@ -92,21 +93,26 @@ function run( args, options ) {
};

run.restart = function( args ) {
const watchedFiles = walkSync( process.cwd(), {
globs: [ "**/*.js" ],
directories: false,
ignore: IGNORED_GLOBS
} );
clearTimeout( this._restartDebounceTimer );

watchedFiles.forEach( file => delete require.cache[ path.resolve( file ) ] );
this._restartDebounceTimer = setTimeout( () => {

if ( QUnit.config.queue.length ) {
console.log( "Finishing current test and restarting..." );
} else {
console.log( "Restarting..." );
}
const watchedFiles = walkSync( process.cwd(), {
globs: [ "**/*.js" ],
directories: false,
ignore: IGNORED_GLOBS
} );

watchedFiles.forEach( file => delete require.cache[ path.resolve( file ) ] );

if ( QUnit.config.queue.length ) {
console.log( "Finishing current test and restarting..." );
} else {
console.log( "Restarting..." );
}

run.abort( () => run.apply( null, args ) );
run.abort( () => run.apply( null, args ) );
}, RESTART_DEBOUNCE_LENGTH );
};

run.abort = function( callback ) {
Expand Down
6 changes: 4 additions & 2 deletions test/cli/fixtures/expected/watch-tap-outputs.js
Expand Up @@ -91,15 +91,17 @@ ok 1 Module > Test
# todo 0
# fail 0
File changed: watching/tests/foo.js
Restarting...
File added: watching/bar.js
Finishing current test and restarting...
Restarting...
TAP version 13
ok 1 Module > Test
1..1
# pass 1
# skip 0
# todo 0
# fail 0
File changed: watching/bar.js
Restarting...
TAP version 13
ok 1 Module > Test
1..1
Expand Down

0 comments on commit dd1c66c

Please sign in to comment.