UNPKG

13.7 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*/
19var shell = require('shelljs');
20var fs = require('fs-extra');
21var path = require('path');
22
23var FIXTURES = path.join(__dirname, '../unit/fixtures');
24var EXTENSIONS_PLUGIN = 'org.test.plugins.extensionsplugin';
25var extensionsPlugin = path.join(FIXTURES, EXTENSIONS_PLUGIN);
26
27var templateFolder = path.join(__dirname, '../../template');
28var Api = require(path.join(templateFolder, 'cordova/Api'));
29var PluginInfo = require('cordova-common').PluginInfo;
30
31describe('Cordova create and build', function () {
32
33 var templateDir = path.join(__dirname, '../../template');
34 var projectFolder = 'testcreate 応用';
35 var workingDirectory = path.join(__dirname, '../../temp');
36 var buildDirectory = path.join(workingDirectory, 'platforms');
37 var appPackagesFolder = path.join(buildDirectory, projectFolder, 'AppPackages');
38 var buildScriptPath = '"' + path.join(buildDirectory, projectFolder, 'cordova', 'build') + '"';
39 var prepareScriptPath = '"' + path.join(buildDirectory, projectFolder, 'cordova', 'prepare') + '"';
40
41 var silent = false;
42
43 function verifySubDirContainsFile (subDirName, fileName, count) {
44 count = typeof count !== 'undefined' ? count : 1;
45
46 var subDir = path.join(appPackagesFolder, subDirName);
47 var packages = shell.ls(subDir);
48 expect(packages.filter(function (file) { return file.match(fileName); }).length).toBe(count);
49 }
50
51 function _expectExist (fileNamePattern, count) {
52 count = typeof count !== 'undefined' ? count : 1;
53
54 var packages = shell.ls(appPackagesFolder);
55 expect(packages.filter(function (file) { return file.match(fileNamePattern); }).length).toBe(count);
56 }
57
58 function _expectSubdirAndFileExist (subDirName, fileName, count) {
59 count = typeof count !== 'undefined' ? count : 1;
60
61 _expectExist(subDirName);
62 verifySubDirContainsFile(subDirName, fileName, count);
63 }
64
65 beforeEach(function () {
66 fs.ensureDirSync(buildDirectory);
67 fs.copySync(path.join(templateDir, 'www'), path.join(workingDirectory, 'www'));
68 fs.copySync(path.join(templateDir, 'config.xml'), path.join(workingDirectory, 'config.xml'));
69 shell.exec(path.join('bin', 'create') + ' "' + path.join(buildDirectory, projectFolder) + '" com.test.app 応用', { silent: silent });
70 shell.exec(prepareScriptPath + '', { silent: silent });
71 });
72
73 afterEach(function () {
74 fs.removeSync(workingDirectory);
75 });
76
77 it('spec.1 should create new project', function () {
78 expect(fs.existsSync(path.join(buildDirectory, projectFolder))).toBe(true);
79 });
80
81 describe('Windows 10', function () {
82
83 // default
84
85 it('spec.2a should build default (win10) project', function () {
86 shell.exec(buildScriptPath + '', { silent: silent });
87 _expectSubdirAndFileExist('CordovaApp.Windows10_1.0.0.0_anycpu_debug_Test', 'CordovaApp.Windows10_1.0.0.0_anycpu_debug.appx');
88 });
89
90 // --appx
91
92 it('spec.2b should build uap (win10) project', function () {
93 shell.exec(buildScriptPath + ' --appx=uap', { silent: silent });
94 _expectSubdirAndFileExist('CordovaApp.Windows10_1.0.0.0_anycpu_debug_Test', 'CordovaApp.Windows10_1.0.0.0_anycpu_debug.appx');
95 });
96
97 it('spec.2c should build uwp (win10) project', function () {
98 shell.exec(buildScriptPath + ' --appx=uwp', { silent: silent });
99 _expectSubdirAndFileExist('CordovaApp.Windows10_1.0.0.0_anycpu_debug_Test', 'CordovaApp.Windows10_1.0.0.0_anycpu_debug.appx');
100 });
101
102 // --archs
103
104 it('spec.3a should build project for particular CPU', function () {
105 shell.exec(buildScriptPath + ' --archs=\"x64\"', { silent: silent }); /* eslint no-useless-escape : 0 */
106 _expectSubdirAndFileExist('CordovaApp.Windows10_1.0.0.0_x64_debug_Test', 'CordovaApp.Windows10_1.0.0.0_x64_debug.appx');
107 });
108
109 it('spec.4a should build project for CPUs separated by whitespaces', function () {
110 shell.exec(buildScriptPath + ' --archs=\"x64 x86 arm anycpu\"', { silent: silent }); /* eslint no-useless-escape : 0 */
111 _expectSubdirAndFileExist('CordovaApp.Windows10_1.0.0.0_x64_debug_Test', 'CordovaApp.Windows10_1.0.0.0_x64_debug.appx');
112 _expectSubdirAndFileExist('CordovaApp.Windows10_1.0.0.0_x86_debug_Test', 'CordovaApp.Windows10_1.0.0.0_x86_debug.appx');
113 _expectSubdirAndFileExist('CordovaApp.Windows10_1.0.0.0_arm_debug_Test', 'CordovaApp.Windows10_1.0.0.0_arm_debug.appx');
114 _expectSubdirAndFileExist('CordovaApp.Windows10_1.0.0.0_anycpu_debug_Test', 'CordovaApp.Windows10_1.0.0.0_anycpu_debug.appx');
115 });
116
117 // "InProcessServer extension"
118
119 it('spec.5a should build project containing plugin with InProcessServer extension', function (done) {
120 var extensionsPluginInfo, api;
121
122 extensionsPluginInfo = new PluginInfo(extensionsPlugin);
123 api = new Api();
124 api.root = path.join(buildDirectory, projectFolder);
125 api.locations.root = path.join(buildDirectory, projectFolder);
126 api.locations.www = path.join(buildDirectory, projectFolder, 'www');
127
128 var fail = jasmine.createSpy('fail')
129 .and.callFake(function (err) {
130 console.error(err);
131 });
132
133 api.addPlugin(extensionsPluginInfo)
134 .then(function () {
135 shell.exec(buildScriptPath, { silent: silent });
136 _expectSubdirAndFileExist('CordovaApp.Windows10_1.0.0.0_anycpu_debug_Test', 'CordovaApp.Windows10_1.0.0.0_anycpu_debug.appx');
137 })
138 .catch(fail)
139 .finally(function () {
140 expect(fail).not.toHaveBeenCalled();
141 done();
142 });
143 });
144
145 // --release --bundle
146
147 it('spec.6a should generate appxupload and appxbundle for Windows 10 project bundle release build', function () {
148 // FIXME Fails for VS 2017 on AppVeyor
149 if (process.env.APPVEYOR_BUILD_WORKER_IMAGE === 'Visual Studio 2017') {
150 pending('This test is broken for VS 2017 on AppVeyor');
151 }
152
153 shell.exec(buildScriptPath + ' --release --bundle --archs=\"x64 x86 arm\"', { silent: silent });
154 _expectExist(/.*bundle\.appxupload$/, 3);
155 _expectSubdirAndFileExist('CordovaApp.Windows10_1.0.0.0_Test', 'CordovaApp.Windows10_1.0.0.0_x64_x86_arm.appxbundle');
156 });
157
158 // --release (non-bundle)
159
160 it('spec.7 should generate appxupload for Windows 10 project non-bundle release build', function () {
161 shell.exec(buildScriptPath + ' --release --archs=\"x64 x86 arm\"', { silent: silent });
162 _expectExist(/.*\.appxupload$/, 3);
163 // CB-12416 Should build appx in separate dirs for each architecture
164 // Should contain a subdirectory for each of the architectures
165 // These subdirectories should contain corresponding appx files
166 _expectSubdirAndFileExist('CordovaApp.Windows10_1.0.0.0_arm_Test', 'CordovaApp.Windows10_1.0.0.0_arm.appx');
167 _expectSubdirAndFileExist('CordovaApp.Windows10_1.0.0.0_x64_Test', 'CordovaApp.Windows10_1.0.0.0_x64.appx');
168 _expectSubdirAndFileExist('CordovaApp.Windows10_1.0.0.0_x86_Test', 'CordovaApp.Windows10_1.0.0.0_x86.appx');
169 });
170
171 });
172
173 describe('Windows 8.1', function () {
174
175 beforeEach(function () {
176 if (process.env.APPVEYOR_BUILD_WORKER_IMAGE === 'Visual Studio 2017' && process.env.MSBUILDDIR !== 'C:\\Program Files (x86)\\MSBuild\\14.0\\bin\\') {
177 pending('Windows 8.1 builds are not supported by Visual Studio 2017: https://docs.microsoft.com/en-us/visualstudio/productinfo/vs2017-compatibility-vs#windows-store-and-windows-phone-apps');
178 /*
179 via https://issues.apache.org/jira/browse/CB-13874
180 > Projects for Windows Store 8.1 and 8.0, and Windows Phone 8.1 and 8.0 are not supported in this release.
181 > To maintain these apps, continue to use Visual Studio 2015
182 */
183 }
184 });
185
186 it('spec.2d should build 8.1 win project', function () {
187 shell.exec(buildScriptPath + ' --appx=8.1-win', { silent: silent });
188 _expectExist(/.*Windows.*\.appxupload/);
189 });
190
191 it('spec.2e should build 8.1 phone project', function () {
192 shell.exec(buildScriptPath + ' --appx=8.1-phone', { silent: silent });
193 _expectExist(/.*Phone.*\.appxupload/);
194 });
195
196 it('spec.2f should build 8.1 win + phone project', function () {
197 shell.exec(buildScriptPath + ' --appx=8.1', { silent: silent });
198 _expectExist(/.*Windows.*\.appxupload/);
199 _expectExist(/.*Phone.*\.appxupload/);
200 });
201
202 // --archs
203
204 it('spec.3b should build project (8.1) for particular CPU', function () {
205 shell.exec(buildScriptPath + ' --appx=8.1 --archs=\"x64\"', { silent: silent }); /* eslint no-useless-escape : 0 */
206 _expectExist(/.*Phone.*x64.*\.appxupload/);
207 _expectExist(/.*Windows.*x64.*\.appxupload/);
208 });
209
210 it('spec.3c should build project (8.1-win) for particular CPU', function () {
211 shell.exec(buildScriptPath + ' --appx=8.1-win --archs=\"x64\"', { silent: silent }); /* eslint no-useless-escape : 0 */
212 _expectExist(/.*Windows.*x64.*\.appxupload/);
213 });
214
215 it('spec.3d should build project (8.1-phone) for particular CPU', function () {
216 shell.exec(buildScriptPath + ' --appx=8.1-phone --archs=\"x64\"', { silent: silent }); /* eslint no-useless-escape : 0 */
217 _expectExist(/.*Phone.*x64.*\.appxupload/);
218 });
219
220 it('spec.4b should build project (8.1) for CPUs separated by whitespaces', function () {
221 shell.exec(buildScriptPath + ' --appx=8.1 --archs=\"x64 x86 arm anycpu\"', { silent: silent }); /* eslint no-useless-escape : 0 */
222 _expectExist(/.*Phone.*x86.*\.appxupload/);
223 _expectExist(/.*Phone.*x64.*\.appxupload/);
224 _expectExist(/.*Phone.*arm.*\.appxupload/);
225 _expectExist(/.*Phone.*AnyCPU.*\.appxupload/i);
226 _expectExist(/.*Windows.*x64.*\.appxupload/);
227 _expectExist(/.*Windows.*x86.*\.appxupload/);
228 _expectExist(/.*Windows.*arm.*\.appxupload/);
229 _expectExist(/.*Windows.*anycpu.*\.appxupload/i);
230 });
231
232 // "InProcessServer extension"
233
234 it('spec.5b should build project (8.1) containing plugin with InProcessServer extension', function (done) {
235 var extensionsPluginInfo, api;
236
237 extensionsPluginInfo = new PluginInfo(extensionsPlugin);
238 api = new Api();
239 api.root = path.join(buildDirectory, projectFolder);
240 api.locations.root = path.join(buildDirectory, projectFolder);
241 api.locations.www = path.join(buildDirectory, projectFolder, 'www');
242
243 var fail = jasmine.createSpy('fail')
244 .and.callFake(function (err) {
245 console.error(err);
246 });
247
248 api.addPlugin(extensionsPluginInfo)
249 .then(function () {
250 shell.exec(buildScriptPath + ' --appx=8.1', { silent: silent });
251 _expectExist(/.*Windows.*\.appxupload/);
252 _expectExist(/.*Phone.*\.appxupload/);
253 })
254 .catch(fail)
255 .finally(function () {
256 expect(fail).not.toHaveBeenCalled();
257 done();
258 });
259 });
260
261 // --release --bundle
262
263 it('spec.6b should generate appxupload and appxbundle for Windows Phone 8.1 project bundle release build', function () {
264 shell.exec(buildScriptPath + ' --release --appx=8.1-phone --bundle --archs=\"x64 x86 arm\"', { silent: silent });
265 _expectExist(/.*bundle\.appxupload$/, 3);
266 _expectSubdirAndFileExist('CordovaApp.Phone_1.0.0.0_Test', 'CordovaApp.Phone_1.0.0.0_x64_x86_arm.appxbundle');
267 });
268
269 // --release (non-bundle)
270
271 it('spec.8 for a non-bundle case for Windows Phone 8.1 it should build appx in separate dirs for each architecture', function () {
272 shell.exec(buildScriptPath + ' --release --appx=8.1-phone --phone --archs=\"x86 arm\"', { silent: silent });
273 _expectExist(/.*\.appxupload$/, 2);
274 _expectSubdirAndFileExist('CordovaApp.Phone_1.0.0.0_arm_Test', 'CordovaApp.Phone_1.0.0.0_arm.appx');
275 _expectSubdirAndFileExist('CordovaApp.Phone_1.0.0.0_x86_Test', 'CordovaApp.Phone_1.0.0.0_x86.appx');
276 });
277
278 });
279
280});