Skip to content

Commit 8b7eeef

Browse files
phatedactions-user
authored andcommittedMay 31, 2023
chore: Run prettier
1 parent cbb4b18 commit 8b7eeef

File tree

5 files changed

+94
-97
lines changed

5 files changed

+94
-97
lines changed
 

‎README.md

+10-9
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Watch globs and execute a function upon change, with intelligent defaults for de
1515
```js
1616
var watch = require('glob-watcher');
1717

18-
watch(['./*.js', '!./something.js'], function(done){
18+
watch(['./*.js', '!./something.js'], function (done) {
1919
// This function will be called each time a globbed file is changed
2020
// but is debounced with a 200ms delay (default) and queues subsequent calls
2121

@@ -35,14 +35,14 @@ var watcher = watch(['./*.js', '!./something.js']);
3535

3636
// Listen for the 'change' event to get `path`/`stat`
3737
// No async completion available because this is the raw chokidar instance
38-
watcher.on('change', function(path, stat) {
38+
watcher.on('change', function (path, stat) {
3939
// `path` is the path of the changed file
4040
// `stat` is an `fs.Stat` object (not always available)
4141
});
4242

4343
// Listen for other events
4444
// No async completion available because this is the raw chokidar instance
45-
watcher.on('add', function(path, stat) {
45+
watcher.on('add', function (path, stat) {
4646
// `path` is the path of the changed file
4747
// `stat` is an `fs.Stat` object (not always available)
4848
});
@@ -54,7 +54,7 @@ watcher.on('add', function(path, stat) {
5454

5555
Takes a path string, an array of path strings, a [glob][micromatch] string or an array of [glob][micromatch] strings as `globs` to watch on the filesystem. Also optionally takes `options` to configure the watcher and a `fn` to execute when a file changes.
5656

57-
__Note: As of 5.0.0, globs must use `/` as the separator character because `\\` is reserved for escape sequences (as per the Bash 4.3 & Micromatch specs). This means you can't use `path.join()` or `__dirname` in Windows environments. If you need to use `path.join()`, you can use [normalize-path][normalize-path] against your paths afterwards. If you need to use `__dirname`, you can set it as the `cwd` option that gets passed directly to [chokidar][chokidar]. The [micromatch docs][micromatch-backslashes] contain more information about backslashes.__
57+
**Note: As of 5.0.0, globs must use `/` as the separator character because `\\` is reserved for escape sequences (as per the Bash 4.3 & Micromatch specs). This means you can't use `path.join()` or `**dirname`in Windows environments. If you need to use`path.join()`, you can use [normalize-path][normalize-path] against your paths afterwards. If you need to use `**dirname`, you can set it as the `cwd` option that gets passed directly to [chokidar][chokidar]. The [micromatch docs][micromatch-backslashes] contain more information about backslashes.**
5858

5959
Returns an instance of [chokidar][chokidar].
6060

@@ -63,10 +63,11 @@ Returns an instance of [chokidar][chokidar].
6363
If the `fn` is passed, it will be called when the watcher emits a `change`, `add` or `unlink` event. It is automatically debounced with a default delay of 200 milliseconds and subsequent calls will be queued and called upon completion. These defaults can be changed using the `options`.
6464

6565
The `fn` is passed a single argument, `callback`, which is a function that must be called when work in the `fn` is complete. Instead of calling the `callback` function, [async completion][async-completion] can be signalled by:
66-
* Returning a `Stream` or `EventEmitter`
67-
* Returning a `Child Process`
68-
* Returning a `Promise`
69-
* Returning an `Observable`
66+
67+
- Returning a `Stream` or `EventEmitter`
68+
- Returning a `Child Process`
69+
- Returning a `Promise`
70+
- Returning an `Observable`
7071

7172
Once async completion is signalled, if another run is queued, it will be executed.
7273

@@ -76,7 +77,7 @@ Once async completion is signalled, if another run is queued, it will be execute
7677

7778
If set to `false` the `fn` is called during [chokidar][chokidar] instantiation as it discovers the file paths. Useful if it is desirable to trigger the `fn` during startup.
7879

79-
__Passed through to [chokidar][chokidar], but defaulted to `true` instead of `false`.__
80+
**Passed through to [chokidar][chokidar], but defaulted to `true` instead of `false`.**
8081

8182
Type: `Boolean`
8283

‎lib/debounce.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ function debounce(fn, delay) {
55
var args;
66
var self;
77

8-
return function() {
8+
return function () {
99
self = this;
1010
args = arguments;
1111
clear();

‎test/index.js

+55-56
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ var watch = require('../');
1414
// Default delay on debounce
1515
var timeout = 200;
1616

17-
describe('glob-watcher', function() {
18-
17+
describe('glob-watcher', function () {
1918
var watcher;
2019

2120
var outDir = path.join(__dirname, './fixtures/');
@@ -34,27 +33,27 @@ describe('glob-watcher', function() {
3433
fs.writeFileSync(outFile2, 'hello added');
3534
}
3635

37-
beforeEach(function(cb) {
36+
beforeEach(function (cb) {
3837
fs.mkdirSync(outDir);
3938
fs.writeFileSync(outFile1, 'hello world');
4039
cb();
4140
});
4241

43-
afterEach(function(cb) {
42+
afterEach(function (cb) {
4443
if (watcher) {
4544
watcher.close();
4645
}
4746
rimraf(outDir, cb);
4847
});
4948

50-
after(function(cb) {
49+
after(function (cb) {
5150
rimraf(outDir, cb);
5251
});
5352

54-
it('only requires a glob and returns watcher', function(done) {
53+
it('only requires a glob and returns watcher', function (done) {
5554
watcher = watch(outGlob);
5655

57-
watcher.once('change', function(filepath) {
56+
watcher.once('change', function (filepath) {
5857
expect(filepath).toEqual(outFile1);
5958
done();
6059
});
@@ -63,10 +62,10 @@ describe('glob-watcher', function() {
6362
watcher.on('ready', changeFile);
6463
});
6564

66-
it('picks up added files', function(done) {
65+
it('picks up added files', function (done) {
6766
watcher = watch(outGlob);
6867

69-
watcher.once('add', function(filepath) {
68+
watcher.once('add', function (filepath) {
7069
expect(filepath).toEqual(outFile2);
7170
done();
7271
});
@@ -75,10 +74,10 @@ describe('glob-watcher', function() {
7574
watcher.on('ready', addFile);
7675
});
7776

78-
it('works with OS-specific cwd', function(done) {
77+
it('works with OS-specific cwd', function (done) {
7978
watcher = watch('./fixtures/' + globPattern, { cwd: __dirname });
8079

81-
watcher.once('change', function(filepath) {
80+
watcher.once('change', function (filepath) {
8281
// Uses path.join here because the resulting path is OS-specific
8382
expect(filepath).toEqual(path.join('fixtures', 'changed.js'));
8483
done();
@@ -88,8 +87,8 @@ describe('glob-watcher', function() {
8887
watcher.on('ready', changeFile);
8988
});
9089

91-
it('accepts a callback & calls when file is changed', function(done) {
92-
watcher = watch(outGlob, function(cb) {
90+
it('accepts a callback & calls when file is changed', function (done) {
91+
watcher = watch(outGlob, function (cb) {
9392
cb();
9493
done();
9594
});
@@ -98,8 +97,8 @@ describe('glob-watcher', function() {
9897
watcher.on('ready', changeFile);
9998
});
10099

101-
it('accepts a callback & calls when file is added', function(done) {
102-
watcher = watch(outGlob, function(cb) {
100+
it('accepts a callback & calls when file is added', function (done) {
101+
watcher = watch(outGlob, function (cb) {
103102
cb();
104103
done();
105104
});
@@ -108,13 +107,13 @@ describe('glob-watcher', function() {
108107
watcher.on('ready', addFile);
109108
});
110109

111-
it('waits for completion is signaled before running again', function(done) {
110+
it('waits for completion is signaled before running again', function (done) {
112111
var runs = 0;
113112

114-
watcher = watch(outGlob, function(cb) {
113+
watcher = watch(outGlob, function (cb) {
115114
runs++;
116115
if (runs === 1) {
117-
setTimeout(function() {
116+
setTimeout(function () {
118117
expect(runs).toEqual(1);
119118
cb();
120119
}, timeout * 3);
@@ -126,7 +125,7 @@ describe('glob-watcher', function() {
126125
});
127126

128127
// We default `ignoreInitial` to true, so always wait for `on('ready')`
129-
watcher.on('ready', function() {
128+
watcher.on('ready', function () {
130129
changeFile();
131130
// Fire after double the delay
132131
setTimeout(changeFile, timeout * 2);
@@ -135,14 +134,14 @@ describe('glob-watcher', function() {
135134

136135
// It can signal completion with anything async-done supports
137136
// Just wanted to have a smoke test for streams
138-
it('can signal completion with a stream', function(done) {
137+
it('can signal completion with a stream', function (done) {
139138
var runs = 0;
140139

141-
watcher = watch(outGlob, function(cb) {
140+
watcher = watch(outGlob, function (cb) {
142141
runs++;
143142
if (runs === 1) {
144143
var stream = through();
145-
setTimeout(function() {
144+
setTimeout(function () {
146145
expect(runs).toEqual(1);
147146
stream.end();
148147
}, timeout * 3);
@@ -155,21 +154,21 @@ describe('glob-watcher', function() {
155154
});
156155

157156
// We default `ignoreInitial` to true, so always wait for `on('ready')`
158-
watcher.on('ready', function() {
157+
watcher.on('ready', function () {
159158
changeFile();
160159
// Fire after double the delay
161160
setTimeout(changeFile, timeout * 2);
162161
});
163162
});
164163

165-
it('emits an error if one occurs in the callback and handler attached', function(done) {
164+
it('emits an error if one occurs in the callback and handler attached', function (done) {
166165
var expectedError = new Error('boom');
167166

168-
watcher = watch(outGlob, function(cb) {
167+
watcher = watch(outGlob, function (cb) {
169168
cb(expectedError);
170169
});
171170

172-
watcher.on('error', function(err) {
171+
watcher.on('error', function (err) {
173172
expect(err).toEqual(expectedError);
174173
done();
175174
});
@@ -178,10 +177,10 @@ describe('glob-watcher', function() {
178177
watcher.on('ready', changeFile);
179178
});
180179

181-
it('does not emit an error (and crash) when no handlers attached', function(done) {
180+
it('does not emit an error (and crash) when no handlers attached', function (done) {
182181
var expectedError = new Error('boom');
183182

184-
watcher = watch(outGlob, function(cb) {
183+
watcher = watch(outGlob, function (cb) {
185184
cb(expectedError);
186185
setTimeout(done, timeout * 3);
187186
});
@@ -190,12 +189,12 @@ describe('glob-watcher', function() {
190189
watcher.on('ready', changeFile);
191190
});
192191

193-
it('allows the user to disable queueing', function(done) {
192+
it('allows the user to disable queueing', function (done) {
194193
var runs = 0;
195194

196-
watcher = watch(outGlob, { queue: false }, function(cb) {
195+
watcher = watch(outGlob, { queue: false }, function (cb) {
197196
runs++;
198-
setTimeout(function() {
197+
setTimeout(function () {
199198
// Expect 1 because run 2 is never queued
200199
expect(runs).toEqual(1);
201200
cb();
@@ -204,20 +203,20 @@ describe('glob-watcher', function() {
204203
});
205204

206205
// We default `ignoreInitial` to true, so always wait for `on('ready')`
207-
watcher.on('ready', function() {
206+
watcher.on('ready', function () {
208207
changeFile();
209208
// This will never trigger a call because queueing is disabled
210209
setTimeout(changeFile, timeout * 2);
211210
});
212211
});
213212

214-
it('allows the user to adjust delay', function(done) {
213+
it('allows the user to adjust delay', function (done) {
215214
var runs = 0;
216215

217-
watcher = watch(outGlob, { delay: (timeout / 2) }, function(cb) {
216+
watcher = watch(outGlob, { delay: timeout / 2 }, function (cb) {
218217
runs++;
219218
if (runs === 1) {
220-
setTimeout(function() {
219+
setTimeout(function () {
221220
expect(runs).toEqual(1);
222221
cb();
223222
}, timeout * 3);
@@ -230,24 +229,24 @@ describe('glob-watcher', function() {
230229
});
231230

232231
// We default `ignoreInitial` to true, so always wait for `on('ready')`
233-
watcher.on('ready', function() {
232+
watcher.on('ready', function () {
234233
changeFile();
235234
// This will queue because delay is halved
236235
setTimeout(changeFile, timeout);
237236
});
238237
});
239238

240-
it('passes options to chokidar', function(done) {
239+
it('passes options to chokidar', function (done) {
241240
// Callback is called while chokidar is discovering file paths
242241
// if ignoreInitial is explicitly set to false and passed to chokidar
243-
watcher = watch(outGlob, { ignoreInitial: false }, function(cb) {
242+
watcher = watch(outGlob, { ignoreInitial: false }, function (cb) {
244243
cb();
245244
done();
246245
});
247246
});
248247

249-
it('does not override default values with null values', function(done) {
250-
watcher = watch(outGlob, { ignoreInitial: null }, function(cb) {
248+
it('does not override default values with null values', function (done) {
249+
watcher = watch(outGlob, { ignoreInitial: null }, function (cb) {
251250
cb();
252251
done();
253252
});
@@ -257,8 +256,8 @@ describe('glob-watcher', function() {
257256
watcher.on('ready', changeFile);
258257
});
259258

260-
it('watches exactly the given event', function(done) {
261-
var spy = sinon.spy(function(cb) {
259+
it('watches exactly the given event', function (done) {
260+
var spy = sinon.spy(function (cb) {
262261
cb();
263262
expect(spy.callCount).toEqual(1);
264263
setTimeout(done, 500);
@@ -270,8 +269,8 @@ describe('glob-watcher', function() {
270269
watcher.on('ready', addFile);
271270
});
272271

273-
it('accepts multiple events to watch', function(done) {
274-
var spy = sinon.spy(function(cb) {
272+
it('accepts multiple events to watch', function (done) {
273+
var spy = sinon.spy(function (cb) {
275274
cb();
276275
if (spy.callCount === 2) {
277276
done();
@@ -281,15 +280,15 @@ describe('glob-watcher', function() {
281280
watcher = watch(outGlob, { events: ['add', 'change'] }, spy);
282281

283282
watcher.on('ready', addFile);
284-
watcher.on('add', function() {
283+
watcher.on('add', function () {
285284
setTimeout(changeFile, 500);
286285
});
287286
});
288287

289-
it('can ignore a glob after it has been added', function(done) {
288+
it('can ignore a glob after it has been added', function (done) {
290289
watcher = watch([outGlob, ignoreGlob]);
291290

292-
watcher.once('change', function(filepath) {
291+
watcher.once('change', function (filepath) {
293292
// It should never reach here
294293
expect(filepath).toNotExist();
295294
done();
@@ -301,10 +300,10 @@ describe('glob-watcher', function() {
301300
setTimeout(done, 1500);
302301
});
303302

304-
it('can re-add a glob after it has been negated', function(done) {
303+
it('can re-add a glob after it has been negated', function (done) {
305304
watcher = watch([outGlob, ignoreGlob, singleAdd]);
306305

307-
watcher.once('change', function(filepath) {
306+
watcher.once('change', function (filepath) {
308307
expect(filepath).toEqual(singleAdd);
309308
done();
310309
});
@@ -313,14 +312,14 @@ describe('glob-watcher', function() {
313312
watcher.on('ready', changeFile);
314313
});
315314

316-
it('can re-add a glob after it has been negated (unix style path)', function(done) {
315+
it('can re-add a glob after it has been negated (unix style path)', function (done) {
317316
watcher = watch([
318317
normalizePath(outGlob),
319318
normalizePath(ignoreGlob),
320319
normalizePath(singleAdd),
321320
]);
322321

323-
watcher.once('change', function(filepath) {
322+
watcher.once('change', function (filepath) {
324323
// chokidar pass windows style path on windows.
325324
expect(filepath).toEqual(singleAdd);
326325
done();
@@ -330,7 +329,7 @@ describe('glob-watcher', function() {
330329
watcher.on('ready', changeFile);
331330
});
332331

333-
it('does not mutate the globs array', function(done) {
332+
it('does not mutate the globs array', function (done) {
334333
var globs = [outGlob, ignoreGlob, singleAdd];
335334
watcher = watch(globs);
336335

@@ -341,13 +340,13 @@ describe('glob-watcher', function() {
341340
done();
342341
});
343342

344-
it('passes ignores through to chokidar', function(done) {
343+
it('passes ignores through to chokidar', function (done) {
345344
var ignored = [singleAdd];
346345
watcher = watch(outGlob, {
347346
ignored: ignored,
348347
});
349348

350-
watcher.once('change', function(filepath) {
349+
watcher.once('change', function (filepath) {
351350
// It should never reach here
352351
expect(filepath).toNotExist();
353352
done();
@@ -363,10 +362,10 @@ describe('glob-watcher', function() {
363362
});
364363

365364
// https://github.com/gulpjs/glob-watcher/issues/46
366-
it('ignoring globs also works with `cwd` option', function(done) {
365+
it('ignoring globs also works with `cwd` option', function (done) {
367366
watcher = watch(['fixtures/**', '!fixtures/*.js'], { cwd: 'test' });
368367

369-
watcher.once('change', function(filepath) {
368+
watcher.once('change', function (filepath) {
370369
// It should never reach here
371370
expect(filepath).toNotExist();
372371
done();

‎test/lib/debounce.test.js

+15-16
Original file line numberDiff line numberDiff line change
@@ -4,65 +4,64 @@ var expect = require('expect');
44
var sinon = require('sinon');
55
var debounce = require('../../lib/debounce');
66

7-
describe('lib/debounce', function() {
8-
9-
it('should call an original function with specified delay', function(done) {
7+
describe('lib/debounce', function () {
8+
it('should call an original function with specified delay', function (done) {
109
expect.assertions(1);
1110

1211
var executed = false;
13-
var fn = debounce(function() {
12+
var fn = debounce(function () {
1413
executed = true;
1514
}, 10);
1615

1716
fn();
1817

1918
expect(executed).toBeFalsy();
2019

21-
setTimeout(function() {
20+
setTimeout(function () {
2221
expect(executed).toBeTruthy();
2322
done();
2423
}, 11);
2524
});
2625

27-
it('should extend delay against multiple calls', function(done) {
26+
it('should extend delay against multiple calls', function (done) {
2827
expect.assertions(1);
2928

30-
var fn = debounce(function(a) {
29+
var fn = debounce(function (a) {
3130
expect(a).toBe(3);
3231
done();
3332
}, 50);
3433

3534
fn(1);
3635
fn(2);
3736

38-
setTimeout(function() {
37+
setTimeout(function () {
3938
fn(3);
4039
}, 3);
4140
});
4241

43-
it('should extends delay if a preceding call doesn\'t run yet', function(done) {
42+
it("should extends delay if a preceding call doesn't run yet", function (done) {
4443
expect.assertions(1);
4544

46-
var fn = debounce(function(a) {
45+
var fn = debounce(function (a) {
4746
expect(a).toBe(3);
4847
done();
4948
}, 10);
5049

5150
fn(1);
5251

53-
setTimeout(function() {
52+
setTimeout(function () {
5453
fn(2);
5554

56-
setTimeout(function() {
55+
setTimeout(function () {
5756
fn(3);
5857
}, 5);
5958
}, 5);
6059
});
6160

62-
it('should run if a preceding call already run', function(done) {
61+
it('should run if a preceding call already run', function (done) {
6362
expect.assertions(2);
6463

65-
var spy = sinon.spy(function(a) {
64+
var spy = sinon.spy(function (a) {
6665
switch (spy.callCount) {
6766
case 1:
6867
expect(a).toBe(2);
@@ -79,10 +78,10 @@ describe('lib/debounce', function() {
7978

8079
fn(1);
8180

82-
setTimeout(function() {
81+
setTimeout(function () {
8382
fn(2);
8483

85-
setTimeout(function() {
84+
setTimeout(function () {
8685
fn(3);
8786
}, 10);
8887
}, 3);

‎test/lib/normalize-args.test.js

+13-15
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
var expect = require('expect');
44
var normalizeArgs = require('../../lib/normalize-args');
55

6-
describe('lib/normalize-args', function() {
7-
8-
it('should normalize glob to an array', function(done) {
6+
describe('lib/normalize-args', function () {
7+
it('should normalize glob to an array', function (done) {
98
var opts0 = {
109
delay: 500,
1110
events: ['all'],
@@ -14,9 +13,9 @@ describe('lib/normalize-args', function() {
1413
queue: false,
1514
persistent: true,
1615
};
17-
var cb0 = function() {};
16+
var cb0 = function () {};
1817

19-
normalizeArgs('*.txt', opts0, cb0, function(glob, opts, cb) {
18+
normalizeArgs('*.txt', opts0, cb0, function (glob, opts, cb) {
2019
expect(Array.isArray(glob)).toBeTruthy();
2120
expect(opts).not.toBe(opts0);
2221
expect(opts).toEqual(opts0);
@@ -25,11 +24,11 @@ describe('lib/normalize-args', function() {
2524
});
2625
});
2726

28-
it('should complement options with default options', function(done) {
27+
it('should complement options with default options', function (done) {
2928
var glob0 = ['*.txt'];
30-
var cb0 = function() {};
29+
var cb0 = function () {};
3130

32-
normalizeArgs(glob0, {}, cb0, function(glob, opts, cb) {
31+
normalizeArgs(glob0, {}, cb0, function (glob, opts, cb) {
3332
expect(glob).not.toBe(glob0);
3433
expect(glob).toEqual(glob0);
3534
expect(opts).toEqual({
@@ -44,14 +43,14 @@ describe('lib/normalize-args', function() {
4443
});
4544
});
4645

47-
it('should normalize options.events to an array', function(done) {
46+
it('should normalize options.events to an array', function (done) {
4847
var glob0 = ['*.txt'];
4948
var opts0 = {
5049
events: 'all',
5150
};
52-
var cb0 = function() {};
51+
var cb0 = function () {};
5352

54-
normalizeArgs(glob0, opts0, cb0, function(glob, opts, cb) {
53+
normalizeArgs(glob0, opts0, cb0, function (glob, opts, cb) {
5554
expect(glob).not.toBe(glob0);
5655
expect(glob).toEqual(glob0);
5756
expect(opts).toEqual({
@@ -66,10 +65,10 @@ describe('lib/normalize-args', function() {
6665
});
6766
});
6867

69-
it('should change 2nd arg to cb if 2nd arg is a function', function(done) {
68+
it('should change 2nd arg to cb if 2nd arg is a function', function (done) {
7069
var glob0 = ['*.txt'];
71-
var cb0 = function() {};
72-
normalizeArgs(glob0, cb0, undefined, function(glob, opts, cb) {
70+
var cb0 = function () {};
71+
normalizeArgs(glob0, cb0, undefined, function (glob, opts, cb) {
7372
expect(glob).not.toBe(glob0);
7473
expect(glob).toEqual(glob0);
7574
expect(opts).toEqual({
@@ -83,5 +82,4 @@ describe('lib/normalize-args', function() {
8382
done();
8483
});
8584
});
86-
8785
});

0 commit comments

Comments
 (0)
Please sign in to comment.