@@ -25,6 +25,9 @@ import Future = require("fibers/future");
25
25
var assert = require ( "chai" ) . assert ;
26
26
require ( 'should' ) ;
27
27
28
+ let temp = require ( "temp" ) ;
29
+ temp . track ( ) ;
30
+
28
31
function createTestInjector ( ) {
29
32
var testInjector = new yok . Yok ( ) ;
30
33
@@ -165,4 +168,115 @@ describe('Platform Service Tests', () => {
165
168
} ) ;
166
169
} ) ;
167
170
} ) ;
171
+
172
+ describe ( "prepare platform unit tests" , ( ) => {
173
+ let testInjector : IInjector , fs : IFileSystem ;
174
+ beforeEach ( ( ) => {
175
+ testInjector = createTestInjector ( ) ;
176
+ testInjector . register ( "fs" , fsLib . FileSystem ) ;
177
+ fs = testInjector . resolve ( "fs" ) ;
178
+ } ) ;
179
+ it ( "should process only files in app folder when preparing for iOS platform" , ( ) => {
180
+ let tempFolder = temp . mkdirSync ( "prepare platform" ) ;
181
+
182
+ let appFolderPath = path . join ( tempFolder , "app" ) ;
183
+ fs . createDirectory ( appFolderPath ) . wait ( ) ;
184
+
185
+ let app1FolderPath = path . join ( tempFolder , "app1" ) ;
186
+ fs . createDirectory ( app1FolderPath ) . wait ( ) ;
187
+
188
+ let appDestFolderPath = path . join ( tempFolder , "appDest" ) ;
189
+ let appResourcesFolderPath = path . join ( appDestFolderPath , "App_Resources" ) ;
190
+
191
+ // Add platform specific files to app and app1 folders
192
+ let platformSpecificFiles = [
193
+ "test1.ios.js" , "test1-ios-js" , "test2.android.js" , "test2-android-js"
194
+ ] ;
195
+
196
+ let destinationDirectories = [ appFolderPath , app1FolderPath ] ;
197
+
198
+ _ . each ( destinationDirectories , directoryPath => {
199
+ _ . each ( platformSpecificFiles , filePath => {
200
+ let fileFullPath = path . join ( directoryPath , filePath ) ;
201
+ fs . writeFile ( fileFullPath , "testData" ) . wait ( ) ;
202
+ } ) ;
203
+ } ) ;
204
+
205
+ let platformsData = testInjector . resolve ( "platformsData" ) ;
206
+ platformsData . platformsNames = [ "ios" , "android" ] ;
207
+ platformsData . getPlatformData = ( platform : string ) => {
208
+ return {
209
+ appDestinationDirectoryPath : appDestFolderPath ,
210
+ appResourcesDestinationDirectoryPath : appResourcesFolderPath ,
211
+ normalizedPlatformName : "iOS"
212
+ }
213
+ } ;
214
+
215
+ let projectData = testInjector . resolve ( "projectData" ) ;
216
+ projectData . projectDir = tempFolder ;
217
+
218
+ let platformService = testInjector . resolve ( "platformService" ) ;
219
+ platformService . preparePlatform ( "ios" ) . wait ( ) ;
220
+
221
+ // Asserts that the files in app folder are process as platform specific
222
+ assert . isTrue ( fs . exists ( path . join ( appDestFolderPath , "app" , "test1.js" ) ) . wait ( ) ) ;
223
+ assert . isTrue ( fs . exists ( path . join ( appDestFolderPath , "app" , "test1-js" ) ) . wait ( ) ) ;
224
+ assert . isFalse ( fs . exists ( path . join ( appDestFolderPath , "app" , "test2.js" ) ) . wait ( ) ) ;
225
+ assert . isFalse ( fs . exists ( path . join ( appDestFolderPath , "app" , "test2-js" ) ) . wait ( ) ) ;
226
+
227
+ // Asserts that the files in app1 folder aren't process as platform specific
228
+ assert . isFalse ( fs . exists ( path . join ( appDestFolderPath , "app1" ) ) . wait ( ) ) ;
229
+ } ) ;
230
+ it ( "should process only files in app folder when preparing for Android platform" , ( ) => {
231
+ let tempFolder = temp . mkdirSync ( "prepare platform" ) ;
232
+
233
+ let appFolderPath = path . join ( tempFolder , "app" ) ;
234
+ fs . createDirectory ( appFolderPath ) . wait ( ) ;
235
+
236
+ let app1FolderPath = path . join ( tempFolder , "app1" ) ;
237
+ fs . createDirectory ( app1FolderPath ) . wait ( ) ;
238
+
239
+ let appDestFolderPath = path . join ( tempFolder , "appDest" ) ;
240
+ let appResourcesFolderPath = path . join ( appDestFolderPath , "App_Resources" ) ;
241
+
242
+ // Add platform specific files to app and app1 folders
243
+ let platformSpecificFiles = [
244
+ "test1.ios.js" , "test1-ios-js" , "test2.android.js" , "test2-android-js"
245
+ ] ;
246
+
247
+ let destinationDirectories = [ appFolderPath , app1FolderPath ] ;
248
+
249
+ _ . each ( destinationDirectories , directoryPath => {
250
+ _ . each ( platformSpecificFiles , filePath => {
251
+ let fileFullPath = path . join ( directoryPath , filePath ) ;
252
+ fs . writeFile ( fileFullPath , "testData" ) . wait ( ) ;
253
+ } ) ;
254
+ } ) ;
255
+
256
+ let platformsData = testInjector . resolve ( "platformsData" ) ;
257
+ platformsData . platformsNames = [ "ios" , "android" ] ;
258
+ platformsData . getPlatformData = ( platform : string ) => {
259
+ return {
260
+ appDestinationDirectoryPath : appDestFolderPath ,
261
+ appResourcesDestinationDirectoryPath : appResourcesFolderPath ,
262
+ normalizedPlatformName : "Android"
263
+ }
264
+ } ;
265
+
266
+ let projectData = testInjector . resolve ( "projectData" ) ;
267
+ projectData . projectDir = tempFolder ;
268
+
269
+ let platformService = testInjector . resolve ( "platformService" ) ;
270
+ platformService . preparePlatform ( "android" ) . wait ( ) ;
271
+
272
+ // Asserts that the files in app folder are process as platform specific
273
+ assert . isTrue ( fs . exists ( path . join ( appDestFolderPath , "app" , "test2.js" ) ) . wait ( ) ) ;
274
+ assert . isTrue ( fs . exists ( path . join ( appDestFolderPath , "app" , "test2-js" ) ) . wait ( ) ) ;
275
+ assert . isFalse ( fs . exists ( path . join ( appDestFolderPath , "app" , "test1.js" ) ) . wait ( ) ) ;
276
+ assert . isFalse ( fs . exists ( path . join ( appDestFolderPath , "app" , "test1-js" ) ) . wait ( ) ) ;
277
+
278
+ // Asserts that the files in app1 folder aren't process as platform specific
279
+ assert . isFalse ( fs . exists ( path . join ( appDestFolderPath , "app1" ) ) . wait ( ) ) ;
280
+ } ) ;
281
+ } ) ;
168
282
} ) ;
0 commit comments