|
| 1 | + |
| 2 | +/** |
| 3 | + * @author Toru Nagashima |
| 4 | + * @copyright 2016 Toru Nagashima. All rights reserved. |
| 5 | + * See LICENSE file in root directory for full license. |
| 6 | + */ |
| 7 | +"use strict" |
| 8 | + |
| 9 | +//------------------------------------------------------------------------------ |
| 10 | +// Requirements |
| 11 | +//------------------------------------------------------------------------------ |
| 12 | + |
| 13 | +const assert = require("power-assert") |
| 14 | +const nodeApi = require("../lib") |
| 15 | +const BufferStream = require("./lib/buffer-stream") |
| 16 | +const util = require("./lib/util") |
| 17 | +const runAll = util.runAll |
| 18 | +const runPar = util.runPar |
| 19 | +const runSeq = util.runSeq |
| 20 | + |
| 21 | +//------------------------------------------------------------------------------ |
| 22 | +// Test |
| 23 | +//------------------------------------------------------------------------------ |
| 24 | + |
| 25 | +describe("[aggregated-output] npm-run-all", () => { |
| 26 | + before(() => process.chdir("test-workspace")) |
| 27 | + after(() => process.chdir("..")) |
| 28 | + |
| 29 | + /** |
| 30 | + * create expected text |
| 31 | + * @param {string} term the term to use when creating a line |
| 32 | + * @returns {string} the complete line |
| 33 | + */ |
| 34 | + function createExpectedOutput(term) { |
| 35 | + return `[${term}]__[${term}]` |
| 36 | + } |
| 37 | + |
| 38 | + describe("should not intermingle output of various commands", () => { |
| 39 | + const EXPECTED_SERIALIZED_TEXT = [ |
| 40 | + createExpectedOutput("first"), |
| 41 | + createExpectedOutput("second"), |
| 42 | + `${createExpectedOutput("third")}\n`, |
| 43 | + ].join("\n") |
| 44 | + |
| 45 | + const EXPECTED_PARALLELIZED_TEXT = [ |
| 46 | + createExpectedOutput("second"), |
| 47 | + createExpectedOutput("third"), |
| 48 | + `${createExpectedOutput("first")}\n`, |
| 49 | + ].join("\n") |
| 50 | + |
| 51 | + let stdout = null |
| 52 | + |
| 53 | + beforeEach(() => { |
| 54 | + stdout = new BufferStream() |
| 55 | + }) |
| 56 | + |
| 57 | + it("Node API", () => nodeApi( |
| 58 | + ["test-task:delayed first 300", "test-task:delayed second 100", "test-task:delayed third 200"], |
| 59 | + {stdout, silent: true, aggregateOutput: true} |
| 60 | + ) |
| 61 | + .then(() => { |
| 62 | + assert.equal(stdout.value, EXPECTED_SERIALIZED_TEXT) |
| 63 | + })) |
| 64 | + |
| 65 | + it("npm-run-all command", () => runAll( |
| 66 | + ["test-task:delayed first 300", "test-task:delayed second 100", "test-task:delayed third 200", "--silent", "--aggregate-output"], |
| 67 | + stdout |
| 68 | + ) |
| 69 | + .then(() => { |
| 70 | + assert.equal(stdout.value, EXPECTED_SERIALIZED_TEXT) |
| 71 | + })) |
| 72 | + |
| 73 | + it("run-s command", () => runSeq( |
| 74 | + ["test-task:delayed first 300", "test-task:delayed second 100", "test-task:delayed third 200", "--silent", "--aggregate-output"], |
| 75 | + stdout |
| 76 | + ) |
| 77 | + .then(() => { |
| 78 | + assert.equal(stdout.value, EXPECTED_SERIALIZED_TEXT) |
| 79 | + })) |
| 80 | + |
| 81 | + it("run-p command", () => runPar([ |
| 82 | + "test-task:delayed first 3000", |
| 83 | + "test-task:delayed second 1000", |
| 84 | + "test-task:delayed third 2000", |
| 85 | + "--silent", "--aggregate-output"], |
| 86 | + stdout |
| 87 | + ) |
| 88 | + .then(() => { |
| 89 | + assert.equal(stdout.value, EXPECTED_PARALLELIZED_TEXT) |
| 90 | + })) |
| 91 | + }) |
| 92 | +}) |
| 93 | + |
0 commit comments