-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwatch.js
More file actions
112 lines (94 loc) · 2.53 KB
/
Copy pathwatch.js
File metadata and controls
112 lines (94 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
'use strict';
var fs = require('fs');
var path = require('path');
var test = {
file: path.resolve(__dirname, 'dir', 'watchTestFile.js'),
content: 'exports = module.exports = { test: "watchTest" };',
dirname: path.resolve(__dirname, 'dir')
};
exports = module.exports = function (Gulp, util) {
before(function (done) {
util.mkdirp(test.dirname, done);
});
after(function (done) {
util.rimraf(test.dirname, done);
});
function setupTest (onSuccess, onError) {
fs.writeFile(test.file, test.content, function (writeError) {
if (writeError) {
return onError(writeError);
}
onSuccess();
setTimeout(function () {
fs.writeFile(test.file, '// changed', onError);
}, 10);
});
}
it('watch(glob, [Function]) should call function on change', function (done) {
var gulp = Gulp.create({log: false});
setupTest(function () {
var watcher = gulp.watch(test.file, function () {
watcher.end();
done();
});
}, done);
});
it('watch(glob, tasks) runs tasks in parallel after change', function (done) {
var pile = [];
var gulp = Gulp.create({
log: false,
onHandleError: done
});
gulp.task('one', function (next) {
setTimeout(function () {
pile.push('one');
if (pile.length > 1) {
pile.should.containDeep(['one', 'two']);
done();
}
next();
}, Math.random() * 10);
});
gulp.task('two', function (next) {
setTimeout(function () {
pile.push('two');
if (pile.length > 1) {
pile.should.containDeep(['one', 'two']);
done();
}
next();
}, Math.random() * 10);
});
setupTest(function () {
var watcher = gulp.watch(test.file, ['one', 'two'], function () {
watcher.end();
});
}, done);
});
it('watch(glob, tasks, fn) onChange fn runs after tasks', function (done) {
var pile = [];
var gulp = Gulp.create({
log: false,
onHandleError: done
});
gulp.task('one', function (next) {
setTimeout(function () {
pile.push('one');
next();
}, Math.random() * 10);
});
gulp.task('two', function (next) {
setTimeout(function () {
pile.push('two');
next();
}, Math.random() * 10);
});
setupTest(function () {
var watcher = gulp.watch(test.file, ['one', 'two'], function () {
pile.should.containDeep(['one', 'two']);
watcher.end();
done();
});
}, done);
});
};