Skip to content

Commit 61848ee

Browse files
novemberbornsindresorhus
authored andcommitted
watcher: fix recursive test file matcher
The watcher used dir**/*.js as the recursive pattern when the initial pattern matched a directory. This should be dir/**/*.js instead. Before this fix tests were matched as sources, causing all tests to be rerun.
1 parent 37c67b9 commit 61848ee

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

lib/watcher.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ function makeTestMatcher(files, excludePatterns) {
369369
return multimatch(subpath, initialPatterns).length === 1;
370370
}).map(function (subpath) {
371371
// Always use / to makes multimatch consistent across platforms.
372-
return subpath + '**/*.js';
372+
return subpath + '/**/*.js';
373373
});
374374

375375
// See if the entire path matches any of the subpaths patterns, taking the

test/watcher.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -478,16 +478,21 @@ group('chokidar is installed', function (beforeEach, test, group) {
478478
test('files patterns may match directories', function (t) {
479479
t.plan(2);
480480

481-
files = ['dir', 'dir2/*/dir3'];
481+
files = ['dir', 'another-dir/*/deeper'];
482482
api.run.returns(Promise.resolve());
483483
start();
484484

485-
add(path.join('dir', 'foo.js'));
486-
add(path.join('dir2', 'foo', 'dir3', 'bar.js'));
487-
return debounce(2).then(function () {
485+
add(path.join('dir', 'test.js'));
486+
add(path.join('dir', 'nested', 'test.js'));
487+
add(path.join('another-dir', 'nested', 'deeper', 'test.js'));
488+
return debounce(3).then(function () {
488489
t.ok(api.run.calledTwice);
489490
t.same(api.run.secondCall.args, [
490-
[path.join('dir', 'foo.js'), path.join('dir2', 'foo', 'dir3', 'bar.js')],
491+
[
492+
path.join('dir', 'test.js'),
493+
path.join('dir', 'nested', 'test.js'),
494+
path.join('another-dir', 'nested', 'deeper', 'test.js')
495+
],
491496
{runOnlyExclusive: false}
492497
]);
493498
});

0 commit comments

Comments
 (0)