-
Notifications
You must be signed in to change notification settings - Fork 684
Expand file tree
/
Copy pathcli-process.test.ts
More file actions
201 lines (195 loc) · 8.47 KB
/
Copy pathcli-process.test.ts
File metadata and controls
201 lines (195 loc) · 8.47 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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
import assert from 'node:assert/strict';
import { afterEach, beforeEach, describe, it } from 'node:test';
import sinon from 'sinon';
import { SlackCLIProcess } from './cli-process';
import { shell } from './shell';
describe('SlackCLIProcess class', () => {
const sandbox = sinon.createSandbox();
let spawnProcessSpy: sinon.SinonStub;
beforeEach(() => {
spawnProcessSpy = sandbox.stub(shell, 'spawnProcess');
sandbox.stub(shell, 'checkIfFinished');
});
afterEach(() => {
sandbox.restore();
});
describe('constructor', () => {
it('should throw if `SLACK_CLI_PATH` env variable is falsy', () => {
const orig = process.env.SLACK_CLI_PATH;
process.env.SLACK_CLI_PATH = '';
assert.throws(() => {
new SlackCLIProcess(['help']);
});
process.env.SLACK_CLI_PATH = orig;
});
});
describe('CLI flag handling', () => {
describe('global options', () => {
it('should map dev option to --slackdev', async () => {
let cmd = new SlackCLIProcess(['help'], { dev: true });
await cmd.execAsync();
sandbox.assert.calledWith(spawnProcessSpy, sinon.match.string, sinon.match.array.contains(['--slackdev']));
spawnProcessSpy.resetHistory();
cmd = new SlackCLIProcess(['help']);
await cmd.execAsync();
sandbox.assert.neverCalledWith(spawnProcessSpy, sinon.match.string, sinon.match.array.contains(['--slackdev']));
spawnProcessSpy.resetHistory();
});
it('should map qa option to QA host', async () => {
let cmd = new SlackCLIProcess(['help'], { qa: true });
await cmd.execAsync();
sandbox.assert.calledWith(
spawnProcessSpy,
sinon.match.string,
sinon.match.array.contains(['--apihost', 'qa.slack.com']),
);
spawnProcessSpy.resetHistory();
cmd = new SlackCLIProcess(['help']);
await cmd.execAsync();
sandbox.assert.neverCalledWith(
spawnProcessSpy,
sinon.match.string,
sinon.match.array.contains(['--apihost', 'qa.slack.com']),
);
spawnProcessSpy.resetHistory();
});
it('should map apihost option to provided host', async () => {
let cmd = new SlackCLIProcess(['help'], { apihost: 'dev123.slack.com' });
await cmd.execAsync();
sandbox.assert.calledWith(
spawnProcessSpy,
sinon.match.string,
sinon.match.array.contains(['--apihost', 'dev123.slack.com']),
);
spawnProcessSpy.resetHistory();
cmd = new SlackCLIProcess(['help']);
await cmd.execAsync();
sandbox.assert.neverCalledWith(
spawnProcessSpy,
sinon.match.string,
sinon.match.array.contains(['--apihost', 'dev123.slack.com']),
);
spawnProcessSpy.resetHistory();
});
it('should default to passing --skip-update but allow overriding that', async () => {
let cmd = new SlackCLIProcess(['help']);
await cmd.execAsync();
sandbox.assert.calledWith(spawnProcessSpy, sinon.match.string, sinon.match.array.contains(['--skip-update']));
spawnProcessSpy.resetHistory();
cmd = new SlackCLIProcess(['help'], { skipUpdate: false });
await cmd.execAsync();
sandbox.assert.neverCalledWith(
spawnProcessSpy,
sinon.match.string,
sinon.match.array.contains(['--skip-update']),
);
spawnProcessSpy.resetHistory();
cmd = new SlackCLIProcess(['help'], { skipUpdate: true });
await cmd.execAsync();
sandbox.assert.calledWith(spawnProcessSpy, sinon.match.string, sinon.match.array.contains(['--skip-update']));
spawnProcessSpy.resetHistory();
cmd = new SlackCLIProcess(['help'], {}); // empty global options; so undefined skipUpdate option
await cmd.execAsync();
sandbox.assert.calledWith(spawnProcessSpy, sinon.match.string, sinon.match.array.contains(['--skip-update']));
});
it('should only pass `--app` when explicitly provided via the `app` parameter', async () => {
let cmd = new SlackCLIProcess(['help']);
await cmd.execAsync();
sandbox.assert.neverCalledWith(spawnProcessSpy, sinon.match.string, sinon.match.array.contains(['--app']));
spawnProcessSpy.resetHistory();
cmd = new SlackCLIProcess(['help'], { app: 'local' });
await cmd.execAsync();
sandbox.assert.calledWith(spawnProcessSpy, sinon.match.string, sinon.match.array.contains(['--app', 'local']));
spawnProcessSpy.resetHistory();
cmd = new SlackCLIProcess(['help'], { app: 'deployed' });
await cmd.execAsync();
sandbox.assert.calledWith(
spawnProcessSpy,
sinon.match.string,
sinon.match.array.contains(['--app', 'deployed']),
);
});
it('should default to `--force` but allow overriding that via the `force` parameter', async () => {
let cmd = new SlackCLIProcess(['help']);
await cmd.execAsync();
sandbox.assert.calledWith(spawnProcessSpy, sinon.match.string, sinon.match.array.contains(['--force']));
spawnProcessSpy.resetHistory();
cmd = new SlackCLIProcess(['help'], { force: true });
await cmd.execAsync();
sandbox.assert.calledWithMatch(spawnProcessSpy, sinon.match.string, sinon.match.array.contains(['--force']));
spawnProcessSpy.resetHistory();
cmd = new SlackCLIProcess(['help'], { force: false });
await cmd.execAsync();
sandbox.assert.neverCalledWith(spawnProcessSpy, sinon.match.string, sinon.match.array.contains(['--force']));
});
it('should map token option to `--token`', async () => {
let cmd = new SlackCLIProcess(['help'], { token: 'xoxb-1234' });
await cmd.execAsync();
sandbox.assert.calledWith(
spawnProcessSpy,
sinon.match.string,
sinon.match.array.contains(['--token', 'xoxb-1234']),
);
spawnProcessSpy.resetHistory();
cmd = new SlackCLIProcess(['help']);
await cmd.execAsync();
sandbox.assert.neverCalledWith(
spawnProcessSpy,
sinon.match.string,
sinon.match.array.contains(['--token', 'xoxb-1234']),
);
spawnProcessSpy.resetHistory();
});
it('should map verbose option to `--verbose`', async () => {
let cmd = new SlackCLIProcess(['help'], { verbose: true });
await cmd.execAsync();
sandbox.assert.calledWith(spawnProcessSpy, sinon.match.string, sinon.match.array.contains(['--verbose']));
spawnProcessSpy.resetHistory();
cmd = new SlackCLIProcess(['help']);
await cmd.execAsync();
sandbox.assert.neverCalledWith(spawnProcessSpy, sinon.match.string, sinon.match.array.contains(['--verbose']));
});
});
describe('command options', () => {
it('should pass command-level key/value options to command in the form `--<key> value`', async () => {
const cmd = new SlackCLIProcess(['help'], {}, { '--awesome': 'yes' });
await cmd.execAsync();
sandbox.assert.calledWith(
spawnProcessSpy,
sinon.match.string,
sinon.match.array.contains(['--awesome', 'yes']),
);
});
it('should only pass command-level key option if value is true in the form `--key`', async () => {
const cmd = new SlackCLIProcess(['help'], {}, { '--no-prompt': true });
await cmd.execAsync();
sandbox.assert.calledWith(spawnProcessSpy, sinon.match.string, sinon.match.array.contains(['--no-prompt']));
});
it('should not pass command-level key option if value is falsy', async () => {
let cmd = new SlackCLIProcess(['help'], {}, { '--no-prompt': false });
await cmd.execAsync();
sandbox.assert.neverCalledWith(
spawnProcessSpy,
sinon.match.string,
sinon.match.array.contains(['--no-prompt']),
);
spawnProcessSpy.resetHistory();
cmd = new SlackCLIProcess(['help'], {}, { '--no-prompt': '' });
await cmd.execAsync();
sandbox.assert.neverCalledWith(
spawnProcessSpy,
sinon.match.string,
sinon.match.array.contains(['--no-prompt']),
);
spawnProcessSpy.resetHistory();
cmd = new SlackCLIProcess(['help'], {}, { '--no-prompt': undefined });
await cmd.execAsync();
sandbox.assert.neverCalledWith(
spawnProcessSpy,
sinon.match.string,
sinon.match.array.contains(['--no-prompt']),
);
});
});
});
});