-
-
Notifications
You must be signed in to change notification settings - Fork 242
/
Copy pathyarn.js
64 lines (54 loc) · 2.03 KB
/
yarn.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
/**
* @author Toru Nagashima
* @copyright 2016 Toru Nagashima. All rights reserved.
* See LICENSE file in root directory for full license.
*/
"use strict"
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
const spawn = require("cross-spawn")
const assert = require("power-assert")
const BufferStream = require("./lib/buffer-stream")
const util = require("./lib/util")
const result = util.result
const removeResult = util.removeResult
//------------------------------------------------------------------------------
// Helpers
//------------------------------------------------------------------------------
/**
* Execute a command.
* @param {string} command A command to execute.
* @param {string[]} args Arguments for the command.
* @returns {Promise<void>} The result of child process's stdout.
*/
function exec(command, args) {
return new Promise((resolve, reject) => {
const stderr = new BufferStream()
const cp = spawn(command, args, { stdio: ["ignore", "ignore", "pipe"] })
cp.stderr.pipe(stderr)
cp.on("exit", (exitCode) => {
if (exitCode) {
reject(new Error(`Exited with ${exitCode}: ${stderr.value}`))
return
}
resolve()
})
cp.on("error", reject)
})
}
const nodeVersion = Number(process.versions.node.split(".")[0])
//------------------------------------------------------------------------------
// Test
//------------------------------------------------------------------------------
;(nodeVersion >= 6 ? describe : xdescribe)("[yarn]", () => {
before(() => process.chdir("test-workspace"))
after(() => process.chdir(".."))
beforeEach(removeResult)
describe("'yarn run' command", () => {
it("should run 'npm-run-all' in scripts with yarn.", async () => {
await exec("yarn", ["run", "test-task:yarn"])
assert(result() === "aabb")
})
})
})