-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathplugin-create.ts
116 lines (97 loc) · 3.6 KB
/
plugin-create.ts
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import { Yok } from "../lib/common/yok";
import * as stubs from "./stubs";
import { CreatePluginCommand } from "../lib/commands/plugin/create-plugin";
import { assert } from "chai";
import helpers = require("../lib/common/helpers");
const originalIsInteractive = helpers.isInteractive;
const dummyArgs = ["dummyProjectName"];
const dummyUser = "devUsername";
const dummyName = "devPlugin";
function createTestInjector() {
const testInjector = new Yok();
testInjector.register("injector", testInjector);
testInjector.register("errors", stubs.ErrorsStub);
testInjector.register("logger", stubs.LoggerStub);
testInjector.register("childProcess", stubs.ChildProcessStub);
testInjector.register("prompter", new stubs.PrompterStub());
testInjector.register("fs", stubs.FileSystemStub);
testInjector.register("npm", stubs.NpmInstallationManagerStub);
testInjector.register("options", {
username: undefined,
pluginName: undefined
});
testInjector.register("terminalSpinnerService", {
createSpinner: () => ({
start: (): void => undefined,
stop: (): void => undefined,
message: (): void => undefined
})
});
testInjector.register("pacoteService", {
manifest: () => Promise.resolve(),
extractPackage: () => Promise.resolve()
});
testInjector.register("createCommand", CreatePluginCommand);
return testInjector;
}
describe("Plugin create command tests", () => {
let testInjector: IInjector;
let options: IOptions;
let createPluginCommand: CreatePluginCommand;
beforeEach(() => {
helpers.isInteractive = () => true;
testInjector = createTestInjector();
options = testInjector.resolve("$options");
createPluginCommand = testInjector.resolve("$createCommand");
});
afterEach(() => {
helpers.isInteractive = originalIsInteractive;
});
describe("#CreatePluginCommand", () => {
it("should fail when project name is not set.", async () => {
assert.isRejected(createPluginCommand.canExecute([]));
});
it("should pass when only project name is set in non-interactive shell.", async () => {
helpers.isInteractive = () => false;
await createPluginCommand.execute(dummyArgs);
});
it("should pass when only project name is set with prompts in interactive shell.", async () => {
const prompter = testInjector.resolve("$prompter");
const strings: IDictionary<string> = {};
strings[createPluginCommand.userMessage] = dummyUser;
strings[createPluginCommand.nameMessage] = dummyName;
prompter.expect({
strings: strings
});
await createPluginCommand.execute(dummyArgs);
prompter.assert();
});
it("should pass with project name and username set with one prompt in interactive shell.", async () => {
options.username = dummyUser;
const prompter = testInjector.resolve("$prompter");
const strings: IDictionary<string> = {};
strings[createPluginCommand.nameMessage] = dummyName;
prompter.expect({
strings: strings
});
await createPluginCommand.execute(dummyArgs);
prompter.assert();
});
it("should pass with project name and pluginName set with one prompt in interactive shell.", async () => {
options.pluginName = dummyName;
const prompter = testInjector.resolve("$prompter");
const strings: IDictionary<string> = {};
strings[createPluginCommand.userMessage] = dummyUser;
prompter.expect({
strings: strings
});
await createPluginCommand.execute(dummyArgs);
prompter.assert();
});
it("should pass with project name, username and pluginName set with no prompt in interactive shell.", async () => {
options.username = dummyUser;
options.pluginName = dummyName;
await createPluginCommand.execute(dummyArgs);
});
});
});