UNPKG

11.9 kBJavaScriptView Raw
1/**
2 Licensed to the Apache Software Foundation (ASF) under one
3 or more contributor license agreements. See the NOTICE file
4 distributed with this work for additional information
5 regarding copyright ownership. The ASF licenses this file
6 to you under the Apache License, Version 2.0 (the
7 "License"); you may not use this file except in compliance
8 with the License. You may obtain a copy of the License at
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12 Unless required by applicable law or agreed to in writing,
13 software distributed under the License is distributed on an
14 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 KIND, either express or implied. See the License for the
16 specific language governing permissions and limitations
17 under the License.
18*/
19
20var rewire = require('rewire');
21var deployment = rewire('../../template/cordova/lib/deployment');
22var Q = require('q');
23var path = require('path');
24var AppDeployCmdTool = deployment.__get__('AppDeployCmdTool');
25var WinAppDeployCmdTool = deployment.__get__('WinAppDeployCmdTool');
26
27var TEST_APP_PACKAGE_NAME = '"c:\\testapppackage.appx"';
28var TEST_APP_PACKAGE_ID = '12121212-3434-3434-3434-567856785678';
29
30describe('The correct version of the app deployment tool is obtained.', function () {
31
32 var mockedProgramFiles = process.env['ProgramFiles(x86)'];
33
34 beforeEach(function () {
35 process.env['ProgramFiles(x86)'] = path.join('c:/Program Files (x86)');
36 });
37
38 afterEach(function () {
39 if (mockedProgramFiles) {
40 process.env['ProgramFiles(x86)'] = mockedProgramFiles;
41 } else {
42 delete process.env['ProgramFiles(x86)'];
43 }
44 });
45
46 it('Test #000 : Provides an AppDeployCmdTool when 8.1 is requested.', function () {
47
48 var tool = deployment.getDeploymentTool('8.1');
49 expect(tool instanceof AppDeployCmdTool).toBe(true);
50
51 });
52
53 it('Test #001 : Provides a WinAppDeployCmdTool when 10.0 is requested.', function () {
54
55 var tool = deployment.getDeploymentTool('10.0');
56 expect(tool instanceof WinAppDeployCmdTool).toBe(true);
57
58 });
59});
60
61describe('Windows 10 deployment interacts with the file system as expected.', function () {
62
63 function fakeSpawn (cmd, args, cwd) {
64 expect(cmd).toBe(path.join('c:/Program Files (x86)/Windows Kits/10/bin/x86/WinAppDeployCmd.exe'));
65 switch (args[0]) {
66 case 'devices':
67 var output = 'Windows App Deployment Tool\r\nVersion 10.0.0.0\r\nCopyright (c) Microsoft Corporation. All rights reserved.\r\n\r\nDiscovering devices...\r\nIP Address GUID Model/Name\r\n127.0.0.1 00000015-b21e-0da9-0000-000000000000 Lumia 1520 (RM-940)\r\n10.120.70.172 00000000-0000-0000-0000-00155d619532 00155D619532\r\n10.120.68.150 00000000-0000-0000-0000-00155d011765 00155D011765\r\nDone.';
68 return Q(output);
69
70 case 'update':
71 case 'install':
72 expect(args[2]).toBe(TEST_APP_PACKAGE_NAME);
73 expect(args[4]).toBe('127.0.0.1');
74 return Q('');
75
76 case 'uninstall':
77 expect(args[2]).toBe(TEST_APP_PACKAGE_ID);
78 expect(args[4]).toBe('10.120.68.150');
79 return Q('');
80
81 }
82 }
83
84 var mockedSpawn = deployment.__get__('spawn');
85 var mockedProgramFiles = process.env['ProgramFiles(x86)'];
86
87 beforeEach(function () {
88 deployment.__set__('spawn', fakeSpawn);
89 process.env['ProgramFiles(x86)'] = path.join('c:/Program Files (x86)');
90 });
91
92 afterEach(function () {
93 deployment.__set__('spawn', mockedSpawn);
94 if (mockedProgramFiles) {
95 process.env['ProgramFiles(x86)'] = mockedProgramFiles;
96 } else {
97 delete process.env['ProgramFiles(x86)'];
98 }
99 });
100
101 it('Test #002 : enumerateDevices returns a valid set of objects', function (done) {
102 var deploymentTool = deployment.getDeploymentTool('10.0');
103 deploymentTool.enumerateDevices()
104 .then(function (deviceList) {
105 expect(deviceList.length).toBe(3);
106 expect(deviceList[0].name).toBe('Lumia 1520 (RM-940)');
107 expect(deviceList[0].index).toBe(0);
108 expect(deviceList[0].type).toBe('device');
109 done();
110 }).fail(function err (errMsg) {
111 expect(errMsg).toBeUndefined();
112 done();
113 });
114 });
115
116 it('Test #003 : installAppPackage passes the correct set of parameters', function (done) {
117 var deploymentTool = deployment.getDeploymentTool('10.0');
118 deploymentTool.enumerateDevices()
119 .then(function (deviceList) {
120 deploymentTool.installAppPackage(TEST_APP_PACKAGE_NAME, deviceList[0], /* shouldLaunch */ false, /* shouldUpdate */ false);
121 done();
122 }).fail(function err (errMsg) {
123 expect(errMsg).toBeUndefined();
124 done();
125 });
126 });
127
128 it('Test #004 : installAppPackage passes the correct set of parameters when updating', function (done) {
129 var deploymentTool = deployment.getDeploymentTool('10.0');
130 deploymentTool.enumerateDevices()
131 .then(function (deviceList) {
132 deploymentTool.installAppPackage(TEST_APP_PACKAGE_NAME, deviceList[0], /* shouldLaunch */ false, /* shouldUpdate */ true);
133 done();
134 }).fail(function err (errMsg) {
135 expect(errMsg).toBeUndefined();
136 done();
137 });
138 });
139
140 it('Test #005 : uninstallAppPackage passes the correct set of parameters', function (done) {
141 var deploymentTool = deployment.getDeploymentTool('10.0');
142 deploymentTool.enumerateDevices()
143 .then(function (deviceList) {
144 deploymentTool.uninstallAppPackage(TEST_APP_PACKAGE_ID, deviceList[2]);
145 done();
146 }).fail(function err (errMsg) {
147 expect(errMsg).toBeUndefined();
148 done();
149 });
150 });
151});
152
153describe('Windows 8.1 deployment interacts with the file system as expected.', function () {
154
155 function fakeSpawn (cmd, args, cwd) {
156 expect(cmd).toBe(path.join('c:/Program Files (x86)/Microsoft SDKs/Windows Phone/v8.1/Tools/AppDeploy/AppDeployCmd.exe'));
157 switch (args[0]) {
158 case '/EnumerateDevices':
159 var output = '\r\nDevice Index Device Name\r\n------------ -------------------------------\r\n 0 Device\r\n 1 Mobile Emulator 10.0.10150.0 WVGA 4 inch 512MB\r\n 2 Mobile Emulator 10.0.10150.0 WVGA 4 inch 1GB\r\n 3 Mobile Emulator 10.0.10150.0 WXGA 4.5 inch 1GB\r\n 4 Mobile Emulator 10.0.10150.0 720p 5 inch 1GB\r\n 5 Mobile Emulator 10.0.10150.0 1080p 6 inch 2GB\r\n 6 Emulator 8.1 WVGA 4 inch 512MB\r\n 7 Emulator 8.1 WVGA 4 inch\r\n 8 Emulator 8.1 WXGA 4.5 inch\r\n 9 Emulator 8.1 720P 4.7 inch\r\n 10 Emulator 8.1 1080P 5.5 inch\r\n 11 Emulator 8.1 1080P 6 inch\r\nDone.\r\n';
160 return Q(output);
161
162 case '/update':
163 case '/install':
164 case '/updatelaunch':
165 case '/installlaunch':
166 expect(args[1]).toBe(TEST_APP_PACKAGE_NAME);
167 expect(args[2]).toBe('/targetdevice:de');
168 return Q('');
169
170 case '/uninstall':
171 expect(args[1]).toBe(TEST_APP_PACKAGE_ID);
172 expect(args[2]).toBe('/targetdevice:5');
173 return Q('');
174
175 default:
176 throw new Error('Unrecognized AppDeployCmd parameter "' + args[0] + '"');
177
178 }
179 }
180
181 var mockedSpawn = deployment.__get__('spawn');
182 var mockedProgramFiles = process.env['ProgramFiles(x86)'];
183
184 beforeEach(function () {
185 deployment.__set__('spawn', fakeSpawn);
186 process.env['ProgramFiles(x86)'] = path.join('c:/Program Files (x86)');
187 });
188
189 afterEach(function () {
190 deployment.__set__('spawn', mockedSpawn);
191 if (mockedProgramFiles) {
192 process.env['ProgramFiles(x86)'] = mockedProgramFiles;
193 } else {
194 delete process.env['ProgramFiles(x86)'];
195 }
196 });
197
198 it('Test #006 : enumerateDevices returns a valid set of objects', function (done) {
199 var deploymentTool = deployment.getDeploymentTool('8.1');
200 deploymentTool.enumerateDevices()
201 .then(function (deviceList) {
202 expect(deviceList.length).toBe(12);
203 expect(deviceList[0].name).toBe('Device');
204 expect(deviceList[0].index).toBe(0);
205 expect(deviceList[0].type).toBe('device');
206 expect(deviceList[5].name).toBe('Mobile Emulator 10.0.10150.0 1080p 6 inch 2GB');
207 expect(deviceList[5].index).toBe(5);
208 expect(deviceList[5].type).toBe('emulator');
209 done();
210 }).fail(function err (errMsg) {
211 expect(errMsg).toBeUndefined();
212 done();
213 });
214 });
215
216 it('Test #007 : installAppPackage passes the correct set of parameters', function (done) {
217 var deploymentTool = deployment.getDeploymentTool('8.1');
218 deploymentTool.enumerateDevices()
219 .then(function (deviceList) {
220 deploymentTool.installAppPackage(TEST_APP_PACKAGE_NAME, deviceList[0], /* shouldLaunch */ false, /* shouldUpdate */ false);
221 done();
222 }).fail(function err (errMsg) {
223 expect(errMsg).toBeUndefined();
224 done();
225 });
226 });
227
228 it('Test #008 : installAppPackage passes the correct set of parameters when updating', function (done) {
229 var deploymentTool = deployment.getDeploymentTool('8.1');
230 deploymentTool.enumerateDevices()
231 .then(function (deviceList) {
232 deploymentTool.installAppPackage(TEST_APP_PACKAGE_NAME, deviceList[0], /* shouldLaunch */ false, /* shouldUpdate */ true);
233 done();
234 }).fail(function err (errMsg) {
235 expect(errMsg).toBeUndefined();
236 done();
237 });
238 });
239
240 it('Test #009 : installAppPackage passes the correct set of parameters when launching', function (done) {
241 var deploymentTool = deployment.getDeploymentTool('8.1');
242 deploymentTool.enumerateDevices()
243 .then(function (deviceList) {
244 deploymentTool.installAppPackage(TEST_APP_PACKAGE_NAME, deviceList[0], /* shouldLaunch */ true, /* shouldUpdate */ false);
245 done();
246 }).fail(function err (errMsg) {
247 expect(errMsg).toBeUndefined();
248 done();
249 });
250 });
251
252 it('Test #010 : installAppPackage passes the correct set of parameters when updating and launching', function (done) {
253 var deploymentTool = deployment.getDeploymentTool('8.1');
254 deploymentTool.enumerateDevices()
255 .then(function (deviceList) {
256 deploymentTool.installAppPackage(TEST_APP_PACKAGE_NAME, deviceList[0], /* shouldLaunch */ true, /* shouldUpdate */ true);
257 done();
258 }).fail(function err (errMsg) {
259 expect(errMsg).toBeUndefined();
260 done();
261 });
262 });
263
264 it('Test #011 : uninstallAppPackage passes the correct set of parameters', function (done) {
265 var deploymentTool = deployment.getDeploymentTool('8.1');
266 deploymentTool.enumerateDevices()
267 .then(function (deviceList) {
268 deploymentTool.uninstallAppPackage(TEST_APP_PACKAGE_ID, deviceList[5]);
269 done();
270 }).fail(function err (errMsg) {
271 expect(errMsg).toBeUndefined();
272 done();
273 });
274 });
275});