-
-
Notifications
You must be signed in to change notification settings - Fork 241
/
fail.js
65 lines (52 loc) · 2.21 KB
/
fail.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
import assert from "power-assert";
import {removeResult} from "./lib/util";
// Test targets.
import runAll from "../src/lib/npm-run-all";
import command from "../src/bin/npm-run-all";
/**
* Throws an assertion error if a given promise comes to be fulfilled.
*
* @param {Promise} p - A promise to check.
* @returns {Promise} A promise which is checked.
*/
function shouldFail(p) {
return p.then(
() => assert(false, "should fail"),
() => null // OK!
);
}
describe("[fail] npm-run-all should fail", () => {
before(() => { process.chdir("test-workspace"); });
after(() => { process.chdir(".."); });
beforeEach(removeResult);
it("if an invalid option exists.", () =>
shouldFail(command(["--invalid"]))
);
it("if invalid `options.taskList` is given.", () =>
shouldFail(runAll("test-task:append a", {taskList: {invalid: 0}}))
);
describe("if unknown tasks are given:", () => {
it("lib version", () => shouldFail(runAll("unknown-task")));
it("command version", () => shouldFail(command(["unknown-task"])));
});
describe("if unknown tasks are given (2):", () => {
it("lib version", () => shouldFail(runAll(["test-task:append:a", "unknown-task"])));
it("command version", () => shouldFail(command(["test-task:append:a", "unknown-task"])));
});
describe("if package.json is not found:", () => {
before(() => { process.chdir("no-package-json"); });
after(() => { process.chdir(".."); });
it("lib version", () => shouldFail(runAll(["test-task:append:a"])));
it("command version", () => shouldFail(command(["test-task:append:a"])));
});
describe("if package.json does not have scripts field:", () => {
before(() => { process.chdir("no-scripts"); });
after(() => { process.chdir(".."); });
it("lib version", () => shouldFail(runAll(["test-task:append:a"])));
it("command version", () => shouldFail(command(["test-task:append:a"])));
});
describe("if tasks exited with non-zero code:", () => {
it("lib version", () => shouldFail(runAll("test-task:error")));
it("command version", () => shouldFail(command(["test-task:error"])));
});
});