-
-
Notifications
You must be signed in to change notification settings - Fork 243
/
Copy pathaggregate-output.js
121 lines (105 loc) · 3.94 KB
/
aggregate-output.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
/**
* @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 BufferStream = require("./lib/buffer-stream")
const util = require("./lib/util")
const runAll = util.runAll
const runPar = util.runPar
const runSeq = util.runSeq
//------------------------------------------------------------------------------
// Test
//------------------------------------------------------------------------------
describe("[aggregated-output] npm-run-all", () => {
before(() => process.chdir("test-workspace"))
after(() => process.chdir(".."))
/**
* create expected text
* @param {string} term the term to use when creating a line
* @returns {string} the complete line
*/
function createExpectedOutput(term) {
return `[${term}]__[${term}]`
}
describe("should not intermingle output of various commands", () => {
const EXPECTED_PARALLELIZED_TEXT = [
createExpectedOutput("second"),
createExpectedOutput("third"),
createExpectedOutput("first"),
"",
].join("\n")
let stdout = null
beforeEach(() => {
stdout = new BufferStream()
})
it("Node API with parallel", async () => {
await nodeApi(
["test-task:delayed first 5000", "test-task:delayed second 1000", "test-task:delayed third 3000"],
{ stdout, parallel: true, silent: true, aggregateOutput: true }
)
assert.equal(stdout.value, EXPECTED_PARALLELIZED_TEXT)
})
it("Node API without parallel should fail", async () => {
try {
await nodeApi(
["test-task:delayed first 5000", "test-task:delayed second 1000", "test-task:delayed third 3000"],
{ stdout, silent: true, aggregateOutput: true }
)
}
catch (_err) {
return
}
assert(false, "should fail")
})
it("npm-run-all command with parallel", async () => {
await runAll(
["--parallel", "test-task:delayed first 5000", "test-task:delayed second 1000", "test-task:delayed third 3000", "--silent", "--aggregate-output"],
stdout
)
assert.equal(stdout.value, EXPECTED_PARALLELIZED_TEXT)
})
it("npm-run-all command without parallel should fail", async () => {
try {
await runAll(
["test-task:delayed first 5000", "test-task:delayed second 1000", "test-task:delayed third 3000", "--silent", "--aggregate-output"],
stdout
)
}
catch (_err) {
return
}
assert(false, "should fail")
})
it("run-s command should fail", async () => {
try {
await runSeq(
["test-task:delayed first 5000", "test-task:delayed second 1000", "test-task:delayed third 3000", "--silent", "--aggregate-output"],
stdout
)
}
catch (_err) {
return
}
assert(false, "should fail")
})
it("run-p command", async () => {
await runPar(
[
"test-task:delayed first 5000",
"test-task:delayed second 1000",
"test-task:delayed third 3000",
"--silent", "--aggregate-output",
],
stdout
)
assert.equal(stdout.value, EXPECTED_PARALLELIZED_TEXT)
})
})
})