Skip to content

Commit a57e2e9

Browse files
committed
Add 'sandbox-pod' command. Implement test.
1 parent d241c49 commit a57e2e9

File tree

4 files changed

+39
-14
lines changed

4 files changed

+39
-14
lines changed

config/config.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
"PROXY_HOSTNAME": "127.0.0.1",
66
"TYPESCRIPT_COMPILER_OPTIONS": {},
77
"CI_LOGGER": false,
8-
"ANDROID_DEBUG_UI_MAC": "Google Chrome"
8+
"ANDROID_DEBUG_UI_MAC": "Google Chrome",
9+
"USE_POD_SANDBOX": true
910
}

lib/declarations.ts

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ interface IStaticConfig extends Config.IStaticConfig { }
3636

3737
interface IConfiguration extends Config.IConfig {
3838
ANDROID_DEBUG_UI: string;
39+
USE_POD_SANDBOX: boolean;
3940
}
4041

4142
interface IApplicationPackage {

lib/services/ios-project-service.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
3232
private $options: IOptions,
3333
private $injector: IInjector,
3434
$projectDataService: IProjectDataService,
35-
private $prompter: IPrompter) {
35+
private $prompter: IPrompter,
36+
private $config: Config.IConfig) {
3637
super($fs, $projectData, $projectDataService);
3738
}
3839

@@ -495,7 +496,8 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
495496

496497
private executePodInstall(): IFuture<any> {
497498
this.$logger.info("Installing pods...");
498-
return this.$childProcess.spawnFromEvent("pod", ["install"], "close", { cwd: this.platformData.projectRoot, stdio: 'inherit' });
499+
let podTool = this.$config.USE_POD_SANDBOX ? "sandbox-pod" : "pod";
500+
return this.$childProcess.spawnFromEvent(podTool, ["install"], "close", { cwd: this.platformData.projectRoot, stdio: 'inherit' });
499501
}
500502

