Skip to content

Commit

Permalink
Fix and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Molinaro committed Jun 14, 2021
1 parent 77ec651 commit 8bcee15
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/watchpack.js
Expand Up @@ -26,7 +26,7 @@ function addWatchersToSet(watchers, set) {

const stringOrRegexpToRegexp = ignored => {
if (ignored instanceof RegExp) {
return ignored;
return ignored.source;
}
const { source } = globToRegExp(ignored, { globstar: true, extended: true });
const matchingStart = source.slice(0, source.length - 1) + "(?:$|\\/)";
Expand Down
26 changes: 26 additions & 0 deletions test/Watchpack.js
Expand Up @@ -118,6 +118,32 @@ describe("Watchpack", function() {
});
});

it("should not watch a single ignored file (array with regexp and glob)", function(done) {
var w = new Watchpack({
aggregateTimeout: 300,
ignored: [/\/a$/, "**/b"]
});
var changeEvents = 0;
var aggregatedEvents = 0;
w.on("change", () => {
changeEvents++;
});
w.on("aggregated", () => {
aggregatedEvents++;
});
w.watch([path.join(fixtures, "a")], []);
testHelper.tick(() => {
testHelper.file("a");
testHelper.tick(1000, () => {
changeEvents.should.be.eql(0);
aggregatedEvents.should.be.eql(0);
testHelper.getNumberOfWatchers().should.be.eql(0);
w.close();
done();
});
});
});

it("should watch multiple files", function(done) {
var w = new Watchpack({
aggregateTimeout: 1000
Expand Down

0 comments on commit 8bcee15

Please sign in to comment.