diff --git a/.babelrc b/.babelrc index 8469eba..6454fa9 100644 --- a/.babelrc +++ b/.babelrc @@ -1,5 +1,6 @@ { "presets": ["power-assert"], + "plugins": ["transform-async-to-generator"], "only": "/test/*.js", "sourceMaps": "inline" } diff --git a/bin/common/parse-cli-args.js b/bin/common/parse-cli-args.js index f6e4408..60e3290 100644 --- a/bin/common/parse-cli-args.js +++ b/bin/common/parse-cli-args.js @@ -43,12 +43,12 @@ function createPackageConfig() { return retv } - Object.keys(process.env).forEach(key => { + for (const key of Object.keys(process.env)) { const m = PACKAGE_CONFIG_PATTERN.exec(key) if (m != null) { overwriteConfig(retv, packageName, m[1], process.env[key]) } - }) + } return retv } @@ -62,7 +62,7 @@ function createPackageConfig() { */ function addGroup(groups, initialValues) { groups.push(Object.assign( - {parallel: false, patterns: []}, + { parallel: false, patterns: [] }, initialValues || {} )) } @@ -183,7 +183,7 @@ function parseCLIArgsCore(set, args) { // eslint-disable-line complexity if (set.singleMode) { throw new Error(`Invalid Option: ${arg}`) } - addGroup(set.groups, {parallel: true}) + addGroup(set.groups, { parallel: true }) break case "--npm-path": diff --git a/bin/run-p/main.js b/bin/run-p/main.js index be10a7a..e44f2f2 100644 --- a/bin/run-p/main.js +++ b/bin/run-p/main.js @@ -28,7 +28,7 @@ const parseCLIArgs = require("../common/parse-cli-args") module.exports = function npmRunAll(args, stdout, stderr) { try { const stdin = process.stdin - const argv = parseCLIArgs(args, {parallel: true}, {singleMode: true}) + const argv = parseCLIArgs(args, { parallel: true }, { singleMode: true }) const group = argv.lastGroup if (group.patterns.length === 0) { diff --git a/bin/run-s/main.js b/bin/run-s/main.js index 7c5faae..d1bd6da 100644 --- a/bin/run-s/main.js +++ b/bin/run-s/main.js @@ -28,7 +28,7 @@ const parseCLIArgs = require("../common/parse-cli-args") module.exports = function npmRunAll(args, stdout, stderr) { try { const stdin = process.stdin - const argv = parseCLIArgs(args, {parallel: false}, {singleMode: true}) + const argv = parseCLIArgs(args, { parallel: false }, { singleMode: true }) const group = argv.lastGroup if (group.patterns.length === 0) { diff --git a/lib/create-header.js b/lib/create-header.js index c22f857..63bf6f7 100644 --- a/lib/create-header.js +++ b/lib/create-header.js @@ -38,7 +38,7 @@ module.exports = function createHeader(nameAndArgs, packageInfo, isTTY) { const packageVersion = packageInfo.body.version const scriptBody = packageInfo.body.scripts[name] const packagePath = packageInfo.path - const color = isTTY ? chalk.styles.gray : {open: "", close: ""} + const color = isTTY ? chalk.styles.gray : { open: "", close: "" } return ` ${color.open}> ${packageName}@${packageVersion} ${name} ${packagePath}${color.close} diff --git a/lib/create-prefix-transform-stream.js b/lib/create-prefix-transform-stream.js index 296c0de..cb2c360 100644 --- a/lib/create-prefix-transform-stream.js +++ b/lib/create-prefix-transform-stream.js @@ -45,11 +45,11 @@ class PrefixTransform extends stream.Transform { * Transforms the output chunk. * * @param {string|Buffer} chunk - A chunk to be transformed. - * @param {string} encoding - The encoding of the chunk. + * @param {string} _encoding - The encoding of the chunk. * @param {function} callback - A callback function that is called when done. * @returns {void} */ - _transform(chunk, encoding, callback) { + _transform(chunk, _encoding, callback) { const prefix = this.prefix const nPrefix = `\n${prefix}` const state = this.state diff --git a/lib/index.js b/lib/index.js index 7c569d6..4ee18cf 100644 --- a/lib/index.js +++ b/lib/index.js @@ -110,15 +110,15 @@ function parsePatterns(patternOrPatterns, args) { function toOverwriteOptions(config) { const options = [] - Object.keys(config).forEach(packageName => { + for (const packageName of Object.keys(config)) { const packageConfig = config[packageName] - Object.keys(packageConfig).forEach(variableName => { + for (const variableName of Object.keys(packageConfig)) { const value = packageConfig[variableName] options.push(`--${packageName}:${variableName}=${value}`) - }) - }) + } + } return options } @@ -249,7 +249,7 @@ module.exports = function npmRunAll(patternOrPatterns, options) { return Promise.resolve() .then(() => { if (taskList != null) { - return {taskList, packageInfo: null} + return { taskList, packageInfo: null } } return readPackageJson() }) diff --git a/lib/match-tasks.js b/lib/match-tasks.js index 92adcc4..63a0de3 100644 --- a/lib/match-tasks.js +++ b/lib/match-tasks.js @@ -17,7 +17,7 @@ const Minimatch = require("minimatch").Minimatch //------------------------------------------------------------------------------ const COLON_OR_SLASH = /[:/]/g -const CONVERT_MAP = {":": "/", "/": ":"} +const CONVERT_MAP = { ":": "/", "/": ":" } /** * Swaps ":" and "/", in order to use ":" as the separator in minimatch. @@ -46,7 +46,7 @@ function createFilter(pattern) { const matcher = new Minimatch(swapColonAndSlash(task)) const match = matcher.match.bind(matcher) - return {match, task, args} + return { match, task, args } } /** @@ -97,10 +97,10 @@ module.exports = function matchTasks(taskList, patterns) { const unknownSet = Object.create(null) // Take tasks while keep the order of patterns. - filters.forEach(filter => { + for (const filter of filters) { let found = false - candidates.forEach(candidate => { + for (const candidate of candidates) { if (filter.match(candidate)) { found = true taskSet.add( @@ -108,7 +108,7 @@ module.exports = function matchTasks(taskList, patterns) { filter.task ) } - }) + } // Built-in tasks should be allowed. if (!found && (filter.task === "restart" || filter.task === "env")) { @@ -118,7 +118,7 @@ module.exports = function matchTasks(taskList, patterns) { if (!found) { unknownSet[filter.task] = true } - }) + } const unknownTasks = Object.keys(unknownSet) if (unknownTasks.length > 0) { diff --git a/lib/read-package-json.js b/lib/read-package-json.js index bc8b4e3..1497ebf 100644 --- a/lib/read-package-json.js +++ b/lib/read-package-json.js @@ -26,6 +26,6 @@ module.exports = function readPackageJson() { const path = joinPath(process.cwd(), "package.json") return readPkg(path).then(body => ({ taskList: Object.keys(body.scripts || {}), - packageInfo: {path, body}, + packageInfo: { path, body }, })) } diff --git a/lib/run-task.js b/lib/run-task.js index e153b25..0cc3332 100644 --- a/lib/run-task.js +++ b/lib/run-task.js @@ -33,8 +33,8 @@ const colors = [chalk.cyan, chalk.green, chalk.magenta, chalk.yellow, chalk.red] function selectColor(taskName) { let hash = 0 - for (const i in taskName) { - hash = ((hash << 5) - hash) + taskName.charCodeAt(i) + for (const c of taskName) { + hash = ((hash << 5) - hash) + c hash |= 0 } @@ -124,7 +124,7 @@ module.exports = function runTask(task, options) { const stdinKind = detectStreamKind(stdin, process.stdin) const stdoutKind = detectStreamKind(stdout, process.stdout) const stderrKind = detectStreamKind(stderr, process.stderr) - const spawnOptions = {stdio: [stdinKind, stdoutKind, stderrKind]} + const spawnOptions = { stdio: [stdinKind, stdoutKind, stderrKind] } // Print task name. if (options.printName && stdout != null) { @@ -164,10 +164,10 @@ module.exports = function runTask(task, options) { stdin.pipe(cp.stdin) } if (stdoutKind === "pipe") { - cp.stdout.pipe(stdout, {end: false}) + cp.stdout.pipe(stdout, { end: false }) } if (stderrKind === "pipe") { - cp.stderr.pipe(stderr, {end: false}) + cp.stderr.pipe(stderr, { end: false }) } // Register @@ -177,7 +177,7 @@ module.exports = function runTask(task, options) { }) cp.on("close", (code) => { cp = null - resolve({task, code}) + resolve({ task, code }) }) }) diff --git a/lib/run-tasks.js b/lib/run-tasks.js index 3ede5e3..b5484a0 100644 --- a/lib/run-tasks.js +++ b/lib/run-tasks.js @@ -53,8 +53,8 @@ module.exports = function runTasks(tasks, options) { return } - const results = tasks.map(task => ({name: task, code: undefined})) - const queue = tasks.map((task, index) => ({name: task, index})) + const results = tasks.map(task => ({ name: task, code: undefined })) + const queue = tasks.map((task, index) => ({ name: task, index })) const promises = [] let error = null let aborted = false @@ -86,7 +86,9 @@ module.exports = function runTasks(tasks, options) { done() } else { - promises.forEach(p => p.abort()) + for (const p of promises) { + p.abort() + } Promise.all(promises).then(done, reject) } } diff --git a/lib/spawn-posix.js b/lib/spawn-posix.js index 245b690..1fb5de0 100644 --- a/lib/spawn-posix.js +++ b/lib/spawn-posix.js @@ -28,14 +28,14 @@ function kill() { return } - descendent.forEach(child => { + for (const child of descendent) { try { process.kill(child.PID) } catch (_err) { // ignore. } - }) + } }) } diff --git a/package.json b/package.json index 7a8401b..23eef04 100644 --- a/package.json +++ b/package.json @@ -40,11 +40,12 @@ }, "devDependencies": { "@types/node": "^4.2.20", + "babel-plugin-transform-async-to-generator": "^6.24.1", "babel-preset-power-assert": "^1.0.0", "babel-register": "^6.26.0", "codecov": "^2.3.0", - "eslint": "^3.12.2", - "eslint-config-mysticatea": "^7.0.1", + "eslint": "^4.5.0", + "eslint-config-mysticatea": "^12.0.0", "jsdoc": "^3.5.4", "mocha": "^3.5.0", "nyc": "^11.1.0", diff --git a/test/.eslintrc.json b/test/.eslintrc.json index 2fd9145..407983a 100644 --- a/test/.eslintrc.json +++ b/test/.eslintrc.json @@ -1,3 +1,8 @@ { - "extends": "mysticatea/mocha" + "extends": "mysticatea/mocha", + "rules": { + "node/no-unsupported-features": ["error", { + "ignores": ["asyncAwait"] + }] + } } diff --git a/test/aggregate-output.js b/test/aggregate-output.js index f0fa931..ec629d4 100644 --- a/test/aggregate-output.js +++ b/test/aggregate-output.js @@ -54,40 +54,42 @@ describe("[aggregated-output] npm-run-all", () => { stdout = new BufferStream() }) - it("Node API", () => nodeApi( - ["test-task:delayed first 300", "test-task:delayed second 100", "test-task:delayed third 200"], - {stdout, silent: true, aggregateOutput: true} - ) - .then(() => { - assert.equal(stdout.value, EXPECTED_SERIALIZED_TEXT) - })) + it("Node API", async () => { + await nodeApi( + ["test-task:delayed first 300", "test-task:delayed second 100", "test-task:delayed third 200"], + { stdout, silent: true, aggregateOutput: true } + ) + assert.equal(stdout.value, EXPECTED_SERIALIZED_TEXT) + }) - it("npm-run-all command", () => runAll( - ["test-task:delayed first 300", "test-task:delayed second 100", "test-task:delayed third 200", "--silent", "--aggregate-output"], - stdout - ) - .then(() => { - assert.equal(stdout.value, EXPECTED_SERIALIZED_TEXT) - })) + it("npm-run-all command", async () => { + await runAll( + ["test-task:delayed first 300", "test-task:delayed second 100", "test-task:delayed third 200", "--silent", "--aggregate-output"], + stdout + ) + assert.equal(stdout.value, EXPECTED_SERIALIZED_TEXT) + }) - it("run-s command", () => runSeq( - ["test-task:delayed first 300", "test-task:delayed second 100", "test-task:delayed third 200", "--silent", "--aggregate-output"], - stdout - ) - .then(() => { - assert.equal(stdout.value, EXPECTED_SERIALIZED_TEXT) - })) + it("run-s command", async () => { + await runSeq( + ["test-task:delayed first 300", "test-task:delayed second 100", "test-task:delayed third 200", "--silent", "--aggregate-output"], + stdout + ) + assert.equal(stdout.value, EXPECTED_SERIALIZED_TEXT) + }) - it("run-p command", () => runPar([ - "test-task:delayed first 3000", - "test-task:delayed second 1000", - "test-task:delayed third 2000", - "--silent", "--aggregate-output"], - stdout - ) - .then(() => { - assert.equal(stdout.value, EXPECTED_PARALLELIZED_TEXT) - })) + it("run-p command", async () => { + await runPar( + [ + "test-task:delayed first 3000", + "test-task:delayed second 1000", + "test-task:delayed third 2000", + "--silent", "--aggregate-output", + ], + stdout + ) + assert.equal(stdout.value, EXPECTED_PARALLELIZED_TEXT) + }) }) }) diff --git a/test/argument-placeholders.js b/test/argument-placeholders.js index cfe1bc6..0c07d63 100644 --- a/test/argument-placeholders.js +++ b/test/argument-placeholders.js @@ -67,7 +67,7 @@ describe("[argument-placeholders]", () => { describe("'{1}' should be replaced by the 1st argument preceded by '--':", () => { it("Node API", () => - nodeApi("test-task:dump {1}", {arguments: ["1st", "2nd"]}) + nodeApi("test-task:dump {1}", { arguments: ["1st", "2nd"] }) .then(() => assert(result() === "[\"1st\"]")) ) @@ -89,7 +89,7 @@ describe("[argument-placeholders]", () => { describe("'{2}' should be replaced by the 2nd argument preceded by '--':", () => { it("Node API", () => - nodeApi("test-task:dump {2}", {arguments: ["1st", "2nd"]}) + nodeApi("test-task:dump {2}", { arguments: ["1st", "2nd"] }) .then(() => assert(result() === "[\"2nd\"]")) ) @@ -111,7 +111,7 @@ describe("[argument-placeholders]", () => { describe("'{@}' should be replaced by the every argument preceded by '--':", () => { it("Node API", () => - nodeApi("test-task:dump {@}", {arguments: ["1st", "2nd"]}) + nodeApi("test-task:dump {@}", { arguments: ["1st", "2nd"] }) .then(() => assert(result() === "[\"1st\",\"2nd\"]")) ) @@ -133,7 +133,7 @@ describe("[argument-placeholders]", () => { describe("'{*}' should be replaced by the all arguments preceded by '--':", () => { it("Node API", () => - nodeApi("test-task:dump {*}", {arguments: ["1st", "2nd"]}) + nodeApi("test-task:dump {*}", { arguments: ["1st", "2nd"] }) .then(() => assert(result() === "[\"1st 2nd\"]")) ) @@ -155,7 +155,7 @@ describe("[argument-placeholders]", () => { describe("Every '{1}', '{2}', '{@}' and '{*}' should be replaced by the arguments preceded by '--':", () => { it("Node API", () => - nodeApi("test-task:dump {1} {2} {3} {@} {*}", {arguments: ["1st", "2nd"]}) + nodeApi("test-task:dump {1} {2} {3} {@} {*}", { arguments: ["1st", "2nd"] }) .then(() => assert(result() === "[\"1st\",\"2nd\",\"1st\",\"2nd\",\"1st 2nd\"]")) ) diff --git a/test/common.js b/test/common.js index 27d0a3b..ca118b1 100644 --- a/test/common.js +++ b/test/common.js @@ -30,192 +30,210 @@ describe("[common]", () => { beforeEach(removeResult) describe("should print a help text if arguments are nothing.", () => { - it("npm-run-all command", () => { + it("npm-run-all command", async () => { const buf = new BufferStream() - return runAll([], buf) - .then(() => assert(/Usage:/.test(buf.value))) + await runAll([], buf) + assert(/Usage:/.test(buf.value)) }) - it("run-s command", () => { + it("run-s command", async () => { const buf = new BufferStream() - return runSeq([], buf) - .then(() => assert(/Usage:/.test(buf.value))) + await runSeq([], buf) + assert(/Usage:/.test(buf.value)) }) - it("run-p command", () => { + it("run-p command", async () => { const buf = new BufferStream() - return runPar([], buf) - .then(() => assert(/Usage:/.test(buf.value))) + await runPar([], buf) + assert(/Usage:/.test(buf.value)) }) }) describe("should print a help text if the first argument is --help (-h)", () => { - it("npm-run-all command (-h)", () => { + it("npm-run-all command (-h)", async () => { const buf = new BufferStream() - return runAll(["-h"], buf) - .then(() => assert(/Usage:/.test(buf.value))) + await runAll(["-h"], buf) + assert(/Usage:/.test(buf.value)) }) - it("run-s command (-h)", () => { + it("run-s command (-h)", async () => { const buf = new BufferStream() - return runSeq(["-h"], buf) - .then(() => assert(/Usage:/.test(buf.value))) + await runSeq(["-h"], buf) + assert(/Usage:/.test(buf.value)) }) - it("run-p command (-h)", () => { + it("run-p command (-h)", async () => { const buf = new BufferStream() - return runPar(["-h"], buf) - .then(() => assert(/Usage:/.test(buf.value))) + await runPar(["-h"], buf) + assert(/Usage:/.test(buf.value)) }) - it("npm-run-all command (--help)", () => { + it("npm-run-all command (--help)", async () => { const buf = new BufferStream() - return runAll(["--help"], buf) - .then(() => assert(/Usage:/.test(buf.value))) + await runAll(["--help"], buf) + assert(/Usage:/.test(buf.value)) }) - it("run-s command (--help)", () => { + it("run-s command (--help)", async () => { const buf = new BufferStream() - return runSeq(["--help"], buf) - .then(() => assert(/Usage:/.test(buf.value))) + await runSeq(["--help"], buf) + assert(/Usage:/.test(buf.value)) }) - it("run-p command (--help)", () => { + it("run-p command (--help)", async () => { const buf = new BufferStream() - return runPar(["--help"], buf) - .then(() => assert(/Usage:/.test(buf.value))) + await runPar(["--help"], buf) + assert(/Usage:/.test(buf.value)) }) }) describe("should print a version number if the first argument is --version (-v)", () => { - it("npm-run-all command (-v)", () => { + it("npm-run-all command (-v)", async () => { const buf = new BufferStream() - return runAll(["-v"], buf) - .then(() => assert(/v[0-9]+\.[0-9]+\.[0-9]+/.test(buf.value))) + await runAll(["-v"], buf) + assert(/v[0-9]+\.[0-9]+\.[0-9]+/.test(buf.value)) }) - it("run-s command (-v)", () => { + it("run-s command (-v)", async () => { const buf = new BufferStream() - return runSeq(["-v"], buf) - .then(() => assert(/v[0-9]+\.[0-9]+\.[0-9]+/.test(buf.value))) + await runSeq(["-v"], buf) + assert(/v[0-9]+\.[0-9]+\.[0-9]+/.test(buf.value)) }) - it("run-p command (-v)", () => { + it("run-p command (-v)", async () => { const buf = new BufferStream() - return runPar(["-v"], buf) - .then(() => assert(/v[0-9]+\.[0-9]+\.[0-9]+/.test(buf.value))) + await runPar(["-v"], buf) + assert(/v[0-9]+\.[0-9]+\.[0-9]+/.test(buf.value)) }) - it("npm-run-all command (--version)", () => { + it("npm-run-all command (--version)", async () => { const buf = new BufferStream() - return runAll(["--version"], buf) - .then(() => assert(/v[0-9]+\.[0-9]+\.[0-9]+/.test(buf.value))) + await runAll(["--version"], buf) + assert(/v[0-9]+\.[0-9]+\.[0-9]+/.test(buf.value)) }) - it("run-s command (--version)", () => { + it("run-s command (--version)", async () => { const buf = new BufferStream() - return runSeq(["--version"], buf) - .then(() => assert(/v[0-9]+\.[0-9]+\.[0-9]+/.test(buf.value))) + await runSeq(["--version"], buf) + assert(/v[0-9]+\.[0-9]+\.[0-9]+/.test(buf.value)) }) - it("run-p command (--version)", () => { + it("run-p command (--version)", async () => { const buf = new BufferStream() - return runPar(["--version"], buf) - .then(() => assert(/v[0-9]+\.[0-9]+\.[0-9]+/.test(buf.value))) + await runPar(["--version"], buf) + assert(/v[0-9]+\.[0-9]+\.[0-9]+/.test(buf.value)) }) }) describe("should do nothing if a task list is empty.", () => { - it("Node API", () => - nodeApi(null).then(() => assert(result() == null)) + it("Node API", async () => { + await nodeApi(null) + assert(result() == null) + } ) }) describe("should run a task by npm (check an environment variable):", () => { - it("Node API", () => - nodeApi("test-task:package-config") - .then(() => assert(result() === "OK")) + it("Node API", async () => { + await nodeApi("test-task:package-config") + assert(result() === "OK") + } ) - it("npm-run-all command", () => - runAll(["test-task:package-config"]) - .then(() => assert(result() === "OK")) + it("npm-run-all command", async () => { + await runAll(["test-task:package-config"]) + assert(result() === "OK") + } ) - it("run-s command", () => - runSeq(["test-task:package-config"]) - .then(() => assert(result() === "OK")) + it("run-s command", async () => { + await runSeq(["test-task:package-config"]) + assert(result() === "OK") + } ) - it("run-p command", () => - runPar(["test-task:package-config"]) - .then(() => assert(result() === "OK")) + it("run-p command", async () => { + await runPar(["test-task:package-config"]) + assert(result() === "OK") + } ) }) describe("stdin can be used in tasks:", () => { - it("Node API", () => - nodeApi("test-task:stdin") - .then(() => assert(result().trim() === "STDIN")) + it("Node API", async () => { + await nodeApi("test-task:stdin") + assert(result().trim() === "STDIN") + } ) - it("npm-run-all command", () => - runAll(["test-task:stdin"]) - .then(() => assert(result().trim() === "STDIN")) + it("npm-run-all command", async () => { + await runAll(["test-task:stdin"]) + assert(result().trim() === "STDIN") + } ) - it("run-s command", () => - runSeq(["test-task:stdin"]) - .then(() => assert(result().trim() === "STDIN")) + it("run-s command", async () => { + await runSeq(["test-task:stdin"]) + assert(result().trim() === "STDIN") + } ) - it("run-p command", () => - runPar(["test-task:stdin"]) - .then(() => assert(result().trim() === "STDIN")) + it("run-p command", async () => { + await runPar(["test-task:stdin"]) + assert(result().trim() === "STDIN") + } ) }) describe("stdout can be used in tasks:", () => { - it("Node API", () => - nodeApi("test-task:stdout") - .then(() => assert(result() === "STDOUT")) + it("Node API", async () => { + await nodeApi("test-task:stdout") + assert(result() === "STDOUT") + } ) - it("npm-run-all command", () => - runAll(["test-task:stdout"]) - .then(() => assert(result() === "STDOUT")) + it("npm-run-all command", async () => { + await runAll(["test-task:stdout"]) + assert(result() === "STDOUT") + } ) - it("run-s command", () => - runSeq(["test-task:stdout"]) - .then(() => assert(result() === "STDOUT")) + it("run-s command", async () => { + await runSeq(["test-task:stdout"]) + assert(result() === "STDOUT") + } ) - it("run-p command", () => - runPar(["test-task:stdout"]) - .then(() => assert(result() === "STDOUT")) + it("run-p command", async () => { + await runPar(["test-task:stdout"]) + assert(result() === "STDOUT") + } ) }) describe("stderr can be used in tasks:", () => { - it("Node API", () => - nodeApi("test-task:stderr") - .then(() => assert(result() === "STDERR")) + it("Node API", async () => { + await nodeApi("test-task:stderr") + assert(result() === "STDERR") + } ) - it("npm-run-all command", () => - runAll(["test-task:stderr"]) - .then(() => assert(result() === "STDERR")) + it("npm-run-all command", async () => { + await runAll(["test-task:stderr"]) + assert(result() === "STDERR") + } ) - it("run-s command", () => - runSeq(["test-task:stderr"]) - .then(() => assert(result() === "STDERR")) + it("run-s command", async () => { + await runSeq(["test-task:stderr"]) + assert(result() === "STDERR") + } ) - it("run-p command", () => - runPar(["test-task:stderr"]) - .then(() => assert(result() === "STDERR")) + it("run-p command", async () => { + await runPar(["test-task:stderr"]) + assert(result() === "STDERR") + } ) }) @@ -251,14 +269,17 @@ describe("[common]", () => { } describe("should not print log if silent option was given:", () => { - it("Node API", () => { + it("Node API", async () => { const stdout = new BufferStream() const stderr = new BufferStream() - return nodeApi("test-task:error", {silent: true, stdout, stderr}) - .then( - () => assert(false, "Should fail."), - () => assert(stdout.value === "" && stderr.value === "") - ) + try { + await nodeApi("test-task:error", { silent: true, stdout, stderr }) + } + catch (_err) { + assert(stdout.value === "" && stderr.value === "") + return + } + assert(false, "Should fail.") }) /** @@ -270,34 +291,43 @@ describe("[common]", () => { return str.replace(/File \[.+?] ignored, nothing could be mapped\r?\n/, "") } - it("npm-run-all command", () => { + it("npm-run-all command", async () => { const stdout = new BufferStream() const stderr = new BufferStream() - return runAll(["--silent", "test-task:error"], stdout, stderr) - .then( - () => assert(false, "Should fail."), - () => assert(stdout.value === "" && stripIstanbulWarnings(stderr.value) === "") - ) + try { + await runAll(["--silent", "test-task:error"], stdout, stderr) + } + catch (_err) { + assert(stdout.value === "" && stripIstanbulWarnings(stderr.value) === "") + return + } + assert(false, "Should fail.") }) - it("run-s command", () => { + it("run-s command", async () => { const stdout = new BufferStream() const stderr = new BufferStream() - return runSeq(["--silent", "test-task:error"], stdout, stderr) - .then( - () => assert(false, "Should fail."), - () => assert(stdout.value === "" && stripIstanbulWarnings(stderr.value) === "") - ) + try { + await runSeq(["--silent", "test-task:error"], stdout, stderr) + } + catch (_err) { + assert(stdout.value === "" && stripIstanbulWarnings(stderr.value) === "") + return + } + assert(false, "Should fail.") }) - it("run-p command", () => { + it("run-p command", async () => { const stdout = new BufferStream() const stderr = new BufferStream() - return runPar(["--silent", "test-task:error"], stdout, stderr) - .then( - () => assert(false, "Should fail."), - () => assert(stdout.value === "" && stripIstanbulWarnings(stderr.value) === "") - ) + try { + await runPar(["--silent", "test-task:error"], stdout, stderr) + } + catch (_err) { + assert(stdout.value === "" && stripIstanbulWarnings(stderr.value) === "") + return + } + assert(false, "Should fail.") }) }) }) diff --git a/test/config.js b/test/config.js index bc79d4a..1dea0fc 100644 --- a/test/config.js +++ b/test/config.js @@ -28,86 +28,64 @@ describe("[config] it should have an ability to set config variables:", () => { beforeEach(removeResult) - it("Node API should address \"config\" option", () => - nodeApi("test-task:config", {config: {test: "this is a config"}}) - .then(() => { - assert(result() === "this is a config") - }) - ) - - it("Node API should address \"config\" option for multiple variables", () => - nodeApi("test-task:config2", {config: {test: "1", test2: "2", test3: "3"}}) - .then(() => { - assert(result() === "1\n2\n3") - }) - ) + it("Node API should address \"config\" option", async () => { + await nodeApi("test-task:config", { config: { test: "this is a config" } }) + assert(result() === "this is a config") + }) + + it("Node API should address \"config\" option for multiple variables", async () => { + await nodeApi("test-task:config2", { config: { test: "1", test2: "2", test3: "3" } }) + assert(result() === "1\n2\n3") + }) describe("CLI commands should address \"--a=b\" style options", () => { - it("npm-run-all command", () => - runAll(["test-task:config", "--test=GO"]) - .then(() => { - assert(result() === "GO") - }) - ) - - it("run-s command", () => - runSeq(["test-task:config", "--test=GO"]) - .then(() => { - assert(result() === "GO") - }) - ) - - it("run-p command", () => - runPar(["test-task:config", "--test=GO"]) - .then(() => { - assert(result() === "GO") - }) - ) + it("npm-run-all command", async () => { + await runAll(["test-task:config", "--test=GO"]) + assert(result() === "GO") + }) + + it("run-s command", async () => { + await runSeq(["test-task:config", "--test=GO"]) + assert(result() === "GO") + }) + + it("run-p command", async () => { + await runPar(["test-task:config", "--test=GO"]) + assert(result() === "GO") + }) }) describe("CLI commands should address \"--b=c\" style options for multiple variables", () => { - it("npm-run-all command", () => - runAll(["test-task:config2", "--test=1", "--test2=2", "--test3=3"]) - .then(() => { - assert(result() === "1\n2\n3") - }) - ) - - it("run-s command", () => - runSeq(["test-task:config2", "--test=1", "--test2=2", "--test3=3"]) - .then(() => { - assert(result() === "1\n2\n3") - }) - ) - - it("run-p command", () => - runPar(["test-task:config2", "--test=1", "--test2=2", "--test3=3"]) - .then(() => { - assert(result() === "1\n2\n3") - }) - ) + it("npm-run-all command", async () => { + await runAll(["test-task:config2", "--test=1", "--test2=2", "--test3=3"]) + assert(result() === "1\n2\n3") + }) + + it("run-s command", async () => { + await runSeq(["test-task:config2", "--test=1", "--test2=2", "--test3=3"]) + assert(result() === "1\n2\n3") + }) + + it("run-p command", async () => { + await runPar(["test-task:config2", "--test=1", "--test2=2", "--test3=3"]) + assert(result() === "1\n2\n3") + }) }) describe("CLI commands should transfar configs to nested commands.", () => { - it("npm-run-all command", () => - runAll(["test-task:nested-config", "--test=GO DEEP"]) - .then(() => { - assert(result() === "GO DEEP") - }) - ) - - it("run-s command", () => - runSeq(["test-task:nested-config", "--test=GO DEEP"]) - .then(() => { - assert(result() === "GO DEEP") - }) - ) - - it("run-p command", () => - runPar(["test-task:nested-config", "--test=GO DEEP"]) - .then(() => { - assert(result() === "GO DEEP") - }) - ) + it("npm-run-all command", async () => { + await runAll(["test-task:nested-config", "--test=GO DEEP"]) + assert(result() === "GO DEEP") + }) + + it("run-s command", async () => { + await runSeq(["test-task:nested-config", "--test=GO DEEP"]) + assert(result() === "GO DEEP") + }) + + it("run-p command", async () => { + await runPar(["test-task:nested-config", "--test=GO DEEP"]) + assert(result() === "GO DEEP") + }) }) }) diff --git a/test/fail.js b/test/fail.js index 2020c20..1b5cf16 100644 --- a/test/fail.js +++ b/test/fail.js @@ -56,7 +56,7 @@ describe("[fail] it should fail", () => { }) describe("if invalid `options.taskList` is given.", () => { - it("Node API", () => shouldFail(nodeApi("test-task:append a", {taskList: {invalid: 0}}))) + it("Node API", () => shouldFail(nodeApi("test-task:append a", { taskList: { invalid: 0 } }))) }) describe("if unknown tasks are given:", () => { diff --git a/test/lib/buffer-stream.js b/test/lib/buffer-stream.js index 9685c9f..798c1ef 100644 --- a/test/lib/buffer-stream.js +++ b/test/lib/buffer-stream.js @@ -36,11 +36,11 @@ module.exports = class BufferStream extends stream.Writable { * Accumulates written data. * * @param {string|Buffer} chunk - A written data. - * @param {string} encoding - The encoding of chunk. + * @param {string} _encoding - The encoding of chunk. * @param {function} callback - The callback to notify done. * @returns {void} */ - _write(chunk, encoding, callback) { + _write(chunk, _encoding, callback) { this.value += chunk.toString() callback() } diff --git a/test/lib/util.js b/test/lib/util.js index c1cee1d..3354978 100644 --- a/test/lib/util.js +++ b/test/lib/util.js @@ -39,7 +39,7 @@ function spawn(filePath, args, stdout, stderr) { const child = cp.spawn( process.execPath, [filePath].concat(args), - {stdio: "pipe"} + { stdio: "pipe" } ) const out = new BufferStream() const error = new BufferStream() @@ -77,7 +77,7 @@ function spawn(filePath, args, stdout, stderr) { */ module.exports.result = function result() { try { - return fs.readFileSync(FILE_NAME, {encoding: "utf8"}) + return fs.readFileSync(FILE_NAME, { encoding: "utf8" }) } catch (err) { if (err.code === "ENOENT") { diff --git a/test/mixed.js b/test/mixed.js index 4ad3d0f..99d7ec4 100644 --- a/test/mixed.js +++ b/test/mixed.js @@ -25,34 +25,32 @@ describe("[mixed] npm-run-all", () => { beforeEach(removeResult) - it("should run a mix of sequential and parallel tasks (has the default group):", () => - runAll([ + it("should run a mix of sequential and parallel tasks (has the default group):", async () => { + await runAll([ "test-task:append a", "-p", "test-task:append b", "test-task:append c", "-s", "test-task:append d", "test-task:append e", ]) - .then(() => { - assert( - result() === "aabcbcddee" || - result() === "aabccbddee" || - result() === "aacbbcddee" || - result() === "aacbcbddee") - }) - ) - - it("should run a mix of sequential and parallel tasks (doesn't have the default group):", () => - runAll([ + assert( + result() === "aabcbcddee" || + result() === "aabccbddee" || + result() === "aacbbcddee" || + result() === "aacbcbddee" + ) + }) + + it("should run a mix of sequential and parallel tasks (doesn't have the default group):", async () => { + await runAll([ "-p", "test-task:append b", "test-task:append c", "-s", "test-task:append d", "test-task:append e", ]) - .then(() => { - assert( - result() === "bcbcddee" || - result() === "bccbddee" || - result() === "cbbcddee" || - result() === "cbcbddee") - }) - ) + assert( + result() === "bcbcddee" || + result() === "bccbddee" || + result() === "cbbcddee" || + result() === "cbcbddee" + ) + }) it("should not throw errors for --race and --max-parallel options if --parallel exists:", () => runAll([ diff --git a/test/package-config.js b/test/package-config.js index 6c3aaf9..66c1d8c 100644 --- a/test/package-config.js +++ b/test/package-config.js @@ -28,109 +28,81 @@ describe("[package-config] it should have an ability to overwrite package's conf beforeEach(removeResult) - it("Node API should address \"packageConfig\" option", () => - nodeApi("test-task:package-config", {packageConfig: {"npm-run-all-test": {test: "OVERWRITTEN"}}}) - .then(() => { - assert(result() === "OVERWRITTEN") - }) - ) - - it("Node API should address \"packageConfig\" option for multiple variables", () => - nodeApi("test-task:package-config2", {packageConfig: {"npm-run-all-test": {test: "1", test2: "2", test3: "3"}}}) - .then(() => { - assert(result() === "1\n2\n3") - }) - ) + it("Node API should address \"packageConfig\" option", async () => { + await nodeApi("test-task:package-config", { packageConfig: { "npm-run-all-test": { test: "OVERWRITTEN" } } }) + assert(result() === "OVERWRITTEN") + }) + + it("Node API should address \"packageConfig\" option for multiple variables", async () => { + await nodeApi("test-task:package-config2", { packageConfig: { "npm-run-all-test": { test: "1", test2: "2", test3: "3" } } }) + assert(result() === "1\n2\n3") + }) describe("CLI commands should address \"--a:b=c\" style options", () => { - it("npm-run-all command", () => - runAll(["test-task:package-config", "--npm-run-all-test:test=OVERWRITTEN"]) - .then(() => { - assert(result() === "OVERWRITTEN") - }) - ) - - it("run-s command", () => - runSeq(["test-task:package-config", "--npm-run-all-test:test=OVERWRITTEN"]) - .then(() => { - assert(result() === "OVERWRITTEN") - }) - ) - - it("run-p command", () => - runPar(["test-task:package-config", "--npm-run-all-test:test=OVERWRITTEN"]) - .then(() => { - assert(result() === "OVERWRITTEN") - }) - ) + it("npm-run-all command", async () => { + await runAll(["test-task:package-config", "--npm-run-all-test:test=OVERWRITTEN"]) + assert(result() === "OVERWRITTEN") + }) + + it("run-s command", async () => { + await runSeq(["test-task:package-config", "--npm-run-all-test:test=OVERWRITTEN"]) + assert(result() === "OVERWRITTEN") + }) + + it("run-p command", async () => { + await runPar(["test-task:package-config", "--npm-run-all-test:test=OVERWRITTEN"]) + assert(result() === "OVERWRITTEN") + }) }) describe("CLI commands should address \"--a:b=c\" style options for multiple variables", () => { - it("npm-run-all command", () => - runAll(["test-task:package-config2", "--npm-run-all-test:test=1", "--npm-run-all-test:test2=2", "--npm-run-all-test:test3=3"]) - .then(() => { - assert(result() === "1\n2\n3") - }) - ) - - it("run-s command", () => - runSeq(["test-task:package-config2", "--npm-run-all-test:test=1", "--npm-run-all-test:test2=2", "--npm-run-all-test:test3=3"]) - .then(() => { - assert(result() === "1\n2\n3") - }) - ) - - it("run-p command", () => - runPar(["test-task:package-config2", "--npm-run-all-test:test=1", "--npm-run-all-test:test2=2", "--npm-run-all-test:test3=3"]) - .then(() => { - assert(result() === "1\n2\n3") - }) - ) + it("npm-run-all command", async () => { + await runAll(["test-task:package-config2", "--npm-run-all-test:test=1", "--npm-run-all-test:test2=2", "--npm-run-all-test:test3=3"]) + assert(result() === "1\n2\n3") + }) + + it("run-s command", async () => { + await runSeq(["test-task:package-config2", "--npm-run-all-test:test=1", "--npm-run-all-test:test2=2", "--npm-run-all-test:test3=3"]) + assert(result() === "1\n2\n3") + }) + + it("run-p command", async () => { + await runPar(["test-task:package-config2", "--npm-run-all-test:test=1", "--npm-run-all-test:test2=2", "--npm-run-all-test:test3=3"]) + assert(result() === "1\n2\n3") + }) }) describe("CLI commands should address \"--a:b c\" style options", () => { - it("npm-run-all command", () => - runAll(["test-task:package-config", "--npm-run-all-test:test", "OVERWRITTEN"]) - .then(() => { - assert(result() === "OVERWRITTEN") - }) - ) - - it("run-s command", () => - runSeq(["test-task:package-config", "--npm-run-all-test:test", "OVERWRITTEN"]) - .then(() => { - assert(result() === "OVERWRITTEN") - }) - ) - - it("run-p command", () => - runPar(["test-task:package-config", "--npm-run-all-test:test", "OVERWRITTEN"]) - .then(() => { - assert(result() === "OVERWRITTEN") - }) - ) + it("npm-run-all command", async () => { + await runAll(["test-task:package-config", "--npm-run-all-test:test", "OVERWRITTEN"]) + assert(result() === "OVERWRITTEN") + }) + + it("run-s command", async () => { + await runSeq(["test-task:package-config", "--npm-run-all-test:test", "OVERWRITTEN"]) + assert(result() === "OVERWRITTEN") + }) + + it("run-p command", async () => { + await runPar(["test-task:package-config", "--npm-run-all-test:test", "OVERWRITTEN"]) + assert(result() === "OVERWRITTEN") + }) }) describe("CLI commands should transfar overriting nested commands.", () => { - it("npm-run-all command", () => - runAll(["test-task:nested-package-config", "--npm-run-all-test:test", "OVERWRITTEN"]) - .then(() => { - assert(result() === "OVERWRITTEN") - }) - ) - - it("run-s command", () => - runSeq(["test-task:nested-package-config", "--npm-run-all-test:test", "OVERWRITTEN"]) - .then(() => { - assert(result() === "OVERWRITTEN") - }) - ) - - it("run-p command", () => - runPar(["test-task:nested-package-config", "--npm-run-all-test:test", "OVERWRITTEN"]) - .then(() => { - assert(result() === "OVERWRITTEN") - }) - ) + it("npm-run-all command", async () => { + await runAll(["test-task:nested-package-config", "--npm-run-all-test:test", "OVERWRITTEN"]) + assert(result() === "OVERWRITTEN") + }) + + it("run-s command", async () => { + await runSeq(["test-task:nested-package-config", "--npm-run-all-test:test", "OVERWRITTEN"]) + assert(result() === "OVERWRITTEN") + }) + + it("run-p command", async () => { + await runPar(["test-task:nested-package-config", "--npm-run-all-test:test", "OVERWRITTEN"]) + assert(result() === "OVERWRITTEN") + }) }) }) diff --git a/test/parallel.js b/test/parallel.js index 18c7848..540795e 100644 --- a/test/parallel.js +++ b/test/parallel.js @@ -30,326 +30,287 @@ describe("[parallel]", () => { beforeEach(() => delay(1000).then(removeResult)) describe("should run tasks on parallel when was given --parallel option:", () => { - it("Node API", () => - nodeApi(["test-task:append a", "test-task:append b"], {parallel: true}) - .then(results => { - 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() === "abab" || + it("Node API", async () => { + const results = await nodeApi(["test-task:append a", "test-task:append b"], { parallel: true }) + 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() === "abab" || result() === "baba" || result() === "abba" || result() === "baab") - }) - ) - - it("npm-run-all command", () => - runAll(["--parallel", "test-task:append a", "test-task:append b"]) - .then(() => { - assert( - result() === "abab" || + }) + + it("npm-run-all command", async () => { + await runAll(["--parallel", "test-task:append a", "test-task:append b"]) + assert( + result() === "abab" || result() === "baba" || result() === "abba" || result() === "baab") - }) - ) - - it("run-p command", () => - runPar(["test-task:append a", "test-task:append b"]) - .then(() => { - assert( - result() === "abab" || + }) + + it("run-p command", async () => { + await runPar(["test-task:append a", "test-task:append b"]) + assert( + result() === "abab" || result() === "baba" || result() === "abba" || result() === "baab") - }) - ) + }) }) describe("should kill all tasks when was given --parallel option if a task exited with a non-zero code:", () => { - it("Node API", () => - nodeApi(["test-task:append2 a", "test-task:error"], {parallel: true}) - .then( - () => { - assert(false, "should fail") - }, - (err) => { - assert(err.results.length === 2) - assert(err.results[0].name === "test-task:append2 a") - assert(err.results[0].code === undefined) - assert(err.results[1].name === "test-task:error") - assert(err.results[1].code === 1) - assert(result() == null || result() === "a") - }) - ) - - it("npm-run-all command", () => - runAll(["--parallel", "test-task:append2 a", "test-task:error"]) - .then( - () => { - assert(false, "should fail") - }, - () => { - assert(result() == null || result() === "a") - } - ) - ) - - it("run-p command", () => - runPar(["test-task:append2 a", "test-task:error"]) - .then( - () => { - assert(false, "should fail") - }, - () => { - assert(result() == null || result() === "a") - } - ) - ) + it("Node API", async () => { + try { + await nodeApi(["test-task:append2 a", "test-task:error"], { parallel: true }) + } + catch (err) { + assert(err.results.length === 2) + assert(err.results[0].name === "test-task:append2 a") + assert(err.results[0].code === undefined) + assert(err.results[1].name === "test-task:error") + assert(err.results[1].code === 1) + assert(result() == null || result() === "a") + return + } + assert(false, "should fail") + }) + + it("npm-run-all command", async () => { + try { + await runAll(["--parallel", "test-task:append2 a", "test-task:error"]) + } + catch (_err) { + assert(result() == null || result() === "a") + return + } + assert(false, "should fail") + }) + + it("run-p command", async () => { + try { + await runPar(["test-task:append2 a", "test-task:error"]) + } + catch (_err) { + assert(result() == null || result() === "a") + return + } + assert(false, "should fail") + }) }) describe("should remove intersected tasks from two or more patterns:", () => { - it("Node API", () => - nodeApi(["test-task:*:a", "*:append:a"], {parallel: true}) - .then(() => { - assert(result() === "aa") - }) - ) - - it("npm-run-all command", () => - runAll(["--parallel", "test-task:*:a", "*:append:a"]) - .then(() => { - assert(result() === "aa") - }) - ) - - it("run-p command", () => - runPar(["test-task:*:a", "*:append:a"]) - .then(() => { - assert(result() === "aa") - }) - ) + it("Node API", async () => { + await nodeApi(["test-task:*:a", "*:append:a"], { parallel: true }) + assert(result() === "aa") + }) + + it("npm-run-all command", async () => { + await runAll(["--parallel", "test-task:*:a", "*:append:a"]) + assert(result() === "aa") + }) + + it("run-p command", async () => { + await runPar(["test-task:*:a", "*:append:a"]) + assert(result() === "aa") + }) }) describe("should not remove duplicate tasks from two or more the same pattern:", () => { - it("Node API", () => - nodeApi(["test-task:*:a", "test-task:*:a"], {parallel: true}) - .then(() => { - assert(result() === "aaaa") - }) - ) - - it("npm-run-all command", () => - runAll(["--parallel", "test-task:*:a", "test-task:*:a"]) - .then(() => { - assert(result() === "aaaa") - }) - ) - - it("run-p command", () => - runPar(["test-task:*:a", "test-task:*:a"]) - .then(() => { - assert(result() === "aaaa") - }) - ) + it("Node API", async () => { + await nodeApi(["test-task:*:a", "test-task:*:a"], { parallel: true }) + assert(result() === "aaaa") + }) + + it("npm-run-all command", async () => { + await runAll(["--parallel", "test-task:*:a", "test-task:*:a"]) + assert(result() === "aaaa") + }) + + it("run-p command", async () => { + await runPar(["test-task:*:a", "test-task:*:a"]) + assert(result() === "aaaa") + }) }) describe("should kill child processes when it's killed", () => { - it("npm-run-all command", () => - spawnWithKill( + it("npm-run-all command", async () => { + await spawnWithKill( "node", ["../bin/npm-run-all/index.js", "--parallel", "test-task:append2 a"] ) - .then(() => { - assert(result() == null || result() === "a") - }) - ) + assert(result() == null || result() === "a") + }) - it("run-p command", () => - spawnWithKill( + it("run-p command", async () => { + await spawnWithKill( "node", ["../bin/run-p/index.js", "test-task:append2 a"] ) - .then(() => { - assert(result() == null || result() === "a") - }) - ) + assert(result() == null || result() === "a") + }) }) describe("should continue on error when --continue-on-error option was specified:", () => { - it("Node API", () => - nodeApi(["test-task:append a", "test-task:error", "test-task:append b"], {parallel: true, continueOnError: true}) - .then( - () => { - assert(false, "should fail.") - }, - () => { - assert( - result() === "abab" || - result() === "baba" || - result() === "abba" || - result() === "baab") - } + it("Node API", async () => { + try { + await nodeApi(["test-task:append a", "test-task:error", "test-task:append b"], { parallel: true, continueOnError: true }) + } + catch (_err) { + assert( + result() === "abab" || + result() === "baba" || + result() === "abba" || + result() === "baab" ) - ) - - it("npm-run-all command (--continue-on-error)", () => - runAll(["--continue-on-error", "--parallel", "test-task:append a", "test-task:error", "test-task:append b"]) - .then( - () => { - assert(false, "should fail.") - }, - () => { - assert( - result() === "abab" || - result() === "baba" || - result() === "abba" || - result() === "baab") - } + return + } + assert(false, "should fail.") + }) + + it("npm-run-all command (--continue-on-error)", async () => { + try { + await runAll(["--continue-on-error", "--parallel", "test-task:append a", "test-task:error", "test-task:append b"]) + } + catch (_err) { + assert( + result() === "abab" || + result() === "baba" || + result() === "abba" || + result() === "baab" ) - ) - - it("npm-run-all command (-c)", () => - runAll(["-cp", "test-task:append a", "test-task:error", "test-task:append b"]) - .then( - () => { - assert(false, "should fail.") - }, - () => { - assert( - result() === "abab" || - result() === "baba" || - result() === "abba" || - result() === "baab") - } + return + } + assert(false, "should fail.") + }) + + it("npm-run-all command (-c)", async () => { + try { + await runAll(["-cp", "test-task:append a", "test-task:error", "test-task:append b"]) + } + catch (_err) { + assert( + result() === "abab" || + result() === "baba" || + result() === "abba" || + result() === "baab" ) - ) - - it("run-p command (--continue-on-error)", () => - runPar(["--continue-on-error", "test-task:append a", "test-task:error", "test-task:append b"]) - .then( - () => { - assert(false, "should fail.") - }, - () => { - assert( - result() === "abab" || - result() === "baba" || - result() === "abba" || - result() === "baab") - } + return + } + assert(false, "should fail.") + }) + + it("run-p command (--continue-on-error)", async () => { + try { + await runPar(["--continue-on-error", "test-task:append a", "test-task:error", "test-task:append b"]) + } + catch (_err) { + assert( + result() === "abab" || + result() === "baba" || + result() === "abba" || + result() === "baab" ) - ) - - it("run-p command (-c)", () => - runPar(["-c", "test-task:append a", "test-task:error", "test-task:append b"]) - .then( - () => { - assert(false, "should fail.") - }, - () => { - assert( - result() === "abab" || - result() === "baba" || - result() === "abba" || - result() === "baab") - } + return + } + assert(false, "should fail.") + }) + + it("run-p command (-c)", async () => { + try { + await runPar(["-c", "test-task:append a", "test-task:error", "test-task:append b"]) + } + catch (_err) { + assert( + result() === "abab" || + result() === "baba" || + result() === "abba" || + result() === "baab" ) - ) + return + } + assert(false, "should fail.") + }) }) describe("should abort other tasks when a task finished, when --race option was specified:", () => { - it("Node API", () => - nodeApi(["test-task:append1 a", "test-task:append2 b"], {parallel: true, race: true}) - .then(() => delay(1000)) - .then(() => { - assert(result() === "a" || result() === "ab" || result() === "ba") - }) - ) - - it("npm-run-all command (--race)", () => - runAll(["--race", "--parallel", "test-task:append1 a", "test-task:append2 b"]) - .then(() => delay(1000)) - .then(() => { - assert(result() === "a" || result() === "ab" || result() === "ba") - }) - ) - - it("npm-run-all command (-r)", () => - runAll(["-rp", "test-task:append1 a", "test-task:append2 b"]) - .then(() => delay(1000)) - .then(() => { - assert(result() === "a" || result() === "ab" || result() === "ba") - }) - ) - - it("run-p command (--race)", () => - runPar(["--race", "test-task:append1 a", "test-task:append2 b"]) - .then(() => delay(1000)) - .then(() => { - assert(result() === "a" || result() === "ab" || result() === "ba") - }) - ) - - it("run-p command (-r)", () => - runPar(["-r", "test-task:append1 a", "test-task:append2 b"]) - .then(() => delay(1000)) - .then(() => { - assert(result() === "a" || result() === "ab" || result() === "ba") - }) - ) - - it("run-p command (no -r)", () => - runPar(["test-task:append1 a", "test-task:append2 b"]) - .then(() => delay(1000)) - .then(() => { - assert(result() === "abb" || result() === "bab") - }) - ) + it("Node API", async () => { + await nodeApi(["test-task:append1 a", "test-task:append2 b"], { parallel: true, race: true }) + await delay(1000) + assert(result() === "a" || result() === "ab" || result() === "ba") + }) + + it("npm-run-all command (--race)", async () => { + await runAll(["--race", "--parallel", "test-task:append1 a", "test-task:append2 b"]) + await delay(1000) + assert(result() === "a" || result() === "ab" || result() === "ba") + }) + + it("npm-run-all command (-r)", async () => { + await runAll(["-rp", "test-task:append1 a", "test-task:append2 b"]) + await delay(1000) + assert(result() === "a" || result() === "ab" || result() === "ba") + }) + + it("run-p command (--race)", async () => { + await runPar(["--race", "test-task:append1 a", "test-task:append2 b"]) + await delay(1000) + assert(result() === "a" || result() === "ab" || result() === "ba") + }) + + it("run-p command (-r)", async () => { + await runPar(["-r", "test-task:append1 a", "test-task:append2 b"]) + await delay(1000) + assert(result() === "a" || result() === "ab" || result() === "ba") + }) + + it("run-p command (no -r)", async () => { + await runPar(["test-task:append1 a", "test-task:append2 b"]) + await delay(1000) + assert(result() === "abb" || result() === "bab") + }) }) describe("should run tasks in parallel-2 when was given --max-parallel 2 option:", () => { - it("Node API", () => - nodeApi(["test-task:append a", "test-task:append b", "test-task:append c"], {parallel: true, maxParallel: 2}) - .then(results => { - assert(results.length === 3) - 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(results[2].name === "test-task:append c") - assert(results[2].code === 0) - assert( - result() === "ababcc" || - result() === "babacc" || - result() === "abbacc" || - result() === "baabcc") - }) - ) - - it("npm-run-all command", () => - runAll(["--parallel", "test-task:append a", "test-task:append b", "test-task:append c", "--max-parallel", "2"]) - .then(() => { - assert( - result() === "ababcc" || - result() === "babacc" || - result() === "abbacc" || - result() === "baabcc") - }) - ) - - it("run-p command", () => - runPar(["test-task:append a", "test-task:append b", "test-task:append c", "--max-parallel", "2"]) - .then(() => { - assert( - result() === "ababcc" || - result() === "babacc" || - result() === "abbacc" || - result() === "baabcc") - }) - ) + it("Node API", async () => { + const results = await nodeApi(["test-task:append a", "test-task:append b", "test-task:append c"], { parallel: true, maxParallel: 2 }) + assert(results.length === 3) + 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(results[2].name === "test-task:append c") + assert(results[2].code === 0) + assert( + result() === "ababcc" || + result() === "babacc" || + result() === "abbacc" || + result() === "baabcc" + ) + }) + + it("npm-run-all command", async () => { + await runAll(["--parallel", "test-task:append a", "test-task:append b", "test-task:append c", "--max-parallel", "2"]) + assert( + result() === "ababcc" || + result() === "babacc" || + result() === "abbacc" || + result() === "baabcc" + ) + }) + + it("run-p command", async () => { + await runPar(["test-task:append a", "test-task:append b", "test-task:append c", "--max-parallel", "2"]) + assert( + result() === "ababcc" || + result() === "babacc" || + result() === "abbacc" || + result() === "baabcc" + ) + }) }) }) diff --git a/test/pattern.js b/test/pattern.js index 9f5be9a..bbe8580 100644 --- a/test/pattern.js +++ b/test/pattern.js @@ -29,132 +29,118 @@ describe("[pattern] it should run matched tasks if glob like patterns are given. beforeEach(removeResult) describe("\"test-task:append:*\" to \"test-task:append:a\" and \"test-task:append:b\"", () => { - it("Node API", () => - nodeApi("test-task:append:*") - .then(() => { - assert(result() === "aabb") - }) - ) - - it("npm-run-all command", () => - runAll(["test-task:append:*"]) - .then(() => { - assert(result() === "aabb") - }) - ) - - it("run-s command", () => - runSeq(["test-task:append:*"]) - .then(() => { - assert(result() === "aabb") - }) - ) - - it("run-p command", () => - runPar(["test-task:append:*"]) - .then(() => { - assert( - result() === "abab" || - result() === "abba" || - result() === "baba" || - result() === "baab" - ) - }) - ) + it("Node API", async () => { + await nodeApi("test-task:append:*") + assert(result() === "aabb") + }) + + it("npm-run-all command", async () => { + await runAll(["test-task:append:*"]) + assert(result() === "aabb") + }) + + it("run-s command", async () => { + await runSeq(["test-task:append:*"]) + assert(result() === "aabb") + }) + + it("run-p command", async () => { + await runPar(["test-task:append:*"]) + assert( + result() === "abab" || + result() === "abba" || + result() === "baba" || + result() === "baab" + ) + }) }) describe("\"test-task:append:**:*\" to \"test-task:append:a\", \"test-task:append:a:c\", \"test-task:append:a:d\", and \"test-task:append:b\"", () => { - it("Node API", () => - nodeApi("test-task:append:**:*") - .then(() => { - assert(result() === "aaacacadadbb") - }) - ) - - it("npm-run-all command", () => - runAll(["test-task:append:**:*"]) - .then(() => { - assert(result() === "aaacacadadbb") - }) - ) - - it("run-s command", () => - runSeq(["test-task:append:**:*"]) - .then(() => { - assert(result() === "aaacacadadbb") - }) - ) + it("Node API", async () => { + await nodeApi("test-task:append:**:*") + assert(result() === "aaacacadadbb") + }) + + it("npm-run-all command", async () => { + await runAll(["test-task:append:**:*"]) + assert(result() === "aaacacadadbb") + }) + + it("run-s command", async () => { + await runSeq(["test-task:append:**:*"]) + assert(result() === "aaacacadadbb") + }) }) describe("(should ignore duplications) \"test-task:append:b\" \"test-task:append:*\" to \"test-task:append:b\", \"test-task:append:a\"", () => { - it("Node API", () => - nodeApi(["test-task:append:b", "test-task:append:*"]) - .then(() => { - assert(result() === "bbaa") - }) - ) - - it("npm-run-all command", () => - runAll(["test-task:append:b", "test-task:append:*"]) - .then(() => { - assert(result() === "bbaa") - }) - ) - - it("run-s command", () => - runSeq(["test-task:append:b", "test-task:append:*"]) - .then(() => { - assert(result() === "bbaa") - }) - ) - - it("run-p command", () => - runPar(["test-task:append:b", "test-task:append:*"]) - .then(() => { - assert( - result() === "baba" || - result() === "baab" || - result() === "abab" || - result() === "abba" - ) - }) - ) + it("Node API", async () => { + await nodeApi(["test-task:append:b", "test-task:append:*"]) + assert(result() === "bbaa") + }) + + it("npm-run-all command", async () => { + await runAll(["test-task:append:b", "test-task:append:*"]) + assert(result() === "bbaa") + }) + + it("run-s command", async () => { + await runSeq(["test-task:append:b", "test-task:append:*"]) + assert(result() === "bbaa") + }) + + it("run-p command", async () => { + await runPar(["test-task:append:b", "test-task:append:*"]) + assert( + result() === "baba" || + result() === "baab" || + result() === "abab" || + result() === "abba" + ) + }) }) describe("\"a\" should not match to \"test-task:append:a\"", () => { - it("Node API", () => - nodeApi("a") - .then( - () => assert(false, "should not match"), - (err) => assert((/not found/i).test(err.message)) - ) - ) - - it("npm-run-all command", () => { + it("Node API", async () => { + try { + await nodeApi("a") + assert(false, "should not match") + } + catch (err) { + assert((/not found/i).test(err.message)) + } + }) + + it("npm-run-all command", async () => { const stderr = new BufferStream() - return runAll(["a"], null, stderr) - .then( - () => assert(false, "should not match"), - () => assert((/not found/i).test(stderr.value)) - ) + try { + await runAll(["a"], null, stderr) + assert(false, "should not match") + } + catch (_err) { + assert((/not found/i).test(stderr.value)) + } }) - it("run-s command", () => { + it("run-s command", async () => { const stderr = new BufferStream() - return runSeq(["a"], null, stderr) - .then( - () => assert(false, "should not match"), - () => assert((/not found/i).test(stderr.value)) - ) + try { + await runSeq(["a"], null, stderr) + assert(false, "should not match") + } + catch (_err) { + assert((/not found/i).test(stderr.value)) + } }) - it("run-p command", () => { + it("run-p command", async () => { const stderr = new BufferStream() - return runPar(["a"], null, stderr) - .then( - () => assert(false, "should not match"), - () => assert((/not found/i).test(stderr.value)) - ) + try { + await runPar(["a"], null, stderr) + assert(false, "should not match") + } + catch (_err) { + assert((/not found/i).test(stderr.value)) + } }) }) }) diff --git a/test/print-label.js b/test/print-label.js index 817c470..2e1bc44 100644 --- a/test/print-label.js +++ b/test/print-label.js @@ -44,60 +44,46 @@ describe("[print-label] npm-run-all", () => { "[test-task:echo abc] abc", ].join("\n") - it("Node API", () => { + it("Node API", async () => { const stdout = new BufferStream() - return nodeApi("test-task:echo abc", {stdout, silent: true, printLabel: true}) - .then(() => { - assert.equal(stdout.value, EXPECTED_TEXT) - }) + await nodeApi("test-task:echo abc", { stdout, silent: true, printLabel: true }) + assert.equal(stdout.value, EXPECTED_TEXT) }) - it("npm-run-all command (--print-label)", () => { + it("npm-run-all command (--print-label)", async () => { const stdout = new BufferStream() - return runAll(["test-task:echo abc", "--silent", "--print-label"], stdout) - .then(() => { - assert.equal(stdout.value, EXPECTED_TEXT) - }) + await runAll(["test-task:echo abc", "--silent", "--print-label"], stdout) + assert.equal(stdout.value, EXPECTED_TEXT) }) - it("run-s command (--print-label)", () => { + it("run-s command (--print-label)", async () => { const stdout = new BufferStream() - return runSeq(["test-task:echo abc", "--silent", "--print-label"], stdout) - .then(() => { - assert.equal(stdout.value, EXPECTED_TEXT) - }) + await runSeq(["test-task:echo abc", "--silent", "--print-label"], stdout) + assert.equal(stdout.value, EXPECTED_TEXT) }) - it("run-p command (--print-label)", () => { + it("run-p command (--print-label)", async () => { const stdout = new BufferStream() - return runPar(["test-task:echo abc", "--silent", "--print-label"], stdout) - .then(() => { - assert.equal(stdout.value, EXPECTED_TEXT) - }) + await runPar(["test-task:echo abc", "--silent", "--print-label"], stdout) + assert.equal(stdout.value, EXPECTED_TEXT) }) - it("npm-run-all command (-l)", () => { + it("npm-run-all command (-l)", async () => { const stdout = new BufferStream() - return runAll(["test-task:echo abc", "--silent", "-l"], stdout) - .then(() => { - assert.equal(stdout.value, EXPECTED_TEXT) - }) + await runAll(["test-task:echo abc", "--silent", "-l"], stdout) + assert.equal(stdout.value, EXPECTED_TEXT) }) - it("run-s command (-l)", () => { + it("run-s command (-l)", async () => { const stdout = new BufferStream() - return runSeq(["test-task:echo abc", "--silent", "-l"], stdout) - .then(() => { - assert.equal(stdout.value, EXPECTED_TEXT) - }) + await runSeq(["test-task:echo abc", "--silent", "-l"], stdout) + assert.equal(stdout.value, EXPECTED_TEXT) }) - it("run-p command (-l)", () => { + it("run-p command (-l)", async () => { const stdout = new BufferStream() - return runPar(["test-task:echo abc", "--silent", "-l"], stdout) - .then(() => { - assert.equal(stdout.value, EXPECTED_TEXT) - }) + await runPar(["test-task:echo abc", "--silent", "-l"], stdout) + assert.equal(stdout.value, EXPECTED_TEXT) }) }) @@ -150,37 +136,31 @@ describe("[print-label] npm-run-all", () => { "[test-task:echo ab ] ab", ].join("\n") - it("Node API", () => { + it("Node API", async () => { const stdout = new BufferStream() - return nodeApi( - ["test-task:echo a", "test-task:echo abcd", "test-task:echo ab"], - {stdout, silent: true, printLabel: true} - ) - .then(() => { - assert.equal(stdout.value, EXPECTED_TEXT) - }) + await nodeApi( + ["test-task:echo a", "test-task:echo abcd", "test-task:echo ab"], + { stdout, silent: true, printLabel: true } + ) + assert.equal(stdout.value, EXPECTED_TEXT) }) - it("npm-run-all command", () => { + it("npm-run-all command", async () => { const stdout = new BufferStream() - return runAll( - ["test-task:echo a", "test-task:echo abcd", "test-task:echo ab", "--silent", "--print-label"], - stdout - ) - .then(() => { - assert.equal(stdout.value, EXPECTED_TEXT) - }) + await runAll( + ["test-task:echo a", "test-task:echo abcd", "test-task:echo ab", "--silent", "--print-label"], + stdout + ) + assert.equal(stdout.value, EXPECTED_TEXT) }) - it("run-s command", () => { + it("run-s command", async () => { const stdout = new BufferStream() - return runSeq( - ["test-task:echo a", "test-task:echo abcd", "test-task:echo ab", "--silent", "--print-label"], - stdout - ) - .then(() => { - assert.equal(stdout.value, EXPECTED_TEXT) - }) + await runSeq( + ["test-task:echo a", "test-task:echo abcd", "test-task:echo ab", "--silent", "--print-label"], + stdout + ) + assert.equal(stdout.value, EXPECTED_TEXT) }) }) @@ -199,53 +179,46 @@ describe("[print-label] npm-run-all", () => { /\n\n/, ] - it("Node API", () => { + it("Node API", async () => { const stdout = new BufferStream() - return nodeApi( - ["test-task:echo a", "test-task:echo abcd", "test-task:echo ab"], - {stdout, parallel: true, printLabel: true} - ) - .then(() => { - EXPECTED_LINES.forEach(line => { - assert(stdout.value.indexOf(line) !== -1) - }) - UNEXPECTED_PATTERNS.forEach(pattern => { - assert(!pattern.test(stdout.value)) - }) - }) + await nodeApi( + ["test-task:echo a", "test-task:echo abcd", "test-task:echo ab"], + { stdout, parallel: true, printLabel: true } + ) + for (const line of EXPECTED_LINES) { + assert(stdout.value.indexOf(line) !== -1) + } + for (const pattern of UNEXPECTED_PATTERNS) { + assert(!pattern.test(stdout.value)) + } }) - it("npm-run-all command", () => { + it("npm-run-all command", async () => { const stdout = new BufferStream() - return runAll( - ["--parallel", "test-task:echo a", "test-task:echo abcd", "test-task:echo ab", "--print-label"], - stdout - ) - .then(() => { - EXPECTED_LINES.forEach(line => { - assert(stdout.value.indexOf(line) !== -1) - }) - UNEXPECTED_PATTERNS.forEach(pattern => { - assert(!pattern.test(stdout.value)) - }) - }) + await runAll( + ["--parallel", "test-task:echo a", "test-task:echo abcd", "test-task:echo ab", "--print-label"], + stdout + ) + for (const line of EXPECTED_LINES) { + assert(stdout.value.indexOf(line) !== -1) + } + for (const pattern of UNEXPECTED_PATTERNS) { + assert(!pattern.test(stdout.value)) + } }) - it("run-p command", () => { + it("run-p command", async () => { const stdout = new BufferStream() - return runPar( - ["test-task:echo a", "test-task:echo abcd", "test-task:echo ab", "--print-label"], - stdout - ) - .then(() => { - EXPECTED_LINES.forEach(line => { - assert(stdout.value.indexOf(line) !== -1) - }) - UNEXPECTED_PATTERNS.forEach(pattern => { - assert(!pattern.test(stdout.value)) - }) - }) + await runPar( + ["test-task:echo a", "test-task:echo abcd", "test-task:echo ab", "--print-label"], + stdout + ) + for (const line of EXPECTED_LINES) { + assert(stdout.value.indexOf(line) !== -1) + } + for (const pattern of UNEXPECTED_PATTERNS) { + assert(!pattern.test(stdout.value)) + } }) }) }) - diff --git a/test/print-name.js b/test/print-name.js index 9e0029a..256b14a 100644 --- a/test/print-name.js +++ b/test/print-name.js @@ -35,67 +35,53 @@ describe("[print-name] npm-run-all", () => { after(() => process.chdir("..")) describe("should print names before running tasks:", () => { - it("Node API", () => { + it("Node API", async () => { const stdout = new BufferStream() - return nodeApi("test-task:echo abc", {stdout, silent: true, printName: true}) - .then(() => { - const header = createHeader("test-task:echo abc", packageInfo, false) - assert.equal(stdout.value.slice(0, header.length), header) - }) + await nodeApi("test-task:echo abc", { stdout, silent: true, printName: true }) + const header = createHeader("test-task:echo abc", packageInfo, false) + assert.equal(stdout.value.slice(0, header.length), header) }) - it("npm-run-all command (--print-name)", () => { + it("npm-run-all command (--print-name)", async () => { const stdout = new BufferStream() - return runAll(["test-task:echo abc", "--silent", "--print-name"], stdout) - .then(() => { - const header = createHeader("test-task:echo abc", packageInfo, false) - assert.equal(stdout.value.slice(0, header.length), header) - }) + await runAll(["test-task:echo abc", "--silent", "--print-name"], stdout) + const header = createHeader("test-task:echo abc", packageInfo, false) + assert.equal(stdout.value.slice(0, header.length), header) }) - it("run-s command (--print-name)", () => { + it("run-s command (--print-name)", async () => { const stdout = new BufferStream() - return runSeq(["test-task:echo abc", "--silent", "--print-name"], stdout) - .then(() => { - const header = createHeader("test-task:echo abc", packageInfo, false) - assert.equal(stdout.value.slice(0, header.length), header) - }) + await runSeq(["test-task:echo abc", "--silent", "--print-name"], stdout) + const header = createHeader("test-task:echo abc", packageInfo, false) + assert.equal(stdout.value.slice(0, header.length), header) }) - it("run-p command (--print-name)", () => { + it("run-p command (--print-name)", async () => { const stdout = new BufferStream() - return runPar(["test-task:echo abc", "--silent", "--print-name"], stdout) - .then(() => { - const header = createHeader("test-task:echo abc", packageInfo, false) - assert.equal(stdout.value.slice(0, header.length), header) - }) + await runPar(["test-task:echo abc", "--silent", "--print-name"], stdout) + const header = createHeader("test-task:echo abc", packageInfo, false) + assert.equal(stdout.value.slice(0, header.length), header) }) - it("npm-run-all command (-n)", () => { + it("npm-run-all command (-n)", async () => { const stdout = new BufferStream() - return runAll(["test-task:echo abc", "--silent", "-n"], stdout) - .then(() => { - const header = createHeader("test-task:echo abc", packageInfo, false) - assert.equal(stdout.value.slice(0, header.length), header) - }) + await runAll(["test-task:echo abc", "--silent", "-n"], stdout) + const header = createHeader("test-task:echo abc", packageInfo, false) + assert.equal(stdout.value.slice(0, header.length), header) }) - it("run-s command (-n)", () => { + it("run-s command (-n)", async () => { const stdout = new BufferStream() - return runSeq(["test-task:echo abc", "--silent", "-n"], stdout) - .then(() => { - const header = createHeader("test-task:echo abc", packageInfo, false) - assert.equal(stdout.value.slice(0, header.length), header) - }) + await runSeq(["test-task:echo abc", "--silent", "-n"], stdout) + const header = createHeader("test-task:echo abc", packageInfo, false) + assert.equal(stdout.value.slice(0, header.length), header) }) - it("run-p command (-n)", () => { + it("run-p command (-n)", async () => { const stdout = new BufferStream() - return runPar(["test-task:echo abc", "--silent", "-n"], stdout) - .then(() => { - const header = createHeader("test-task:echo abc", packageInfo, false) - assert.equal(stdout.value.slice(0, header.length), header) - }) + await runPar(["test-task:echo abc", "--silent", "-n"], stdout) + const header = createHeader("test-task:echo abc", packageInfo, false) + assert.equal(stdout.value.slice(0, header.length), header) }) }) }) diff --git a/test/sequential.js b/test/sequential.js index 083f6d5..e6f6572 100644 --- a/test/sequential.js +++ b/test/sequential.js @@ -30,204 +30,175 @@ describe("[sequencial] npm-run-all", () => { beforeEach(() => delay(1000).then(removeResult)) describe("should run tasks sequentially:", () => { - it("Node API", () => - nodeApi(["test-task:append a", "test-task:append b"], {parallel: false}) - .then(results => { - 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", () => - runAll(["test-task:append a", "test-task:append b"]) - .then(() => { - assert(result() === "aabb") - }) - ) - - it("run-s command", () => - runSeq(["test-task:append a", "test-task:append b"]) - .then(() => { - assert(result() === "aabb") - }) - ) + 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", () => - nodeApi(["test-task:append2 a", "test-task:error", "test-task:append2 b"]) - .then( - () => { - assert(false, "should fail") - }, - (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") - }) - ) - - it("npm-run-all command", () => - runAll(["test-task:append2 a", "test-task:error", "test-task:append2 b"]) - .then( - () => { - assert(false, "should fail") - }, - () => { - assert(result() === "aa") - } - ) - ) - - it("run-s command", () => - runSeq(["test-task:append2 a", "test-task:error", "test-task:append2 b"]) - .then( - () => { - assert(false, "should fail") - }, - () => { - assert(result() === "aa") - } - ) - ) + 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", () => - nodeApi(["test-task:*:a", "*:append:a"], {parallel: false}) - .then(() => { - assert(result() === "aa") - }) - ) - - it("npm-run-all command", () => - runAll(["test-task:*:a", "*:append:a"]) - .then(() => { - assert(result() === "aa") - }) - ) - - it("run-s command", () => - runSeq(["test-task:*:a", "*:append:a"]) - .then(() => { - assert(result() === "aa") - }) - ) + 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", () => - nodeApi(["test-task:*:a", "test-task:*:a"], {parallel: false}) - .then(() => { - assert(result() === "aaaa") - }) - ) - - it("npm-run-all command", () => - runAll(["test-task:*:a", "test-task:*:a"]) - .then(() => { - assert(result() === "aaaa") - }) - ) - - it("run-s command", () => - runSeq(["test-task:*:a", "test-task:*:a"]) - .then(() => { - assert(result() === "aaaa") - }) - ) + 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", () => - spawnWithKill( + it("npm-run-all command", async () => { + await spawnWithKill( "node", ["../bin/npm-run-all.js", "test-task:append2 a"] ) - .then(() => { - assert(result() == null || result() === "a") - }) - ) + assert(result() == null || result() === "a") + }) - it("run-s command", () => - spawnWithKill( + it("run-s command", async () => { + await spawnWithKill( "node", ["../bin/run-s/index.js", "test-task:append2 a"] ) - .then(() => { - assert(result() == null || result() === "a") - }) - ) + assert(result() == null || result() === "a") + }) }) describe("should continue on error when --continue-on-error option was specified:", () => { - it("Node API", () => - nodeApi(["test-task:append a", "test-task:error", "test-task:append b"], {continueOnError: true}) - .then( - () => { - assert(false, "should fail.") - }, - () => { - assert(result() === "aabb") - } - ) - ) - - it("npm-run-all command (--continue-on-error)", () => - runAll(["--continue-on-error", "test-task:append a", "test-task:error", "test-task:append b"]) - .then( - () => { - assert(false, "should fail.") - }, - () => { - assert(result() === "aabb") - } - ) - ) - - it("run-s command (--continue-on-error)", () => - runSeq(["--continue-on-error", "test-task:append a", "test-task:error", "test-task:append b"]) - .then( - () => { - assert(false, "should fail.") - }, - () => { - assert(result() === "aabb") - } - ) - ) - - it("npm-run-all command (-c)", () => - runAll(["-c", "test-task:append a", "test-task:error", "test-task:append b"]) - .then( - () => { - assert(false, "should fail.") - }, - () => { - assert(result() === "aabb") - } - ) - ) - - it("run-s command (-c)", () => - runSeq(["-c", "test-task:append a", "test-task:error", "test-task:append b"]) - .then( - () => { - assert(false, "should fail.") - }, - () => { - assert(result() === "aabb") - } - ) - ) + 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") + }) }) })