Skip to content

Commit

Permalink
fix: handle an empty array for the ignored option
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Aug 13, 2024
1 parent 585ebf9 commit cb9ab82
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/watchpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ const stringToRegexp = ignored => {

const ignoredToFunction = ignored => {
if (Array.isArray(ignored)) {
if (ignored.length === 0) {
return () => false;
}
const regexp = new RegExp(ignored.map(i => stringToRegexp(i)).join("|"));
return x => regexp.test(x.replace(/\\/g, "/"));
} else if (typeof ignored === "string") {
Expand Down
22 changes: 22 additions & 0 deletions test/Watchpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,28 @@ describe("Watchpack", function() {
});
});

it("should watch a file in a directory when ignore is empty array", function(done) {
var w = new Watchpack({
aggregateTimeout: 300,
ignored: []
});
var changeEvents = 0;
w.on("change", function(file) {
file.should.be.eql(path.join(fixtures, "a"));
changeEvents++;
});
w.on("aggregated", function(changes) {
Array.from(changes).should.be.eql([path.join(fixtures, "a")]);
changeEvents.should.be.greaterThan(0);
w.close();
done();
});
w.watch([path.join(fixtures, "a")], []);
testHelper.tick(function() {
testHelper.file("a");
});
});

it("should watch a file then a directory", function(done) {
var w = new Watchpack({
aggregateTimeout: 1000
Expand Down

0 comments on commit cb9ab82

Please sign in to comment.