Skip to content

Add 'sandbox-pod' command. Implement test. #1052

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Oct 19, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
"PROXY_HOSTNAME": "127.0.0.1",
"TYPESCRIPT_COMPILER_OPTIONS": {},
"CI_LOGGER": false,
"ANDROID_DEBUG_UI_MAC": "Google Chrome"
"ANDROID_DEBUG_UI_MAC": "Google Chrome",
"USE_POD_SANDBOX": true
}
1 change: 1 addition & 0 deletions lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export class Configuration extends configBaseLib.ConfigBase implements IConfigur
TYPESCRIPT_COMPILER_OPTIONS = {};
USE_PROXY = false;
ANDROID_DEBUG_UI: string = null;
USE_POD_SANDBOX: boolean = true;

/*don't require logger and everything that has logger as dependency in config.js due to cyclic dependency*/
constructor(protected $fs: IFileSystem) {
Expand Down
1 change: 1 addition & 0 deletions lib/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ interface IStaticConfig extends Config.IStaticConfig { }

interface IConfiguration extends Config.IConfig {
ANDROID_DEBUG_UI: string;
USE_POD_SANDBOX: boolean;
}

interface IApplicationPackage {
Expand Down
6 changes: 4 additions & 2 deletions lib/services/ios-project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
private $options: IOptions,
private $injector: IInjector,
$projectDataService: IProjectDataService,
private $prompter: IPrompter) {
private $prompter: IPrompter,
private $config: IConfiguration) {
super($fs, $projectData, $projectDataService);
}

Expand Down Expand Up @@ -495,7 +496,8 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ

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

private prepareFrameworks(pluginPlatformsFolderPath: string, pluginData: IPluginData): IFuture<void> {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"main": "./lib/nativescript-cli.js",
"scripts": {
"test": "node_modules/.bin/istanbul cover node_modules/mocha/bin/_mocha -- --ui mocha-fibers --recursive --reporter spec --require test/test-bootstrap.js --timeout 60000 test/ lib/common/test/unit-tests",
"test": "node_modules/.bin/istanbul cover node_modules/mocha/bin/_mocha -- --ui mocha-fibers --recursive --reporter spec --require test/test-bootstrap.js --timeout 150000 test/ lib/common/test/unit-tests",
"postinstall": "node postinstall.js",
"preuninstall": "node preuninstall.js"
},
Expand Down
129 changes: 101 additions & 28 deletions test/project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,24 @@
import yok = require('../lib/common/yok');
import stubs = require('./stubs');
import * as constants from "./../lib/constants";
import * as ChildProcessLib from "../lib/common/child-process";
import {ChildProcess} from "../lib/common/child-process";
import * as ProjectServiceLib from "../lib/services/project-service";
import * as ProjectDataServiceLib from "../lib/services/project-data-service";
import * as ProjectDataLib from "../lib/project-data";
import * as ProjectHelperLib from "../lib/common/project-helper";
import * as StaticConfigLib from "../lib/config";
import {StaticConfig} from "../lib/config";
import * as NpmLib from "../lib/node-package-manager";
import * as NpmInstallationManagerLib from "../lib/npm-installation-manager";
import {NpmInstallationManager} from "../lib/npm-installation-manager";
import * as HttpClientLib from "../lib/common/http-client";
import * as fsLib from "../lib/common/file-system";
import {FileSystem} from "../lib/common/file-system";
import * as path from "path";
import temp = require("temp");
import * as helpers from "../lib/common/helpers";
import {assert} from "chai";
import * as optionsLib from "../lib/options";
import * as hostInfoLib from "../lib/common/host-info";
import {Options} from "../lib/options";
import {HostInfo} from "../lib/common/host-info";
import {IOSProjectService} from "../lib/services/ios-project-service";
import * as shell from "shelljs";

let mockProjectNameValidator = {
validate: () => { return true; }
Expand All @@ -39,21 +41,20 @@ class ProjectIntegrationTest {
return projectService.createProject(projectName);
}

public getDefaultTemplatePath(): IFuture<string> {
public getNpmPackagePath(packageName: string): IFuture<string> {
return (() => {
let npmInstallationManager = this.testInjector.resolve("npmInstallationManager");
let fs = this.testInjector.resolve("fs");

let defaultTemplatePackageName = "tns-template-hello-world";
let cacheRoot = npmInstallationManager.getCacheRootPath();
let defaultTemplatePath = path.join(cacheRoot, defaultTemplatePackageName);
let latestVersion = npmInstallationManager.getLatestVersion(defaultTemplatePackageName).wait();
let defaultTemplatePath = path.join(cacheRoot, packageName);
let latestVersion = npmInstallationManager.getLatestVersion(packageName).wait();

if(!fs.exists(path.join(defaultTemplatePath, latestVersion)).wait()) {
npmInstallationManager.addToCache(defaultTemplatePackageName, latestVersion).wait();
npmInstallationManager.addToCache(packageName, latestVersion).wait();
}
if(!fs.exists(path.join(defaultTemplatePath, latestVersion, "package", "app")).wait()) {
npmInstallationManager.cacheUnpack(defaultTemplatePackageName, latestVersion).wait();
npmInstallationManager.cacheUnpack(packageName, latestVersion).wait();
}

return path.join(defaultTemplatePath, latestVersion, "package");
Expand Down Expand Up @@ -103,26 +104,25 @@ class ProjectIntegrationTest {

private createTestInjector(): void {
this.testInjector = new yok.Yok();
this.testInjector.register("childProcess", ChildProcessLib.ChildProcess);
this.testInjector.register("childProcess", ChildProcess);
this.testInjector.register("errors", stubs.ErrorsStub);
this.testInjector.register('logger', stubs.LoggerStub);
this.testInjector.register("projectService", ProjectServiceLib.ProjectService);
this.testInjector.register("projectHelper", ProjectHelperLib.ProjectHelper);
this.testInjector.register("projectTemplatesService", stubs.ProjectTemplatesService);
this.testInjector.register("projectNameValidator", mockProjectNameValidator);

this.testInjector.register("fs", fsLib.FileSystem);
this.testInjector.register("fs", FileSystem);
this.testInjector.register("projectDataService", ProjectDataServiceLib.ProjectDataService);
this.testInjector.register("staticConfig", StaticConfigLib.StaticConfig);
this.testInjector.register("staticConfig", StaticConfig);

this.testInjector.register("npmInstallationManager", NpmInstallationManagerLib.NpmInstallationManager);
this.testInjector.register("npmInstallationManager", NpmInstallationManager);
this.testInjector.register("npm", NpmLib.NodePackageManager);
this.testInjector.register("httpClient", HttpClientLib.HttpClient);
this.testInjector.register("config", {});
this.testInjector.register("lockfile", stubs.LockFile);

this.testInjector.register("options", optionsLib.Options);
this.testInjector.register("hostInfo", hostInfoLib.HostInfo);
this.testInjector.register("options", Options);
this.testInjector.register("hostInfo", HostInfo);
}
}

Expand All @@ -135,7 +135,7 @@ describe("Project Service Tests", () => {
let options = projectIntegrationTest.testInjector.resolve("options");

options.path = tempFolder;
options.copyFrom = projectIntegrationTest.getDefaultTemplatePath().wait();
options.copyFrom = projectIntegrationTest.getNpmPackagePath("tns-template-hello-world").wait();

projectIntegrationTest.createProject(projectName).wait();
projectIntegrationTest.assertProject(tempFolder, projectName, "org.nativescript.myapp").wait();
Expand All @@ -147,12 +147,50 @@ describe("Project Service Tests", () => {
let options = projectIntegrationTest.testInjector.resolve("options");

options.path = tempFolder;
options.copyFrom = projectIntegrationTest.getDefaultTemplatePath().wait();
options.copyFrom = projectIntegrationTest.getNpmPackagePath("tns-template-hello-world").wait();
options.appid = "my.special.id";

projectIntegrationTest.createProject(projectName).wait();
projectIntegrationTest.assertProject(tempFolder, projectName, options.appid).wait();
});
it("creates ios project and tests post-install sandboxing of CocoaPods setup", () => {
if (require("os").platform() !== "darwin") {
console.log("Skipping CocoaPods sandbox test. It works only on darwin.");
return;
}

let testDirectoryPath = "/tmp/Podfile";
let testInjector = createInjectorForPodsTest();
let iOSProjectService: IPlatformProjectService = testInjector.resolve("iOSProjectService");
let fs: IFileSystem = testInjector.resolve("fs");
let projectIntegrationTest = new ProjectIntegrationTest();
let workingFolderPath = temp.mkdirSync("ios_project");
let iosTemplatePath = path.join(projectIntegrationTest.getNpmPackagePath("tns-ios").wait(), "framework/");
let postInstallCommmand = `\`cat ${testDirectoryPath}/testFile.txt > ${workingFolderPath}/copyTestFile.txt && rm -rf ${testDirectoryPath}\``;
let podfileContent = `post_install do |installer_representation| ${postInstallCommmand} end`;
let platformData = iOSProjectService.platformData;

shell.cp("-R", iosTemplatePath, workingFolderPath);

fs.writeFile(`${testDirectoryPath}/testFile.txt`, "Test content.").wait();
fs.writeFile(path.join(workingFolderPath, "Podfile"), podfileContent).wait();

Object.defineProperty(iOSProjectService, "platformData", {
get: () => {
return { projectRoot: workingFolderPath };
}
});

try {
iOSProjectService.afterPrepareAllPlugins().wait();
} finally {
Object.defineProperty(iOSProjectService, "platformData", platformData);
}

assert.isTrue(fs.exists(testDirectoryPath).wait());
assert.isTrue(fs.exists(path.join(workingFolderPath, "copyTestFile.txt")).wait());
fs.deleteDirectory(testDirectoryPath).wait(); // Clean up 'tmp' after test ends.
});
});
});

Expand All @@ -166,21 +204,56 @@ function createTestInjector() {
testInjector.register("projectTemplatesService", stubs.ProjectTemplatesService);
testInjector.register("projectNameValidator", mockProjectNameValidator);

testInjector.register("fs", fsLib.FileSystem);
testInjector.register("fs", FileSystem);
testInjector.register("projectDataService", ProjectDataServiceLib.ProjectDataService);

testInjector.register("staticConfig", StaticConfigLib.StaticConfig);
testInjector.register("staticConfig", StaticConfig);

testInjector.register("npmInstallationManager", NpmInstallationManagerLib.NpmInstallationManager);
testInjector.register("npmInstallationManager", NpmInstallationManager);
testInjector.register("httpClient", HttpClientLib.HttpClient);
testInjector.register("config", {});
testInjector.register("lockfile", stubs.LockFile);

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

testInjector.register('projectData', ProjectDataLib.ProjectData);
testInjector.register("options", optionsLib.Options);
testInjector.register("hostInfo", hostInfoLib.HostInfo);
testInjector.register("options", Options);
testInjector.register("hostInfo", HostInfo);

return testInjector;
}

function createInjectorForPodsTest() {
let testInjector = new yok.Yok();

testInjector.register("errors", stubs.ErrorsStub);
testInjector.register('logger', stubs.LoggerStub);
testInjector.register("projectHelper", {});
testInjector.register("projectData", {
projectName: "__PROJECT_NAME__",
platformsDir: ""
});
testInjector.register("iOSEmulatorServices", {});
testInjector.register("config", {
"USE_POD_SANDBOX": true
});
testInjector.register("prompter", {});
testInjector.register("fs", FileSystem);
testInjector.register("staticConfig", StaticConfig);
testInjector.register("npmInstallationManager", NpmInstallationManager);
testInjector.register("iOSProjectService", IOSProjectService);
testInjector.register("projectService", ProjectServiceLib.ProjectService);
testInjector.register("pluginsService", {
getAllInstalledPlugins: () => {
return (() => {
return <any>[];
}).future<IPluginData[]>()();
}
});
testInjector.register("fs", FileSystem);
testInjector.register("projectDataService", ProjectDataServiceLib.ProjectDataService);
testInjector.register("options", Options);
testInjector.register("hostInfo", HostInfo);
testInjector.register("childProcess", ChildProcess);

return testInjector;
}
Expand Down