Skip to content

Commit

Permalink
Watch hidden files based on extension
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Scholtes committed Sep 5, 2019
1 parent 5d746bb commit 0e2ee09
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/cli/watch-run.js
Expand Up @@ -30,7 +30,10 @@ const collectFiles = require('./collect-files');
*/
module.exports = (mocha, {watchFiles, watchIgnore}, fileCollectParams) => {
if (!watchFiles) {
watchFiles = fileCollectParams.extension.map(ext => `**/*.${ext}`);
watchFiles = fileCollectParams.extension.reduce(
(watchFiles, ext) => watchFiles.concat([`**/*.${ext}`, `**/.*.${ext}`]),
[]
);
}

const watcher = chokidar.watch(watchFiles, {
Expand Down
18 changes: 18 additions & 0 deletions test/integration/options/watch.spec.js
Expand Up @@ -137,6 +137,24 @@ describe('--watch', function() {
});
});

it('reruns test when file starting with . and matching --extension is changed', function() {
const testFile = path.join(this.tempDir, 'test.js');
copyFixture('__default__', testFile);

const watchedFile = path.join(this.tempDir, '.file.xyz');
touchFile(watchedFile);

return runMochaWatch(
[testFile, '--extension', 'xyz,js'],
this.tempDir,
() => {
touchFile(watchedFile);
}
).then(results => {
expect(results, 'to have length', 2);
});
});

it('ignores files in "node_modules" and ".git" by default', function() {
const testFile = path.join(this.tempDir, 'test.js');
copyFixture('__default__', testFile);
Expand Down

0 comments on commit 0e2ee09

Please sign in to comment.