Skip to content
This repository was archived by the owner on Jun 24, 2025. It is now read-only.

Commit 9526da4

Browse files
committed
Fix Windows CI
1 parent 78ab937 commit 9526da4

File tree

9 files changed

+42
-33
lines changed

9 files changed

+42
-33
lines changed

index.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ function normalizeGlobs(globs) {
2727
return globs;
2828
}
2929

30-
module.exports = function (globs, opts, cb) {
30+
function watch(globs, opts, cb) {
3131
globs = normalizeGlobs(globs);
3232

3333
if (typeof opts === 'function') {
3434
cb = opts;
3535
opts = {};
3636
}
3737

38-
opts = assign({}, opts);
38+
opts = assign({}, watch._defaultOptions, opts);
3939
cb = cb || function () {};
4040

4141
function resolveFilepath(filepath) {
@@ -57,14 +57,6 @@ module.exports = function (globs, opts, cb) {
5757
}
5858
globs = globs.map(resolveGlob);
5959

60-
opts.events = opts.events || ['add', 'change', 'unlink'];
61-
62-
if (opts.ignoreInitial === undefined) {
63-
opts.ignoreInitial = true;
64-
}
65-
66-
opts.readDelay = opts.readDelay || 10;
67-
6860
var baseForced = Boolean(opts.base);
6961
var outputStream = new Duplex({objectMode: true, allowHalfOpen: true});
7062

@@ -164,4 +156,16 @@ module.exports = function (globs, opts, cb) {
164156
}
165157

166158
return outputStream;
159+
}
160+
161+
// This is not part of the public API as that would lead to global state (singleton) pollution,
162+
// and allow unexpected interference between unrelated modules that make use of gulp-watch.
163+
// This can be useful for unit tests and root application configuration, though.
164+
// Avoid modifying gulp-watch's default options inside a library/reusable package, please.
165+
watch._defaultOptions = {
166+
events: ['add', 'change', 'unlink'],
167+
ignoreInitial: true,
168+
readDelay: 10
167169
};
170+
171+
module.exports = watch;

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
"gulpplugin"
1010
],
1111
"scripts": {
12-
"test": "xo && mocha -R spec test/test-*",
13-
"coverage": "istanbul cover node_modules/.bin/_mocha --report html -- -R spec",
14-
"coveralls": "istanbul cover _mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | coveralls && rm -rf ./coverage"
12+
"test": "xo && mocha -r test/util/set-default-options -R spec test/test-*",
13+
"coverage": "istanbul cover node_modules/.bin/_mocha --report html -- -r test/util/set-default-options -R spec",
14+
"coveralls": "istanbul cover _mocha --report lcovonly -- -r test/util/set-default-options -R spec && cat ./coverage/lcov.info | coveralls && rm -rf ./coverage"
1515
},
1616
"files": [
1717
"index.js"

test/test-api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('api', function () {
2323
});
2424

2525
it('should emit added file', function (done) {
26-
w = watch(fixtures('*/*.js'));
26+
w = watch(fixtures('folder'));
2727
w.add(fixtures('*.js'));
2828
w.on('data', function (file) {
2929
file.relative.should.eql('new.js');

test/test-base.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
var watch = require('..');
44
var path = require('path');
5-
var rimraf = require('rimraf');
65
var touch = require('./touch.js');
76
require('should');
87

@@ -14,7 +13,6 @@ describe('base', function () {
1413
var w;
1514

1615
afterEach(function (done) {
17-
rimraf.sync(fixtures('newDir'));
1816
w.on('end', done);
1917
w.close();
2018
});

test/test-callback.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ describe('callback', function () {
1515
var w;
1616

1717
afterEach(function (done) {
18-
rimraf.sync(fixtures('newDir'));
19-
w.on('end', done);
18+
w.on('end', function () {
19+
rimraf.sync(fixtures('newDir'));
20+
done();
21+
});
2022
w.close();
2123
});
2224

@@ -37,8 +39,6 @@ describe('callback', function () {
3739
});
3840

3941
it('should be called on add event in new directory', function (done) {
40-
rimraf.sync(fixtures('newDir'));
41-
4242
w = watch(fixtures('**/*.ts'), function (file) {
4343
file.relative.should.eql(path.normalize('newDir/index.ts'));
4444
done();

test/test-cwd.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
var watch = require('..');
44
var path = require('path');
5-
var rimraf = require('rimraf');
65
var touch = require('./touch.js');
76
require('should');
87

@@ -14,7 +13,6 @@ describe('cwd', function () {
1413
var w;
1514

1615
afterEach(function (done) {
17-
rimraf.sync(fixtures('newDir'));
1816
w.on('end', done);
1917
w.close();
2018
});

test/test-dir.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ describe('dir', function () {
1515
var w;
1616

1717
afterEach(function (done) {
18-
rimraf.sync(fixtures('newDir'));
19-
w.on('end', done);
18+
w.on('end', function () {
19+
rimraf.sync(fixtures('newDir'));
20+
done();
21+
});
2022
w.close();
2123
});
2224

test/test-ignore.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* global describe, it, before, after */
1+
/* global describe, it, afterEach */
22

33
var watch = require('..');
44
var join = require('path').join;
@@ -14,13 +14,17 @@ function fixtures(glob) {
1414
describe('ignore', function () {
1515
var w;
1616

17-
before(function () {
18-
rimraf.sync(fixtures('temp'));
17+
afterEach(function (done) {
18+
w.on('end', function () {
19+
rimraf.sync(fixtures('temp'));
20+
done();
21+
});
22+
w.close();
1923
});
2024

21-
it('should ignore non-existent folders', function (done) {
25+
it('should ignore files', function (done) {
2226
w = watch([fixtures('**/*.ts'), '!**/*.js'], function () {
23-
done('Ignored folder was watched');
27+
done('Ignored file was watched');
2428
});
2529

2630
w.on('ready', function () {
@@ -29,8 +33,4 @@ describe('ignore', function () {
2933
setTimeout(done, 200);
3034
});
3135
});
32-
33-
after(function () {
34-
rimraf.sync(fixtures('temp'));
35-
});
3636
});

test/util/set-default-options.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict';
2+
3+
var watch = require('../..');
4+
5+
if (process.platform === 'win32') {
6+
watch._defaultOptions.ignorePermissionErrors = true;
7+
}

0 commit comments

Comments
 (0)