501503
private prepareFrameworks(pluginPlatformsFolderPath: string, pluginData: IPluginData): IFuture<void> {

test/project-service.ts

+32-11
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,20 @@ class ProjectIntegrationTest {
3939
return projectService.createProject(projectName);
4040
}
4141

42-
public getDefaultTemplatePath(): IFuture<string> {
42+
public getDefaultTemplatePath(templateName: string): IFuture<string> {
4343
return (() => {
4444
let npmInstallationManager = this.testInjector.resolve("npmInstallationManager");
4545
let fs = this.testInjector.resolve("fs");
4646

47-
let defaultTemplatePackageName = "tns-template-hello-world";
4847
let cacheRoot = npmInstallationManager.getCacheRootPath();
49-
let defaultTemplatePath = path.join(cacheRoot, defaultTemplatePackageName);
50-
let latestVersion = npmInstallationManager.getLatestVersion(defaultTemplatePackageName).wait();
48+
let defaultTemplatePath = path.join(cacheRoot, templateName);
49+
let latestVersion = npmInstallationManager.getLatestVersion(templateName).wait();
5150

5251
if(!fs.exists(path.join(defaultTemplatePath, latestVersion)).wait()) {
53-
npmInstallationManager.addToCache(defaultTemplatePackageName, latestVersion).wait();
52+
npmInstallationManager.addToCache(templateName, latestVersion).wait();
5453
}
5554
if(!fs.exists(path.join(defaultTemplatePath, latestVersion, "package", "app")).wait()) {
56-
npmInstallationManager.cacheUnpack(defaultTemplatePackageName, latestVersion).wait();
55+
npmInstallationManager.cacheUnpack(templateName, latestVersion).wait();
5756
}
5857

5958
return path.join(defaultTemplatePath, latestVersion, "package");
@@ -118,7 +117,6 @@ class ProjectIntegrationTest {
118117
this.testInjector.register("npmInstallationManager", NpmInstallationManagerLib.NpmInstallationManager);
119118
this.testInjector.register("npm", NpmLib.NodePackageManager);
120119
this.testInjector.register("httpClient", HttpClientLib.HttpClient);
121-
this.testInjector.register("config", {});
122120
this.testInjector.register("lockfile", stubs.LockFile);
123121

124122
this.testInjector.register("options", optionsLib.Options);
@@ -135,7 +133,7 @@ describe("Project Service Tests", () => {
135133
let options = projectIntegrationTest.testInjector.resolve("options");
136134

137135
options.path = tempFolder;
138-
options.copyFrom = projectIntegrationTest.getDefaultTemplatePath().wait();
136+
options.copyFrom = projectIntegrationTest.getDefaultTemplatePath("tns-template-hello-world").wait();
139137

140138
projectIntegrationTest.createProject(projectName).wait();
141139
projectIntegrationTest.assertProject(tempFolder, projectName, "org.nativescript.myapp").wait();
@@ -147,12 +145,34 @@ describe("Project Service Tests", () => {
147145
let options = projectIntegrationTest.testInjector.resolve("options");
148146

149147
options.path = tempFolder;
150-
options.copyFrom = projectIntegrationTest.getDefaultTemplatePath().wait();
148+
options.copyFrom = projectIntegrationTest.getDefaultTemplatePath("tns-template-hello-world").wait();
151149
options.appid = "my.special.id";
152150

153151
projectIntegrationTest.createProject(projectName).wait();
154152
projectIntegrationTest.assertProject(tempFolder, projectName, options.appid).wait();
155153
});
154+
it("creates valid project and tests pod sandbox", () => {
155+
let testInjector = createTestInjector();
156+
let fs: IFileSystem = testInjector.resolve("fs");
157+
let config = testInjector.resolve("config");
158+
let childProcess = testInjector.resolve("childProcess");
159+
let projectIntegrationTest = new ProjectIntegrationTest();
160+
let workingFolderPath = temp.mkdirSync("ios_project");
161+
162+
let iosTemplatePath = path.join(projectIntegrationTest.getDefaultTemplatePath("tns-ios").wait(), "framework/");
163+
childProcess.exec(`cp -R ${iosTemplatePath} ${workingFolderPath}`, { cwd: workingFolderPath }).wait();
164+
fs.writeFile("/tmp/Podfile/testFile.txt", "Test content.").wait();
165+
166+
let postInstallCommmand = `\`cat /tmp/Podfile/testFile.txt > ${workingFolderPath}/copyTestFile.txt && rm -rf /tmp/Podfile\``;
167+
let podfileContent = `post_install do |installer_representation| ${postInstallCommmand} end`;
168+
fs.writeFile(path.join(workingFolderPath, "Podfile"), podfileContent).wait();
169+
170+
let podTool = config.USE_POD_SANDBOX ? "sandbox-pod" : "pod";
171+
childProcess.spawnFromEvent(podTool, ["install"], "close", { cwd: workingFolderPath, stdio: 'inherit' }).wait();
172+
173+
assert.isTrue(fs.exists("/tmp/Podfile").wait());
174+
assert.isTrue(fs.exists(path.join(workingFolderPath, "copyTestFile.txt")).wait());
175+
});
156176
});
157177
});
158178

@@ -164,7 +184,6 @@ function createTestInjector() {
164184
testInjector.register("projectService", ProjectServiceLib.ProjectService);
165185
testInjector.register("projectHelper", ProjectHelperLib.ProjectHelper);
166186
testInjector.register("projectTemplatesService", stubs.ProjectTemplatesService);
167-
testInjector.register("projectNameValidator", mockProjectNameValidator);
168187

169188
testInjector.register("fs", fsLib.FileSystem);
170189
testInjector.register("projectDataService", ProjectDataServiceLib.ProjectDataService);
@@ -173,7 +192,9 @@ function createTestInjector() {
173192

174193
testInjector.register("npmInstallationManager", NpmInstallationManagerLib.NpmInstallationManager);
175194
testInjector.register("httpClient", HttpClientLib.HttpClient);
176-
testInjector.register("config", {});
195+
testInjector.register("config", {
196+
"USE_POD_SANDBOX": true
197+
});
177198
testInjector.register("lockfile", stubs.LockFile);
178199

179200
testInjector.register("childProcess", ChildProcessLib.ChildProcess);

0 commit comments

Comments
 (0)