4
4
import yok = require( '../lib/common/yok' ) ;
5
5
import stubs = require( './stubs' ) ;
6
6
import * as constants from "./../lib/constants" ;
7
- import * as ChildProcessLib from "../lib/common/child-process" ;
7
+ import { ChildProcess } from "../lib/common/child-process" ;
8
8
import * as ProjectServiceLib from "../lib/services/project-service" ;
9
9
import * as ProjectDataServiceLib from "../lib/services/project-data-service" ;
10
10
import * as ProjectDataLib from "../lib/project-data" ;
11
11
import * as ProjectHelperLib from "../lib/common/project-helper" ;
12
- import * as StaticConfigLib from "../lib/config" ;
12
+ import { StaticConfig } from "../lib/config" ;
13
13
import * as NpmLib from "../lib/node-package-manager" ;
14
- import * as NpmInstallationManagerLib from "../lib/npm-installation-manager" ;
14
+ import { NpmInstallationManager } from "../lib/npm-installation-manager" ;
15
15
import * as HttpClientLib from "../lib/common/http-client" ;
16
- import * as fsLib from "../lib/common/file-system" ;
16
+ import { FileSystem } from "../lib/common/file-system" ;
17
17
import * as path from "path" ;
18
18
import temp = require( "temp" ) ;
19
19
import * as helpers from "../lib/common/helpers" ;
20
20
import { assert } from "chai" ;
21
- import * as optionsLib from "../lib/options" ;
22
- import * as hostInfoLib from "../lib/common/host-info" ;
21
+ import { Options } from "../lib/options" ;
22
+ import { HostInfo } from "../lib/common/host-info" ;
23
+ import { IOSProjectService } from "../lib/services/ios-project-service" ;
24
+ import * as shell from "shelljs" ;
23
25
24
26
let mockProjectNameValidator = {
25
27
validate : ( ) => { return true ; }
@@ -39,21 +41,20 @@ class ProjectIntegrationTest {
39
41
return projectService . createProject ( projectName ) ;
40
42
}
41
43
42
- public getDefaultTemplatePath ( ) : IFuture < string > {
44
+ public getNpmPackagePath ( packageName : string ) : IFuture < string > {
43
45
return ( ( ) => {
44
46
let npmInstallationManager = this . testInjector . resolve ( "npmInstallationManager" ) ;
45
47
let fs = this . testInjector . resolve ( "fs" ) ;
46
48
47
- let defaultTemplatePackageName = "tns-template-hello-world" ;
48
49
let cacheRoot = npmInstallationManager . getCacheRootPath ( ) ;
49
- let defaultTemplatePath = path . join ( cacheRoot , defaultTemplatePackageName ) ;
50
- let latestVersion = npmInstallationManager . getLatestVersion ( defaultTemplatePackageName ) . wait ( ) ;
50
+ let defaultTemplatePath = path . join ( cacheRoot , packageName ) ;
51
+ let latestVersion = npmInstallationManager . getLatestVersion ( packageName ) . wait ( ) ;
51
52
52
53
if ( ! fs . exists ( path . join ( defaultTemplatePath , latestVersion ) ) . wait ( ) ) {
53
- npmInstallationManager . addToCache ( defaultTemplatePackageName , latestVersion ) . wait ( ) ;
54
+ npmInstallationManager . addToCache ( packageName , latestVersion ) . wait ( ) ;
54
55
}
55
56
if ( ! fs . exists ( path . join ( defaultTemplatePath , latestVersion , "package" , "app" ) ) . wait ( ) ) {
56
- npmInstallationManager . cacheUnpack ( defaultTemplatePackageName , latestVersion ) . wait ( ) ;
57
+ npmInstallationManager . cacheUnpack ( packageName , latestVersion ) . wait ( ) ;
57
58
}
58
59
59
60
return path . join ( defaultTemplatePath , latestVersion , "package" ) ;
@@ -103,26 +104,25 @@ class ProjectIntegrationTest {
103
104
104
105
private createTestInjector ( ) : void {
105
106
this . testInjector = new yok . Yok ( ) ;
106
- this . testInjector . register ( "childProcess" , ChildProcessLib . ChildProcess ) ;
107
+ this . testInjector . register ( "childProcess" , ChildProcess ) ;
107
108
this . testInjector . register ( "errors" , stubs . ErrorsStub ) ;
108
109
this . testInjector . register ( 'logger' , stubs . LoggerStub ) ;
109
110
this . testInjector . register ( "projectService" , ProjectServiceLib . ProjectService ) ;
110
111
this . testInjector . register ( "projectHelper" , ProjectHelperLib . ProjectHelper ) ;
111
112
this . testInjector . register ( "projectTemplatesService" , stubs . ProjectTemplatesService ) ;
112
113
this . testInjector . register ( "projectNameValidator" , mockProjectNameValidator ) ;
113
114
114
- this . testInjector . register ( "fs" , fsLib . FileSystem ) ;
115
+ this . testInjector . register ( "fs" , FileSystem ) ;
115
116
this . testInjector . register ( "projectDataService" , ProjectDataServiceLib . ProjectDataService ) ;
116
- this . testInjector . register ( "staticConfig" , StaticConfigLib . StaticConfig ) ;
117
+ this . testInjector . register ( "staticConfig" , StaticConfig ) ;
117
118
118
- this . testInjector . register ( "npmInstallationManager" , NpmInstallationManagerLib . NpmInstallationManager ) ;
119
+ this . testInjector . register ( "npmInstallationManager" , NpmInstallationManager ) ;
119
120
this . testInjector . register ( "npm" , NpmLib . NodePackageManager ) ;
120
121
this . testInjector . register ( "httpClient" , HttpClientLib . HttpClient ) ;
121
- this . testInjector . register ( "config" , { } ) ;
122
122
this . testInjector . register ( "lockfile" , stubs . LockFile ) ;
123
123
124
- this . testInjector . register ( "options" , optionsLib . Options ) ;
125
- this . testInjector . register ( "hostInfo" , hostInfoLib . HostInfo ) ;
124
+ this . testInjector . register ( "options" , Options ) ;
125
+ this . testInjector . register ( "hostInfo" , HostInfo ) ;
126
126
}
127
127
}
128
128
@@ -135,7 +135,7 @@ describe("Project Service Tests", () => {
135
135
let options = projectIntegrationTest . testInjector . resolve ( "options" ) ;
136
136
137
137
options . path = tempFolder ;
138
- options . copyFrom = projectIntegrationTest . getDefaultTemplatePath ( ) . wait ( ) ;
138
+ options . copyFrom = projectIntegrationTest . getNpmPackagePath ( "tns-template-hello-world" ) . wait ( ) ;
139
139
140
140
projectIntegrationTest . createProject ( projectName ) . wait ( ) ;
141
141
projectIntegrationTest . assertProject ( tempFolder , projectName , "org.nativescript.myapp" ) . wait ( ) ;
@@ -147,12 +147,50 @@ describe("Project Service Tests", () => {
147
147
let options = projectIntegrationTest . testInjector . resolve ( "options" ) ;
148
148
149
149
options . path = tempFolder ;
150
- options . copyFrom = projectIntegrationTest . getDefaultTemplatePath ( ) . wait ( ) ;
150
+ options . copyFrom = projectIntegrationTest . getNpmPackagePath ( "tns-template-hello-world" ) . wait ( ) ;
151
151
options . appid = "my.special.id" ;
152
152
153
153
projectIntegrationTest . createProject ( projectName ) . wait ( ) ;
154
154
projectIntegrationTest . assertProject ( tempFolder , projectName , options . appid ) . wait ( ) ;
155
155
} ) ;
156
+ it ( "creates ios project and tests post-install sandboxing of CocoaPods setup" , ( ) => {
157
+ if ( require ( "os" ) . platform ( ) !== "darwin" ) {
158
+ console . log ( "Skipping CocoaPods sandbox test. It works only on darwin." ) ;
159
+ return ;
160
+ }
161
+
162
+ let testDirectoryPath = "/tmp/Podfile" ;
163
+ let testInjector = createInjectorForPodsTest ( ) ;
164
+ let iOSProjectService : IPlatformProjectService = testInjector . resolve ( "iOSProjectService" ) ;
165
+ let fs : IFileSystem = testInjector . resolve ( "fs" ) ;
166
+ let projectIntegrationTest = new ProjectIntegrationTest ( ) ;
167
+ let workingFolderPath = temp . mkdirSync ( "ios_project" ) ;
168
+ let iosTemplatePath = path . join ( projectIntegrationTest . getNpmPackagePath ( "tns-ios" ) . wait ( ) , "framework/" ) ;
169
+ let postInstallCommmand = `\`cat ${ testDirectoryPath } /testFile.txt > ${ workingFolderPath } /copyTestFile.txt && rm -rf ${ testDirectoryPath } \`` ;
170
+ let podfileContent = `post_install do |installer_representation| ${ postInstallCommmand } end` ;
171
+ let platformData = iOSProjectService . platformData ;
172
+
173
+ shell . cp ( "-R" , iosTemplatePath , workingFolderPath ) ;
174
+
175
+ fs . writeFile ( `${ testDirectoryPath } /testFile.txt` , "Test content." ) . wait ( ) ;
176
+ fs . writeFile ( path . join ( workingFolderPath , "Podfile" ) , podfileContent ) . wait ( ) ;
177
+
178
+ Object . defineProperty ( iOSProjectService , "platformData" , {
179
+ get : ( ) => {
180
+ return { projectRoot : workingFolderPath } ;
181
+ }
182
+ } ) ;
183
+
184
+ try {
185
+ iOSProjectService . afterPrepareAllPlugins ( ) . wait ( ) ;
186
+ } finally {
187
+ Object . defineProperty ( iOSProjectService , "platformData" , platformData ) ;
188
+ }
189
+
190
+ assert . isTrue ( fs . exists ( testDirectoryPath ) . wait ( ) ) ;
191
+ assert . isTrue ( fs . exists ( path . join ( workingFolderPath , "copyTestFile.txt" ) ) . wait ( ) ) ;
192
+ fs . deleteDirectory ( testDirectoryPath ) . wait ( ) ; // Clean up 'tmp' after test ends.
193
+ } ) ;
156
194
} ) ;
157
195
} ) ;
158
196
@@ -166,21 +204,56 @@ function createTestInjector() {
166
204
testInjector . register ( "projectTemplatesService" , stubs . ProjectTemplatesService ) ;
167
205
testInjector . register ( "projectNameValidator" , mockProjectNameValidator ) ;
168
206
169
- testInjector . register ( "fs" , fsLib . FileSystem ) ;
207
+ testInjector . register ( "fs" , FileSystem ) ;
170
208
testInjector . register ( "projectDataService" , ProjectDataServiceLib . ProjectDataService ) ;
171
209
172
- testInjector . register ( "staticConfig" , StaticConfigLib . StaticConfig ) ;
210
+ testInjector . register ( "staticConfig" , StaticConfig ) ;
173
211
174
- testInjector . register ( "npmInstallationManager" , NpmInstallationManagerLib . NpmInstallationManager ) ;
212
+ testInjector . register ( "npmInstallationManager" , NpmInstallationManager ) ;
175
213
testInjector . register ( "httpClient" , HttpClientLib . HttpClient ) ;
176
- testInjector . register ( "config" , { } ) ;
177
214
testInjector . register ( "lockfile" , stubs . LockFile ) ;
178
215
179
- testInjector . register ( "childProcess" , ChildProcessLib . ChildProcess ) ;
216
+ testInjector . register ( "childProcess" , ChildProcess ) ;
180
217
181
218
testInjector . register ( 'projectData' , ProjectDataLib . ProjectData ) ;
182
- testInjector . register ( "options" , optionsLib . Options ) ;
183
- testInjector . register ( "hostInfo" , hostInfoLib . HostInfo ) ;
219
+ testInjector . register ( "options" , Options ) ;
220
+ testInjector . register ( "hostInfo" , HostInfo ) ;
221
+
222
+ return testInjector ;
223
+ }
224
+
225
+ function createInjectorForPodsTest ( ) {
226
+ let testInjector = new yok . Yok ( ) ;
227
+
228
+ testInjector . register ( "errors" , stubs . ErrorsStub ) ;
229
+ testInjector . register ( 'logger' , stubs . LoggerStub ) ;
230
+ testInjector . register ( "projectHelper" , { } ) ;
231
+ testInjector . register ( "projectData" , {
232
+ projectName : "__PROJECT_NAME__" ,
233
+ platformsDir : ""
234
+ } ) ;
235
+ testInjector . register ( "iOSEmulatorServices" , { } ) ;
236
+ testInjector . register ( "config" , {
237
+ "USE_POD_SANDBOX" : true
238
+ } ) ;
239
+ testInjector . register ( "prompter" , { } ) ;
240
+ testInjector . register ( "fs" , FileSystem ) ;
241
+ testInjector . register ( "staticConfig" , StaticConfig ) ;
242
+ testInjector . register ( "npmInstallationManager" , NpmInstallationManager ) ;
243
+ testInjector . register ( "iOSProjectService" , IOSProjectService ) ;
244
+ testInjector . register ( "projectService" , ProjectServiceLib . ProjectService ) ;
245
+ testInjector . register ( "pluginsService" , {
246
+ getAllInstalledPlugins : ( ) => {
247
+ return ( ( ) => {
248
+ return < any > [ ] ;
249
+ } ) . future < IPluginData [ ] > ( ) ( ) ;
250
+ }
251
+ } ) ;
252
+ testInjector . register ( "fs" , FileSystem ) ;
253
+ testInjector . register ( "projectDataService" , ProjectDataServiceLib . ProjectDataService ) ;
254
+ testInjector . register ( "options" , Options ) ;
255
+ testInjector . register ( "hostInfo" , HostInfo ) ;
256
+ testInjector . register ( "childProcess" , ChildProcess ) ;
184
257
185
258
return testInjector ;
186
259
}
0 commit comments