1+ /// <reference path=".d.ts" />
2+ "use strict" ;
3+
4+ import yok = require( '../lib/common/yok' ) ;
5+ import fsLib = require( "../lib/common/file-system" ) ;
6+ import projectFilesManagerLib = require( "../lib/services/project-files-manager" ) ;
7+ import hostInfoLib = require( "../lib/common/host-info" ) ;
8+ import StaticConfigLib = require( "../lib/config" ) ;
9+ import ErrorsLib = require( "../lib/common/errors" ) ;
10+ import path = require( "path" ) ;
11+ import temp = require( "temp" ) ;
12+ temp . track ( ) ;
13+
14+ var assert = require ( "chai" ) . assert ;
15+
16+ function createTestInjector ( ) {
17+ let testInjector = new yok . Yok ( ) ;
18+ testInjector . register ( "fs" , fsLib . FileSystem ) ;
19+ testInjector . register ( "hostInfo" , hostInfoLib . HostInfo ) ;
20+ testInjector . register ( "staticConfig" , StaticConfigLib . StaticConfig ) ;
21+ testInjector . register ( "projectFilesManager" , projectFilesManagerLib . ProjectFilesManager ) ;
22+ testInjector . register ( "errors" , ErrorsLib . Errors ) ;
23+ testInjector . register ( "platformsData" , {
24+ platformsNames : [ "ios" , "android" ]
25+ } ) ;
26+
27+ return testInjector ;
28+ }
29+
30+ function createFiles ( testInjector : IInjector , filesToCreate : string [ ] ) : IFuture < string > {
31+ return ( ( ) => {
32+ let fs = testInjector . resolve ( "fs" ) ;
33+ let directoryPath = temp . mkdirSync ( "Project Files Manager Tests" ) ;
34+
35+ _ . each ( filesToCreate , file => fs . writeFile ( path . join ( directoryPath , file ) , "" ) . wait ( ) ) ;
36+
37+ return directoryPath ;
38+ } ) . future < string > ( ) ( ) ;
39+ }
40+
41+ describe ( 'Project Files Manager Tests' , ( ) => {
42+ let testInjector : IInjector , projectFilesManager : IProjectFilesManager ;
43+ beforeEach ( ( ) => {
44+ testInjector = createTestInjector ( ) ;
45+ projectFilesManager = testInjector . resolve ( "projectFilesManager" ) ;
46+ } ) ;
47+ it ( "filters android specific files" , ( ) => {
48+ let files = [ "test.ios.x" , "test.android.x" ] ;
49+ let directoryPath = createFiles ( testInjector , files ) . wait ( ) ;
50+
51+ projectFilesManager . processPlatformSpecificFiles ( directoryPath , "android" ) . wait ( ) ;
52+
53+ let fs = testInjector . resolve ( "fs" ) ;
54+ assert . isFalse ( fs . exists ( path . join ( directoryPath , "test.ios.x" ) ) . wait ( ) ) ;
55+ assert . isTrue ( fs . exists ( path . join ( directoryPath , "test.x" ) ) . wait ( ) ) ;
56+ assert . isFalse ( fs . exists ( path . join ( directoryPath , "test.android.x" ) ) . wait ( ) ) ;
57+ } ) ;
58+ it ( "filters ios specific files" , ( ) => {
59+ let files = [ "index.ios.html" , "index1.android.html" , "a.test" ] ;
60+ let directoryPath = createFiles ( testInjector , files ) . wait ( ) ;
61+
62+ projectFilesManager . processPlatformSpecificFiles ( directoryPath , "ios" ) . wait ( ) ;
63+
64+ let fs = testInjector . resolve ( "fs" ) ;
65+ assert . isFalse ( fs . exists ( path . join ( directoryPath , "index1.android.html" ) ) . wait ( ) ) ;
66+ assert . isFalse ( fs . exists ( path . join ( directoryPath , "index1.html" ) ) . wait ( ) ) ;
67+ assert . isTrue ( fs . exists ( path . join ( directoryPath , "index.html" ) ) . wait ( ) ) ;
68+ assert . isTrue ( fs . exists ( path . join ( directoryPath , "a.test" ) ) . wait ( ) ) ;
69+ } ) ;
70+ it ( "doesn't filter non platform specific files" , ( ) => {
71+ let files = [ "index1.js" , "index2.js" , "index3.js" ] ;
72+ let directoryPath = createFiles ( testInjector , files ) . wait ( ) ;
73+
74+ projectFilesManager . processPlatformSpecificFiles ( directoryPath , "ios" ) . wait ( ) ;
75+
76+ let fs = testInjector . resolve ( "fs" ) ;
77+ assert . isTrue ( fs . exists ( path . join ( directoryPath , "index1.js" ) ) . wait ( ) ) ;
78+ assert . isTrue ( fs . exists ( path . join ( directoryPath , "index2.js" ) ) . wait ( ) ) ;
79+ assert . isTrue ( fs . exists ( path . join ( directoryPath , "index3.js" ) ) . wait ( ) ) ;
80+ } ) ;
81+ } ) ;
0 commit comments