forked from mysticatea/npm-run-all
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsequential.js
204 lines (180 loc) · 6.81 KB
/
sequential.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/**
* @author Toru Nagashima
* @copyright 2016 Toru Nagashima. All rights reserved.
* See LICENSE file in root directory for full license.
*/
"use strict"
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
const assert = require("power-assert")
const nodeApi = require("../lib")
const spawnWithKill = require("./lib/spawn-with-kill")
const util = require("./lib/util")
const delay = util.delay
const result = util.result
const removeResult = util.removeResult
const runAll = util.runAll
const runSeq = util.runSeq
//------------------------------------------------------------------------------
// Test
//------------------------------------------------------------------------------
describe("[sequencial] npm-run-all", () => {
before(() => process.chdir("test-workspace"))
after(() => process.chdir(".."))
beforeEach(() => delay(1000).then(removeResult))
describe("should run tasks sequentially:", () => {
it("Node API", async () => {
const results = await nodeApi(["test-task:append a", "test-task:append b"], { parallel: false })
assert(results.length === 2)
assert(results[0].name === "test-task:append a")
assert(results[0].code === 0)
assert(results[1].name === "test-task:append b")
assert(results[1].code === 0)
assert(result() === "aabb")
})
it("npm-run-all command", async () => {
await runAll(["test-task:append a", "test-task:append b"])
assert(result() === "aabb")
})
it("run-s command", async () => {
await runSeq(["test-task:append a", "test-task:append b"])
assert(result() === "aabb")
})
})
describe("should not run subsequent tasks if a task exited with a non-zero code:", () => {
it("Node API", async () => {
try {
await nodeApi(["test-task:append2 a", "test-task:error", "test-task:append2 b"])
}
catch (err) {
assert(err.results.length === 3)
assert(err.results[0].name === "test-task:append2 a")
assert(err.results[0].code === 0)
assert(err.results[1].name === "test-task:error")
assert(err.results[1].code === 1)
assert(err.results[2].name === "test-task:append2 b")
assert(err.results[2].code === undefined)
assert(result() === "aa")
return
}
assert(false, "should fail")
})
it("npm-run-all command", async () => {
try {
await runAll(["test-task:append2 a", "test-task:error", "test-task:append2 b"])
}
catch (_err) {
assert(result() === "aa")
return
}
assert(false, "should fail")
})
it("run-s command", async () => {
try {
await runSeq(["test-task:append2 a", "test-task:error", "test-task:append2 b"])
}
catch (_err) {
assert(result() === "aa")
return
}
assert(false, "should fail")
})
})
describe("should remove intersected tasks from two or more patterns:", () => {
it("Node API", async () => {
await nodeApi(["test-task:*:a", "*:append:a"], { parallel: false })
assert(result() === "aa")
})
it("npm-run-all command", async () => {
await runAll(["test-task:*:a", "*:append:a"])
assert(result() === "aa")
})
it("run-s command", async () => {
await runSeq(["test-task:*:a", "*:append:a"])
assert(result() === "aa")
})
})
describe("should not remove duplicate tasks from two or more the same pattern:", () => {
it("Node API", async () => {
await nodeApi(["test-task:*:a", "test-task:*:a"], { parallel: false })
assert(result() === "aaaa")
})
it("npm-run-all command", async () => {
await runAll(["test-task:*:a", "test-task:*:a"])
assert(result() === "aaaa")
})
it("run-s command", async () => {
await runSeq(["test-task:*:a", "test-task:*:a"])
assert(result() === "aaaa")
})
})
describe("should kill child processes when it's killed", () => {
it("npm-run-all command", async () => {
await spawnWithKill(
"node",
["../bin/npm-run-all.js", "test-task:append2 a"]
)
assert(result() == null || result() === "a")
})
it("run-s command", async () => {
await spawnWithKill(
"node",
["../bin/run-s/index.js", "test-task:append2 a"]
)
assert(result() == null || result() === "a")
})
})
describe("should continue on error when --continue-on-error option was specified:", () => {
it("Node API", async () => {
try {
await nodeApi(["test-task:append a", "test-task:error", "test-task:append b"], { continueOnError: true })
}
catch (_err) {
assert(result() === "aabb")
return
}
assert(false, "should fail")
})
it("npm-run-all command (--continue-on-error)", async () => {
try {
await runAll(["--continue-on-error", "test-task:append a", "test-task:error", "test-task:append b"])
}
catch (_err) {
assert(result() === "aabb")
return
}
assert(false, "should fail")
})
it("run-s command (--continue-on-error)", async () => {
try {
await runSeq(["--continue-on-error", "test-task:append a", "test-task:error", "test-task:append b"])
}
catch (_err) {
assert(result() === "aabb")
return
}
assert(false, "should fail")
})
it("npm-run-all command (-c)", async () => {
try {
await runAll(["-c", "test-task:append a", "test-task:error", "test-task:append b"])
}
catch (_err) {
assert(result() === "aabb")
return
}
assert(false, "should fail")
})
it("run-s command (-c)", async () => {
try {
await runSeq(["-c", "test-task:append a", "test-task:error", "test-task:append b"])
}
catch (_err) {
assert(result() === "aabb")
return
}
assert(false, "should fail")
})
})
})