-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
109 lines (91 loc) · 2.18 KB
/
test.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
'use strict';
require('mocha');
var Base = require('base');
var assert = require('assert');
var tasks = require('./');
var base;
describe('tasks', function() {
beforeEach(function() {
base = new Base();
base.use('base-task', tasks());
});
it('should register the plugin', function() {
assert(base.isRegistered('base-task'));
});
it('should not register the plugin more than once', function() {
let count = 0;
base = new Base();
base.on('plugin', () => (count++));
base.use('task', tasks());
base.use('task', tasks());
base.use('task', tasks());
base.use('task', tasks());
assert.equal(count, 1);
});
it('should decorate a `tasks` property', function() {
assert(base.tasks);
assert.equal(typeof base.tasks, 'object');
});
it('should decorate a `task` method', function() {
assert.equal(typeof base.task, 'function');
});
it('should decorate a `build` method', function() {
assert.equal(typeof base.build, 'function');
});
it('should run a task', function(cb) {
let count = 0;
base.task('a', function(next) {
count++;
next();
});
base.build('a', function(err) {
assert.equal(count, 1);
cb();
});
});
it('should run multiple tasks', function(cb) {
let count = 0;
base.task('a', function(next) {
count++;
next();
});
base.task('b', function(next) {
count++;
next();
});
base.build(['a', 'b'], function(err) {
assert.equal(count, 2);
cb();
});
});
it('should return a promise', function() {
let count = 0;
base.task('a', function(next) {
count++;
next();
});
base.task('b', function(next) {
count++;
next();
});
return base.build(['a', 'b'])
.then(() => {
assert.equal(count, 2);
});
});
it('should emit task events', async() => {
let count = 0;
base.on('task', task => {
switch (task.status) {
case 'starting':
case 'finished': {
count++;
}
}
});
base.task('a', next => next());
base.task('b', next => next());
await base.build(['a', 'b']);
assert.equal(count, 4);
});
});