forked from ionic-team/ionic-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.spec.js
310 lines (238 loc) · 10.6 KB
/
cli.spec.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
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
var IonicAppLib = require('ionic-app-lib'),
Ionitron = require('../lib/ionic/ionitron'),
IonicCli = require('../lib/cli'),
Q = require('q'),
Task = require('../lib/ionic/task').Task,
Info = IonicAppLib.info,
Utils = IonicAppLib.utils;
describe('Cli', function() {
beforeEach(function() {
spyOn(IonicCli, 'processExit');
spyOn(IonicCli, 'printAvailableTasks');
spyOn(IonicAppLib.events, 'on');
spyOn(process, 'on');
spyOn(Info, 'checkRuntime');
spyOn(Utils, 'fail').andCallFake(function(err){
console.log(err);
console.log(err.stack);
throw err;
});
});
it('should have cli defined', function() {
expect(IonicCli).toBeDefined();
});
it('should have cli tasks defined', function() {
expect(IonicCli.Tasks).toBeDefined();
});
describe('#run', function() {
beforeEach(function() {
var fakeTask = function() {};
fakeTask.prototype = new Task();
fakeTask.prototype.run = function() {};
spyOn(IonicCli, 'lookupTask').andReturn(fakeTask);
});
describe('#Cli methods', function() {
it('should run checkLatestVersion on run', function() {
var deferred = Q.defer();
deferred.resolve();
spyOn(IonicCli, 'checkLatestVersion').andReturn(deferred);
IonicCli.run(['node', 'bin/ionic', 'run', 'ios']);
expect(IonicCli.checkLatestVersion).toHaveBeenCalled();
});
it('should run info checkruntime on run', function() {
spyOn(IonicCli, 'printHelpLines');
IonicCli.run(['node', 'bin/ionic', '--h']);
expect(Info.checkRuntime).toHaveBeenCalled();
});
it('should run ionitron when argument is passed', function() {
spyOn(Ionitron, 'print');
IonicCli.run(['node', 'bin/ionic', '--ionitron']);
expect(Ionitron.print).toHaveBeenCalled();
});
it('should listen to verbosity when arg is passed', function() {
spyOn(IonicCli, 'tryBuildingTask').andReturn(false);
IonicCli.run(['node', 'bin/ionic', '--verbose']);
expect(IonicAppLib.events.on).toHaveBeenCalledWith('verbose', console.log);
});
it('should get version when version flag passed', function() {
spyOn(IonicCli, 'version');
IonicCli.run(['node', 'bin/ionic', '--version']);
expect(IonicCli.version).toHaveBeenCalled();
});
it('should call help when help argument passed', function() {
spyOn(IonicCli, 'printHelpLines');
IonicCli.run(['node', 'bin/ionic', '--help']);
expect(IonicCli.printHelpLines).toHaveBeenCalled();
});
it('should call help when help shorthand argument passed', function() {
spyOn(IonicCli, 'printHelpLines');
IonicCli.run(['node', 'bin/ionic', '--h']);
expect(IonicCli.printHelpLines).toHaveBeenCalled();
});
it('should print available tasks if no valid command is passed', function() {
spyOn(IonicCli, 'tryBuildingTask').andReturn(false);
IonicCli.run(['node', 'bin/ionic']);
expect(IonicCli.printAvailableTasks).toHaveBeenCalled();
});
it('should get the correct task by name', function() {
var task = IonicCli.getTaskWithName('start');
expect(task).toBeDefined();
expect(task.name).toBe('start');
expect(task.args).toBeDefined();
});
it('should call attachErrorHandling', function() {
spyOn(IonicCli, 'attachErrorHandling');
IonicCli.run(['node', 'bin/ionic']);
expect(IonicCli.attachErrorHandling).toHaveBeenCalled();
});
it('should set up console logging helpers', function() {
spyOn(IonicCli, 'setUpConsoleLoggingHelpers');
IonicCli.run(['node', 'bin/ionic']);
expect(IonicCli.setUpConsoleLoggingHelpers).toHaveBeenCalled();
});
it('should get boolean options from start task', function() {
var tasks = require('../lib/tasks/cliTasks');
var task = IonicCli.getTaskWithName('start');
var booleanOptions = IonicCli.getBooleanOptionsForTask(task);
//We expect 6 total = 3 options, each with short hand notation.
expect(booleanOptions.length).toBe(6);
});
});
});
describe('#commands options', function() {
var fakeTask;
beforeEach(function() {
fakeTask = function() {};
fakeTask.prototype = new Task();
fakeTask.prototype.run = function() {};
spyOn(IonicCli, 'lookupTask').andReturn(fakeTask);
spyOn(fakeTask.prototype, 'run').andCallThrough();
});
it('should parse start options correctly', function() {
var processArgs = [ 'node', '/usr/local/bin/ionic', 'start', 's1', '-w', '--appname', 'asdf'];
IonicCli.run(processArgs);
expect(fakeTask.prototype.run).toHaveBeenCalled();
var taskArgs = fakeTask.prototype.run.mostRecentCall.args;
var taskArgv = taskArgs[1];
expect(taskArgv._.length).toBe(2);
expect(taskArgv._[0]).toBe('start');
expect(taskArgv._[1]).toBe('s1');
expect(taskArgv.appname).toBe('asdf');
expect(taskArgv.s).toBe(false);
expect(taskArgv.sass).toBe(false);
expect(taskArgv.l).toBe(false);
expect(taskArgv.list).toBe(false);
expect(taskArgv['no-cordova']).toBe(false);
expect(taskArgv.w).toBe(true);
expect(taskArgv.id).toBeUndefined();
expect(taskArgv.i).toBeUndefined();
});
it('should parse serve options correctly', function() {
var processArgs = [ 'node', '/usr/local/bin/ionic', 'serve', '--nogulp', '--all', '--browser', 'firefox'];
IonicCli.run(processArgs);
expect(fakeTask.prototype.run).toHaveBeenCalled();
var taskArgs = fakeTask.prototype.run.mostRecentCall.args;
var taskArgv = taskArgs[1];
// console.log('taskArgv', taskArgv);
//should only have serve in the command args
expect(taskArgv._.length).toBe(1);
expect(taskArgv.browser).toBe('firefox');
expect(taskArgv.nogulp).toBe(true);
expect(taskArgv.all).toBe(true);
expect(taskArgv.lab).toBe(false);
expect(taskArgv.nobrowser).toBe(false);
});
it('should parse upload options correctly', function() {
var note = 'A note for notes';
var processArgs = [ 'node', '/usr/local/bin/ionic', 'upload', '--email', '[email protected]', '--password', 'pass', '--note', note];
IonicCli.run(processArgs);
expect(fakeTask.prototype.run).toHaveBeenCalled();
var taskArgs = fakeTask.prototype.run.mostRecentCall.args;
var taskArgv = taskArgs[1];
//should only have serve in the command args
expect(taskArgv._.length).toBe(1);
expect(taskArgv.note).toBe(note);
expect(taskArgv.email).toBe('[email protected]');
expect(taskArgv.password).toBe('pass');
});
it('should parse login options correctly', function() {
var processArgs = [ 'node', '/usr/local/bin/ionic', 'login', '--email', '[email protected]', '--password', 'pass'];
IonicCli.run(processArgs);
expect(fakeTask.prototype.run).toHaveBeenCalled();
var taskArgs = fakeTask.prototype.run.mostRecentCall.args;
var taskArgv = taskArgs[1];
//should only have serve in the command args
expect(taskArgv._.length).toBe(1);
expect(taskArgv.email).toBe('[email protected]');
expect(taskArgv.password).toBe('pass');
});
it('should parse run options correctly', function() {
var processArgs = [ 'node', '/usr/local/bin/ionic', 'run', 'ios', '--livereload', '--port', '5000', '-r', '35730', '--consolelogs', '--serverlogs', '--device'];
IonicCli.run(processArgs);
expect(fakeTask.prototype.run).toHaveBeenCalled();
var taskArgs = fakeTask.prototype.run.mostRecentCall.args;
var taskArgv = taskArgs[1];
//should only have serve in the command args
expect(taskArgv._.length).toBe(2);
expect(taskArgv.r).toBe(35730);
expect(taskArgv.port).toBe(5000);
expect(taskArgv.consolelogs).toBe(true);
expect(taskArgv.serverlogs).toBe(true);
expect(taskArgv.livereload).toBe(true);
expect(taskArgv.device).toBe(true);
});
it('should parse emulate options correctly', function() {
var processArgs = [ 'node', '/usr/local/bin/ionic', 'emulate', 'android', '--livereload', '--port', '5000', '-r', '35730', '--consolelogs', '--serverlogs'];
IonicCli.run(processArgs);
expect(fakeTask.prototype.run).toHaveBeenCalled();
var taskArgs = fakeTask.prototype.run.mostRecentCall.args;
var taskArgv = taskArgs[1];
//should only have serve in the command args
expect(taskArgv._.length).toBe(2);
expect(taskArgv._[1]).toBe('android');
expect(taskArgv.r).toBe(35730);
expect(taskArgv.port).toBe(5000);
expect(taskArgv.consolelogs).toBe(true);
expect(taskArgv.serverlogs).toBe(true);
expect(taskArgv.livereload).toBe(true);
});
it('should parse state options correctly', function() {
var processArgs = [ 'node', '/usr/local/bin/ionic', 'state', 'save', '--plugins'];
IonicCli.run(processArgs);
expect(fakeTask.prototype.run).toHaveBeenCalled();
var taskArgs = fakeTask.prototype.run.mostRecentCall.args;
var taskArgv = taskArgs[1];
//should only have serve in the command args
expect(taskArgv._.length).toBe(2);
expect(taskArgv._[1]).toBe('save');
expect(taskArgv.plugins).toBe(true);
expect(taskArgv.platforms).toBe(false);
});
it('should parse plugin options correctly', function() {
var processArgs = [ 'node', '/usr/local/bin/ionic', 'plugin', 'add', 'org.apache.cordova.splashscreen', '--nosave', '--searchpath', '../'];
IonicCli.run(processArgs);
expect(fakeTask.prototype.run).toHaveBeenCalled();
var taskArgs = fakeTask.prototype.run.mostRecentCall.args;
var taskArgv = taskArgs[1];
//should only have serve in the command args
expect(taskArgv._.length).toBe(3);
expect(taskArgv._[0]).toBe('plugin');
expect(taskArgv._[1]).toBe('add');
expect(taskArgv._[2]).toBe('org.apache.cordova.splashscreen');
expect(taskArgv.nosave).toBe(true);
expect(taskArgv.searchpath).toBe('../');
});
it('should parse build options correctly', function() {
var processArgs = [ 'node', '/usr/local/bin/ionic', 'build', 'ios', '--nohooks'];
IonicCli.run(processArgs);
expect(fakeTask.prototype.run).toHaveBeenCalled();
var taskArgs = fakeTask.prototype.run.mostRecentCall.args;
var taskArgv = taskArgs[1];
//should only have serve in the command args
expect(taskArgv._.length).toBe(2);
expect(taskArgv._[0]).toBe('build');
expect(taskArgv._[1]).toBe('ios');
expect(taskArgv.nohooks).toBe(true);
});
});
});