UNPKG

10.1 kBJavaScriptView Raw
1/**
2 * Tests windowslib's emulator module.
3 *
4 * @copyright
5 * Copyright (c) 2014-2017 by Appcelerator, Inc. All Rights Reserved.
6 *
7 * @license
8 * Licensed under the terms of the Apache Public License.
9 * Please see the LICENSE included with this distribution for details.
10 */
11
12const
13 async = require('async'),
14 fs = require('fs'),
15 path = require('path'),
16 windowslib = require('..'),
17 WIN_10 = '10.0',
18 WIN_8_1 = '8.1',
19 WIN_8 = '8.0',
20 PROJECTS = {
21 '8.0': path.join(__dirname, 'TestApp', 'TestApp.csproj'),
22 '8.1': path.join(__dirname, 'TestApp', 'TestApp.csproj'), // FIXME Create an 8.1 project?
23 '10.0': path.join(__dirname, 'TestApp10.0', 'TestApp10.0.vcxproj')
24 },
25 APPS = {
26 '8.0': path.join(__dirname, 'TestApp', 'Bin', 'Debug', 'TestApp_Debug_AnyCPU.xap'),
27 '8.1': path.join(__dirname, 'TestApp', 'Bin', 'Debug', 'TestApp_Debug_AnyCPU.xap'), // FIXME Create an 8.1 project?
28 '10.0': path.join(__dirname, 'TestApp10.0', 'AppPackages', 'TestApp10.0', 'TestApp10.0_1.0.0.0_Win32_Debug_Test', 'TestApp10.0_1.0.0.0_Win32_Debug.appx')
29 };
30
31describe('emulator', function () {
32 it('namespace should be an object', function () {
33 should(windowslib.emulator).be.an.Object;
34 });
35
36 (process.platform === 'win32' ? it : it.skip)('detect Windows Phone emulators', function (done) {
37 this.timeout(8000);
38 this.slow(4000);
39
40 windowslib.emulator.detect(function (err, results) {
41 if (err) {
42 return done(err);
43 }
44
45 should(results).be.an.Object;
46 should(results).have.keys('emulators', 'issues');
47
48 should(results.emulators).be.an.Object;
49 Object.keys(results.emulators).forEach(function (ver) {
50 should(results.emulators[ver]).be.an.Array;
51 results.emulators[ver].forEach(function (emu) {
52 should(emu).be.an.Object;
53 should(emu).have.ownProperty('name');
54 should(emu).have.ownProperty('udid');
55 should(emu).have.ownProperty('index');
56 should(emu).have.ownProperty('wpsdk');
57 should(emu).have.ownProperty('type');
58
59 should(emu.name).be.a.String;
60 should(emu.name).not.equal('');
61
62 should(emu.index).be.an.Integer;
63
64 should(emu.wpsdk).be.a.String;
65 should(emu.wpsdk).not.equal('');
66
67 should(emu.type).be.a.String;
68 should(emu.type).equal('emulator');
69 });
70 });
71
72 should(results.issues).be.an.Array;
73 results.issues.forEach(function (issue) {
74 should(issue).be.an.Object;
75 should(issue).have.keys('id', 'type', 'message');
76 should(issue.id).be.a.String;
77 should(issue.type).be.a.String;
78 should(issue.type).match(/^info|warning|error$/);
79 should(issue.message).be.a.String;
80 });
81
82 done();
83 });
84 });
85
86 (process.platform === 'win32' ? it : it.skip)('detect if emulator is running', function (done) {
87 this.timeout(5000);
88 this.slow(4000);
89
90 windowslib.emulator.detect(function (err, results) {
91 if (err) {
92 return done(err);
93 }
94
95 var emu, wpsdk;
96 for (wpsdk in results.emulators) {
97 if (results.emulators[wpsdk].length > 0) {
98 emu = results.emulators[wpsdk][0];
99 break;
100 }
101 }
102
103 should(emu).be.an.Object;
104
105 windowslib.emulator.isRunning(emu.udid, function (err, running) {
106 if (!err && running) {
107 err = new Error('Expected the emulator to not be running');
108 }
109 done(err);
110 });
111 });
112 });
113
114 // (process.platform === 'win32' ? it : it.skip)('should shutdown specified emulator', function (done) {
115 // this.timeout(5000);
116 // this.slow(4000);
117 //
118 // windowslib.emulator.stop({
119 // name: 'Some emulator that does not exist'
120 // }, done);
121 // });
122});
123
124[WIN_8, WIN_8_1, WIN_10].forEach(function (wpsdk) {
125 // suite
126 (process.platform === 'win32' ? describe : describe.skip)(wpsdk + ' emulator launching', function () {
127 var emu;
128
129 // Grab the emulator
130 before(function (done) {
131 this.timeout(8000);
132 this.slow(4000);
133
134 windowslib.emulator.detect(function (err, results) {
135 if (err) {
136 console.error(err);
137 return done(err);
138 }
139
140 if (results.emulators[wpsdk].length > 0) {
141 emu = results.emulators[wpsdk][0];
142 }
143 done();
144 });
145 });
146
147 // Shut down the emulator
148 after(function (done) {
149 this.timeout(8000);
150 this.slow(4000);
151
152 if (!emu) {
153 return done();
154 }
155
156 windowslib.emulator.stop(emu, done);
157 });
158
159 it('launch and shutdown emulator', function (done) {
160 this.timeout(120000);
161 this.slow(110000);
162
163 if (!emu) {
164 this.skip();
165 return done();
166 }
167
168 windowslib.emulator.isRunning(emu.udid, function (err, running) {
169 if (err) {
170 return done(err);
171 }
172
173 windowslib.emulator.launch(emu.udid, { killIfRunning: true }, function (err, emuHandle) {
174 if (err) {
175 return done(err);
176 }
177
178 windowslib.emulator.isRunning(emuHandle.udid, function (err, running) {
179 if (err) {
180 return done(err);
181 }
182
183 if (!running) {
184 return done(new Error('Expected the emulator to be running'));
185 }
186
187 windowslib.emulator.stop(emuHandle, done);
188 });
189 });
190 });
191 });
192
193 // FIXME: I believe windowslib.emulator.install will fail for Windows 10 emulators.
194 // Specifically, I think that we return from wptool.connect too fast.
195 // We launch the emulator, but don't wait for it to be fully up before attempting to install the app.
196 // We should likely add some check that after we do wptool.connect we wait for the status to change to 'Running' from 'Starting'
197 // Add a specific test for this?
198 it('launch emulator and install app via #install (from shut down emulator), then shutdown emulator', function (done) {
199 this.timeout(240000);
200 this.slow(110000);
201
202 if (!emu) {
203 this.skip();
204 return done();
205 }
206
207 var xapFile = APPS[wpsdk],
208 emuHandle;
209
210 async.series([
211 function (next) {
212 windowslib.visualstudio.build({
213 buildConfiguration: 'Debug',
214 project: PROJECTS[wpsdk]
215 }, function (err, result) {
216 // If we fail to build the project, try and spit out full output
217 if (err && err.extendedError) {
218 console.error(err.extendedError.err);
219 console.info(err.extendedError.out);
220 }
221 next(err);
222 });
223 },
224
225 function (next) {
226 should(fs.existsSync(xapFile)).be.ok;
227 next();
228 },
229
230 function (next) {
231 windowslib.emulator.install(emu.udid, xapFile, { killIfRunning: true, wpsdk: wpsdk }, function (err, _emuHandle) {
232 emuHandle = _emuHandle;
233 next(err);
234 });
235 },
236
237 function (next) {
238 windowslib.emulator.isRunning(emuHandle.udid, function (err, running) {
239 if (err) {
240 next(err);
241 } else if (!running) {
242 next(new Error('Expected the emulator to be running'));
243 } else {
244 next();
245 }
246 });
247 },
248
249 function (next) {
250 windowslib.emulator.stop(emuHandle, next);
251 }
252 ], done);
253 });
254
255 it('launch emulator, then install and launch app via #install, then shutdown emulator', function (done) {
256 this.timeout(180000);
257 this.slow(110000);
258
259 if (!emu) {
260 this.skip();
261 return done();
262 }
263
264 var xapFile = APPS[wpsdk],
265 emuHandle;
266
267 async.series([
268 function (next) {
269 windowslib.visualstudio.build({
270 buildConfiguration: 'Debug',
271 project: PROJECTS[wpsdk]
272 }, function (err, result) {
273 // If we fail to build the project, try and spit out full output
274 if (err && err.extendedError) {
275 console.error(err.extendedError.err);
276 console.info(err.extendedError.out);
277 }
278 next(err);
279 });
280 },
281
282 function (next) {
283 should(fs.existsSync(xapFile)).be.ok;
284 next();
285 },
286
287 function (next) {
288 windowslib.emulator.launch(null, { killIfRunning: true, wpsdk: wpsdk }, function (err, _emuHandle) {
289 emuHandle = _emuHandle;
290 next(err);
291 });
292 },
293
294 function (next) {
295 windowslib.emulator.isRunning(emuHandle.udid, function (err, running) {
296 if (err) {
297 next(err);
298 } else if (!running) {
299 next(new Error('Expected the emulator to be running'));
300 } else {
301 next();
302 }
303 });
304 },
305
306 function (next) {
307 windowslib.emulator.install(emuHandle.udid, xapFile, { killIfRunning: false, wpsdk: wpsdk }, function (err, _emuHandle) {
308 emuHandle = _emuHandle;
309 next(err);
310 });
311 },
312
313 function (next) {
314 windowslib.emulator.isRunning(emuHandle.udid, function (err, running) {
315 if (err) {
316 next(err);
317 } else if (!running) {
318 next(new Error('Expected the emulator to be running'));
319 } else {
320 next();
321 }
322 });
323 },
324
325 function (next) {
326 windowslib.emulator.stop(emuHandle, next);
327 }
328 ], done);
329 });
330
331 it('launch emulator, then install and launch app via #launch, then shutdown emulator', function (done) {
332 this.timeout(180000);
333 this.slow(110000);
334
335 if (!emu) {
336 this.skip();
337 return done();
338 }
339
340 var xapFile = APPS[wpsdk],
341 emuHandle;
342
343 async.series([
344 function (next) {
345 windowslib.visualstudio.build({
346 buildConfiguration: 'Debug',
347 project: PROJECTS[wpsdk]
348 }, next);
349 },
350
351 function (next) {
352 should(fs.existsSync(xapFile)).be.ok;
353 next();
354 },
355
356 function (next) {
357 windowslib.emulator.launch(null, { killIfRunning: true, wpsdk: wpsdk }, function (err, _emuHandle) {
358 emuHandle = _emuHandle;
359 next(err);
360 });
361 },
362
363 function (next) {
364 windowslib.emulator.isRunning(emuHandle.udid, function (err, running) {
365 if (err) {
366 next(err);
367 } else if (!running) {
368 next(new Error('Expected the emulator to be running'));
369 } else {
370 next();
371 }
372 });
373 },
374
375 function (next) {
376 windowslib.emulator.launch(emuHandle.udid, { appPath: xapFile, killIfRunning: false, wpsdk: wpsdk }, function (err, _emuHandle) {
377 next(err);
378 });
379 },
380
381 function (next) {
382 windowslib.emulator.isRunning(emuHandle.udid, function (err, running) {
383 if (err) {
384 next(err);
385 } else if (!running) {
386 next(new Error('Expected the emulator to be running'));
387 } else {
388 next();
389 }
390 });
391 },
392
393 function (next) {
394 windowslib.emulator.stop(emuHandle, next);
395 }
396 ], done);
397 });
398 }); // end suite
399}); // forEach