forked from jamesshore/lets_code_javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask_base.js
More file actions
158 lines (134 loc) · 4.17 KB
/
task_base.js
File metadata and controls
158 lines (134 loc) · 4.17 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
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
var assert = require('assert')
, h = require('./helpers');
var tests = {
'before': function () {
process.chdir('./test');
}
, 'after': function () {
process.chdir('../');
}
, 'test default task': function (next) {
h.exec('../bin/cli.js', function (out) {
assert.equal('default task', out);
h.exec('../bin/cli.js default', function (out) {
assert.equal('default task', out);
next();
});
});
}
, 'test task with no action': function (next) {
h.exec('../bin/cli.js noAction', function (out) {
assert.equal('default task', out);
next();
});
}
, 'test a task with no action and no prereqs': function (next) {
h.exec('../bin/cli.js noActionNoPrereqs', function () {
next();
});
}
, 'test passing args to a task': function (next) {
h.exec('../bin/cli.js argsEnvVars[foo,bar]', function (out) {
var parsed = h.parse(out)
, args = parsed.args;
assert.equal(args[0], 'foo');
assert.equal(args[1], 'bar');
next();
});
}
, 'test a task with environment vars': function (next) {
h.exec('../bin/cli.js argsEnvVars foo=bar baz=qux', function (out) {
var parsed = h.parse(out)
, env = parsed.env;
assert.equal(env.foo, 'bar');
assert.equal(env.baz, 'qux');
next();
});
}
, 'test passing args and using environment vars': function (next) {
h.exec('../bin/cli.js argsEnvVars[foo,bar] foo=bar baz=qux', function (out) {
var parsed = h.parse(out)
, args = parsed.args
, env = parsed.env;
assert.equal(args[0], 'foo');
assert.equal(args[1], 'bar');
assert.equal(env.foo, 'bar');
assert.equal(env.baz, 'qux');
next();
});
}
, 'test a simple prereq': function (next) {
h.exec('../bin/cli.js foo:baz', function (out) {
assert.equal('foo:bar task\nfoo:baz task', out);
next();
});
}
, 'test a duplicate prereq only runs once': function (next) {
h.exec('../bin/cli.js foo:asdf', function (out) {
assert.equal('foo:bar task\nfoo:baz task\nfoo:asdf task', out);
next();
});
}
, 'test a prereq with command-line args': function (next) {
h.exec('../bin/cli.js foo:qux', function (out) {
assert.equal('foo:bar[asdf,qwer] task\nfoo:qux task', out);
next();
});
}
, 'test a prereq with args via invoke': function (next) {
h.exec('../bin/cli.js foo:frang[zxcv,uiop]', function (out) {
assert.equal('foo:bar[zxcv,uiop] task\nfoo:frang task', out);
next();
});
}
, 'test prereq execution-order': function (next) {
h.exec('../bin/cli.js hoge:fuga', function (out) {
assert.equal('hoge:hoge task\nhoge:piyo task\nhoge:fuga task', out);
next();
});
}
, 'test basic async task': function (next) {
h.exec('../bin/cli.js bar:bar', function (out) {
assert.equal('bar:foo task\nbar:bar task', out);
next();
});
}
, 'test promise async task': function (next) {
h.exec('node ../bin/cli.js bar:dependOnpromise', function (out) {
assert.equal('bar:promise task\nbar:dependOnpromise task saw value 123654', out);
next();
});
}
, 'test failing promise async task': function (next) {
h.exec('node ../bin/cli.js bar:brokenPromise', {breakOnError:false}, function (out) {
assert.equal(1, out.code);
next();
});
}
, 'test that current-prereq index gets reset': function (next) {
h.exec('../bin/cli.js hoge:kira', function (out) {
assert.equal('hoge:hoge task\nhoge:piyo task\nhoge:fuga task\n' +
'hoge:charan task\nhoge:gero task\nhoge:kira task', out);
next();
});
}
, 'test modifying a task by adding prereq during execution': function (next) {
h.exec('../bin/cli.js voom', function (out) {
assert.equal(2, out);
next();
});
}
, 'test listening for task error-event': function (next) {
h.exec('../bin/cli.js vronk:groo', function (out) {
assert.equal('OMFGZONG', out);
next();
});
}
, 'test listening for jake error-event': function (next) {
h.exec('../bin/cli.js throwy', function (out) {
assert.equal(out, 'Emitted: Error: I am bad');
next();
});
}
};
module.exports = tests;