From 4fca711c6adfa4fe7ae7d87462aeb1cc4cf9592c Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Thu, 15 Nov 2018 17:47:33 -0700 Subject: [PATCH] Fix: Merge `opt.ignored` and our custom ignore function (fixes #40) --- index.js | 3 ++- test/index.js | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 109ba28..5112fd5 100644 --- a/index.js +++ b/index.js @@ -10,6 +10,7 @@ var anymatch = require('anymatch'); var defaultOpts = { delay: 200, events: ['add', 'change', 'unlink'], + ignored: [], ignoreInitial: true, queue: true, }; @@ -85,7 +86,7 @@ function watch(glob, options, cb) { var toWatch = positives.filter(exists); - opt.ignored = shouldBeIgnored; + opt.ignored = [].concat(opt.ignored, shouldBeIgnored); var watcher = chokidar.watch(toWatch, opt); function runComplete(err) { diff --git a/test/index.js b/test/index.js index 035af17..1db59ac 100644 --- a/test/index.js +++ b/test/index.js @@ -319,4 +319,25 @@ describe('glob-watcher', function() { done(); }); + + it('passes ignores through to chokidar', function(done) { + var ignored = [singleAdd]; + watcher = watch(outGlob, { + ignored: ignored, + }); + + watcher.once('change', function(filepath) { + // It should never reach here + expect(filepath).toNotExist(); + done(); + }); + + // We default `ignoreInitial` to true, so always wait for `on('ready')` + watcher.on('ready', changeFile); + + // Just test the non-mutation in this test + expect(ignored.length).toEqual(1); + + setTimeout(done, 1500); + }); });