forked from gulpjs/gulp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tasks.js
157 lines (155 loc) · 3.69 KB
/
tasks.js
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
'use strict';
var gulp = require('../');
var Q = require('q');
var should = require('should');
require('mocha');
describe('gulp tasks', function() {
describe('task()', function() {
it('should define a task', function(done) {
var fn;
fn = function() {};
gulp.task('test', fn);
should.exist(gulp.tasks.test);
gulp.tasks.test.fn.should.equal(fn);
gulp.reset();
done();
});
});
describe('run()', function() {
it('should run multiple tasks', function(done) {
var a, fn, fn2;
a = 0;
fn = function() {
this.should.equal(gulp);
++a;
};
fn2 = function() {
this.should.equal(gulp);
++a;
};
gulp.task('test', fn);
gulp.task('test2', fn2);
gulp.run('test', 'test2');
a.should.equal(2);
gulp.reset();
done();
});
it('should run all tasks when call run() multiple times', function(done) {
var a, fn, fn2;
a = 0;
fn = function() {
this.should.equal(gulp);
++a;
};
fn2 = function() {
this.should.equal(gulp);
++a;
};
gulp.task('test', fn);
gulp.task('test2', fn2);
gulp.run('test');
gulp.run('test2');
a.should.equal(2);
gulp.reset();
done();
});
it('should run all async promise tasks', function(done) {
var a, fn, fn2;
a = 0;
fn = function() {
var deferred = Q.defer();
setTimeout(function() {
++a;
deferred.resolve();
},1);
return deferred.promise;
};
fn2 = function() {
var deferred = Q.defer();
setTimeout(function() {
++a;
deferred.resolve();
},1);
return deferred.promise;
};
gulp.task('test', fn);
gulp.task('test2', fn2);
gulp.run('test');
gulp.run('test2', function() {
gulp.isRunning.should.equal(false);
a.should.equal(2);
gulp.reset();
done();
});
gulp.isRunning.should.equal(true);
});
it('should run all async callback tasks', function(done) {
var a, fn, fn2;
a = 0;
fn = function(cb) {
setTimeout(function() {
++a;
cb(null);
},1);
};
fn2 = function(cb) {
setTimeout(function() {
++a;
cb(null);
},1);
};
gulp.task('test', fn);
gulp.task('test2', fn2);
gulp.run('test');
gulp.run('test2', function() {
gulp.isRunning.should.equal(false);
a.should.equal(2);
gulp.reset();
done();
});
gulp.isRunning.should.equal(true);
});
it('should emit task_not_found and throw an error when task is not defined', function(done) {
gulp.on('task_not_found', function(err) {
should.exist(err);
should.exist(err.task);
err.task.should.equal('test');
gulp.reset();
done();
});
try {
gulp.run('test');
} catch (err) {
should.exist(err);
}
});
it('should run task scoped to gulp', function(done) {
var a, fn;
a = 0;
fn = function() {
this.should.equal(gulp);
++a;
};
gulp.task('test', fn);
gulp.run('test');
a.should.equal(1);
gulp.isRunning.should.equal(false);
gulp.reset();
done();
});
it('should run default task scoped to gulp', function(done) {
var a, fn;
a = 0;
fn = function() {
this.should.equal(gulp);
++a;
};
gulp.task('default', fn);
gulp.run();
a.should.equal(1);
gulp.isRunning.should.equal(false);
gulp.reset();
done();
});
});
});