-
-
Notifications
You must be signed in to change notification settings - Fork 205
Expand file tree
/
Copy pathcommand-registration.ts
More file actions
83 lines (63 loc) · 2.28 KB
/
Copy pathcommand-registration.ts
File metadata and controls
83 lines (63 loc) · 2.28 KB
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
import { assert } from "chai";
import { Yok } from "../lib/common/yok";
const noopCommandFactory = () => ({
execute: async (): Promise<void> => undefined,
});
describe("yok: command registration", () => {
let injector: Yok;
beforeEach(() => {
injector = new Yok();
});
describe("registerCommand with a hierarchical name", () => {
it("records the subcommand under its parent", () => {
injector.registerCommand("dev|test", noopCommandFactory);
assert.deepStrictEqual(injector.getChildrenCommandsNames("dev"), [
"test",
]);
});
it("routes arguments through the parent name", () => {
injector.registerCommand("dev|test", noopCommandFactory);
const built = injector.buildHierarchicalCommand("dev", ["test", "extra"]);
assert.deepStrictEqual(built, {
commandName: "dev|test",
remainingArguments: ["extra"],
});
});
it("synthesizes a dispatcher for the parent", () => {
injector.registerCommand("dev|test", noopCommandFactory);
const parent = injector.resolveCommand("dev");
assert.isTrue((<any>parent).isHierarchicalCommand);
});
it("records each sibling once, including default commands", () => {
injector.registerCommand("dev|*test", noopCommandFactory);
injector.registerCommand("dev|lint", noopCommandFactory);
assert.deepStrictEqual(injector.getChildrenCommandsNames("dev"), [
"*test",
"lint",
]);
});
it("does not duplicate a subcommand already recorded by requireCommand", () => {
injector.requireCommand("dev|test", "some-file");
injector.registerCommand("dev|test", noopCommandFactory);
assert.deepStrictEqual(injector.getChildrenCommandsNames("dev"), [
"test",
]);
});
});
describe("register with a zero-parameter arrow factory", () => {
it("resolves by calling the factory, without annotate()", () => {
const factory = () => ({ value: 42 });
injector.register("arrowFactoryService", factory);
const instance = injector.resolve("arrowFactoryService");
assert.strictEqual(instance.value, 42);
assert.isUndefined((<any>factory).$inject);
});
it("stays shared by default", () => {
injector.register("sharedArrowFactoryService", () => ({}));
assert.strictEqual(
injector.resolve("sharedArrowFactoryService"),
injector.resolve("sharedArrowFactoryService"),
);
});
});
});