From b6b80de09a427a6970163e1e412aa85f3df2af40 Mon Sep 17 00:00:00 2001 From: Toma Popov Date: Fri, 9 Oct 2015 20:59:26 +0300 Subject: [PATCH 1/9] Add 'sandbox-pod' command. Implement test. --- config/config.json | 3 +- lib/config.ts | 1 + lib/declarations.ts | 1 + lib/services/ios-project-service.ts | 6 ++-- test/project-service.ts | 43 +++++++++++++++++++++-------- 5 files changed, 40 insertions(+), 14 deletions(-) diff --git a/config/config.json b/config/config.json index 10054dee4b..2eae139f10 100644 --- a/config/config.json +++ b/config/config.json @@ -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 } \ No newline at end of file diff --git a/lib/config.ts b/lib/config.ts index f11fcf3d25..7c619c2315 100644 --- a/lib/config.ts +++ b/lib/config.ts @@ -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) { diff --git a/lib/declarations.ts b/lib/declarations.ts index 0d6579ddd5..2d259f8d1e 100644 --- a/lib/declarations.ts +++ b/lib/declarations.ts @@ -36,6 +36,7 @@ interface IStaticConfig extends Config.IStaticConfig { } interface IConfiguration extends Config.IConfig { ANDROID_DEBUG_UI: string; + USE_POD_SANDBOX: boolean; } interface IApplicationPackage { diff --git a/lib/services/ios-project-service.ts b/lib/services/ios-project-service.ts index e26a1a3aed..25b95344b3 100644 --- a/lib/services/ios-project-service.ts +++ b/lib/services/ios-project-service.ts @@ -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); } @@ -495,7 +496,8 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ private executePodInstall(): IFuture { 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 { diff --git a/test/project-service.ts b/test/project-service.ts index 682ab35749..cae4b10ee4 100644 --- a/test/project-service.ts +++ b/test/project-service.ts @@ -39,21 +39,20 @@ class ProjectIntegrationTest { return projectService.createProject(projectName); } - public getDefaultTemplatePath(): IFuture { + public getDefaultTemplatePath(templateName: string): IFuture { 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, templateName); + let latestVersion = npmInstallationManager.getLatestVersion(templateName).wait(); if(!fs.exists(path.join(defaultTemplatePath, latestVersion)).wait()) { - npmInstallationManager.addToCache(defaultTemplatePackageName, latestVersion).wait(); + npmInstallationManager.addToCache(templateName, latestVersion).wait(); } if(!fs.exists(path.join(defaultTemplatePath, latestVersion, "package", "app")).wait()) { - npmInstallationManager.cacheUnpack(defaultTemplatePackageName, latestVersion).wait(); + npmInstallationManager.cacheUnpack(templateName, latestVersion).wait(); } return path.join(defaultTemplatePath, latestVersion, "package"); @@ -118,7 +117,6 @@ class ProjectIntegrationTest { this.testInjector.register("npmInstallationManager", NpmInstallationManagerLib.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); @@ -135,7 +133,7 @@ describe("Project Service Tests", () => { let options = projectIntegrationTest.testInjector.resolve("options"); options.path = tempFolder; - options.copyFrom = projectIntegrationTest.getDefaultTemplatePath().wait(); + options.copyFrom = projectIntegrationTest.getDefaultTemplatePath("tns-template-hello-world").wait(); projectIntegrationTest.createProject(projectName).wait(); projectIntegrationTest.assertProject(tempFolder, projectName, "org.nativescript.myapp").wait(); @@ -147,12 +145,34 @@ describe("Project Service Tests", () => { let options = projectIntegrationTest.testInjector.resolve("options"); options.path = tempFolder; - options.copyFrom = projectIntegrationTest.getDefaultTemplatePath().wait(); + options.copyFrom = projectIntegrationTest.getDefaultTemplatePath("tns-template-hello-world").wait(); options.appid = "my.special.id"; projectIntegrationTest.createProject(projectName).wait(); projectIntegrationTest.assertProject(tempFolder, projectName, options.appid).wait(); }); + it("creates valid project and tests pod sandbox", () => { + let testInjector = createTestInjector(); + let fs: IFileSystem = testInjector.resolve("fs"); + let config = testInjector.resolve("config"); + let childProcess = testInjector.resolve("childProcess"); + let projectIntegrationTest = new ProjectIntegrationTest(); + let workingFolderPath = temp.mkdirSync("ios_project"); + + let iosTemplatePath = path.join(projectIntegrationTest.getDefaultTemplatePath("tns-ios").wait(), "framework/"); + childProcess.exec(`cp -R ${iosTemplatePath} ${workingFolderPath}`, { cwd: workingFolderPath }).wait(); + fs.writeFile("/tmp/Podfile/testFile.txt", "Test content.").wait(); + + let postInstallCommmand = `\`cat /tmp/Podfile/testFile.txt > ${workingFolderPath}/copyTestFile.txt && rm -rf /tmp/Podfile\``; + let podfileContent = `post_install do |installer_representation| ${postInstallCommmand} end`; + fs.writeFile(path.join(workingFolderPath, "Podfile"), podfileContent).wait(); + + let podTool = config.USE_POD_SANDBOX ? "sandbox-pod" : "pod"; + childProcess.spawnFromEvent(podTool, ["install"], "close", { cwd: workingFolderPath, stdio: 'inherit' }).wait(); + + assert.isTrue(fs.exists("/tmp/Podfile").wait()); + assert.isTrue(fs.exists(path.join(workingFolderPath, "copyTestFile.txt")).wait()); + }); }); }); @@ -164,7 +184,6 @@ function createTestInjector() { testInjector.register("projectService", ProjectServiceLib.ProjectService); testInjector.register("projectHelper", ProjectHelperLib.ProjectHelper); testInjector.register("projectTemplatesService", stubs.ProjectTemplatesService); - testInjector.register("projectNameValidator", mockProjectNameValidator); testInjector.register("fs", fsLib.FileSystem); testInjector.register("projectDataService", ProjectDataServiceLib.ProjectDataService); @@ -173,7 +192,9 @@ function createTestInjector() { testInjector.register("npmInstallationManager", NpmInstallationManagerLib.NpmInstallationManager); testInjector.register("httpClient", HttpClientLib.HttpClient); - testInjector.register("config", {}); + testInjector.register("config", { + "USE_POD_SANDBOX": true + }); testInjector.register("lockfile", stubs.LockFile); testInjector.register("childProcess", ChildProcessLib.ChildProcess); From c7bf25a77077277c74fe4e77df8875ffa8bb73df Mon Sep 17 00:00:00 2001 From: Toma Popov Date: Wed, 14 Oct 2015 16:40:22 +0300 Subject: [PATCH 2/9] Fix incorrect spacing. --- test/project-service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/project-service.ts b/test/project-service.ts index cae4b10ee4..6fa9f4aeee 100644 --- a/test/project-service.ts +++ b/test/project-service.ts @@ -156,7 +156,7 @@ describe("Project Service Tests", () => { let fs: IFileSystem = testInjector.resolve("fs"); let config = testInjector.resolve("config"); let childProcess = testInjector.resolve("childProcess"); - let projectIntegrationTest = new ProjectIntegrationTest(); + let projectIntegrationTest = new ProjectIntegrationTest(); let workingFolderPath = temp.mkdirSync("ios_project"); let iosTemplatePath = path.join(projectIntegrationTest.getDefaultTemplatePath("tns-ios").wait(), "framework/"); From 5bcca4ce4b81de39474318506121183648c47a8a Mon Sep 17 00:00:00 2001 From: Toma Popov Date: Wed, 14 Oct 2015 18:44:47 +0300 Subject: [PATCH 3/9] Add OS check. --- test/project-service.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/project-service.ts b/test/project-service.ts index 6fa9f4aeee..837bf13824 100644 --- a/test/project-service.ts +++ b/test/project-service.ts @@ -151,7 +151,12 @@ describe("Project Service Tests", () => { projectIntegrationTest.createProject(projectName).wait(); projectIntegrationTest.assertProject(tempFolder, projectName, options.appid).wait(); }); - it("creates valid project and tests pod sandbox", () => { + 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 testInjector = createTestInjector(); let fs: IFileSystem = testInjector.resolve("fs"); let config = testInjector.resolve("config"); From a4da96c71b9c9e215f25e98fdfa367f8c17525c9 Mon Sep 17 00:00:00 2001 From: Toma Popov Date: Thu, 15 Oct 2015 16:29:34 +0300 Subject: [PATCH 4/9] Create new test injector. Mock 'iOSProjectService' and improve integration test. --- test/project-service.ts | 59 ++++++++++++++++++++++++++++++++++------- 1 file changed, 49 insertions(+), 10 deletions(-) diff --git a/test/project-service.ts b/test/project-service.ts index 837bf13824..ddb12947e0 100644 --- a/test/project-service.ts +++ b/test/project-service.ts @@ -4,7 +4,7 @@ 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"; @@ -20,6 +20,7 @@ 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 iOSProjectServiceLib = require("../lib/services/ios-project-service"); let mockProjectNameValidator = { validate: () => { return true; } @@ -102,7 +103,7 @@ 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); @@ -157,9 +158,10 @@ describe("Project Service Tests", () => { return; } - let testInjector = createTestInjector(); + let testInjector = createInjectorForPodsTest(); + + let iOSProjectService: IPlatformProjectService = testInjector.resolve("iOSProjectService"); let fs: IFileSystem = testInjector.resolve("fs"); - let config = testInjector.resolve("config"); let childProcess = testInjector.resolve("childProcess"); let projectIntegrationTest = new ProjectIntegrationTest(); let workingFolderPath = temp.mkdirSync("ios_project"); @@ -172,8 +174,20 @@ describe("Project Service Tests", () => { let podfileContent = `post_install do |installer_representation| ${postInstallCommmand} end`; fs.writeFile(path.join(workingFolderPath, "Podfile"), podfileContent).wait(); - let podTool = config.USE_POD_SANDBOX ? "sandbox-pod" : "pod"; - childProcess.spawnFromEvent(podTool, ["install"], "close", { cwd: workingFolderPath, stdio: 'inherit' }).wait(); + let platformData = iOSProjectService.platformData; + Object.defineProperty(iOSProjectService, "platformData", { + get: () => { + return { projectRoot: workingFolderPath }; + } + }); + + try { + iOSProjectService.afterPrepareAllPlugins().wait(); + } catch(e) { + assert.isNotNull(e); + } finally { + Object.defineProperty(iOSProjectService, "platformData", platformData); + } assert.isTrue(fs.exists("/tmp/Podfile").wait()); assert.isTrue(fs.exists(path.join(workingFolderPath, "copyTestFile.txt")).wait()); @@ -189,6 +203,7 @@ function createTestInjector() { testInjector.register("projectService", ProjectServiceLib.ProjectService); testInjector.register("projectHelper", ProjectHelperLib.ProjectHelper); testInjector.register("projectTemplatesService", stubs.ProjectTemplatesService); + testInjector.register("projectNameValidator", mockProjectNameValidator); testInjector.register("fs", fsLib.FileSystem); testInjector.register("projectDataService", ProjectDataServiceLib.ProjectDataService); @@ -197,12 +212,9 @@ function createTestInjector() { testInjector.register("npmInstallationManager", NpmInstallationManagerLib.NpmInstallationManager); testInjector.register("httpClient", HttpClientLib.HttpClient); - testInjector.register("config", { - "USE_POD_SANDBOX": true - }); testInjector.register("lockfile", stubs.LockFile); - testInjector.register("childProcess", ChildProcessLib.ChildProcess); + testInjector.register("childProcess", ChildProcess); testInjector.register('projectData', ProjectDataLib.ProjectData); testInjector.register("options", optionsLib.Options); @@ -211,6 +223,33 @@ function createTestInjector() { 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("projectDataService", {}); + testInjector.register("iOSEmulatorServices", {}); + testInjector.register("config", { + "USE_POD_SANDBOX": true + }); + testInjector.register("prompter", {}); + testInjector.register("fs", fsLib.FileSystem); + testInjector.register("staticConfig", StaticConfigLib.StaticConfig); + testInjector.register("npmInstallationManager", NpmInstallationManagerLib.NpmInstallationManager); + testInjector.register("iOSProjectService", iOSProjectServiceLib.IOSProjectService); + testInjector.register("childProcess", ChildProcess); + testInjector.register("options", optionsLib.Options); + testInjector.register("hostInfo", hostInfoLib.HostInfo); + + return testInjector; +} + describe("project upgrade procedure tests", () => { it("should throw error when no nativescript project folder specified", () => { let testInjector = createTestInjector(); From 64c6f0bb18d92b2db1de90d5a0108595aa5d1a93 Mon Sep 17 00:00:00 2001 From: Toma Popov Date: Thu, 15 Oct 2015 16:32:22 +0300 Subject: [PATCH 5/9] Change method name. --- test/project-service.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/project-service.ts b/test/project-service.ts index ddb12947e0..4757c42cf0 100644 --- a/test/project-service.ts +++ b/test/project-service.ts @@ -40,20 +40,20 @@ class ProjectIntegrationTest { return projectService.createProject(projectName); } - public getDefaultTemplatePath(templateName: string): IFuture { + public getNpmPackagePath(packageName: string): IFuture { return (() => { let npmInstallationManager = this.testInjector.resolve("npmInstallationManager"); let fs = this.testInjector.resolve("fs"); let cacheRoot = npmInstallationManager.getCacheRootPath(); - let defaultTemplatePath = path.join(cacheRoot, templateName); - let latestVersion = npmInstallationManager.getLatestVersion(templateName).wait(); + let defaultTemplatePath = path.join(cacheRoot, packageName); + let latestVersion = npmInstallationManager.getLatestVersion(packageName).wait(); if(!fs.exists(path.join(defaultTemplatePath, latestVersion)).wait()) { - npmInstallationManager.addToCache(templateName, latestVersion).wait(); + npmInstallationManager.addToCache(packageName, latestVersion).wait(); } if(!fs.exists(path.join(defaultTemplatePath, latestVersion, "package", "app")).wait()) { - npmInstallationManager.cacheUnpack(templateName, latestVersion).wait(); + npmInstallationManager.cacheUnpack(packageName, latestVersion).wait(); } return path.join(defaultTemplatePath, latestVersion, "package"); @@ -134,7 +134,7 @@ describe("Project Service Tests", () => { let options = projectIntegrationTest.testInjector.resolve("options"); options.path = tempFolder; - options.copyFrom = projectIntegrationTest.getDefaultTemplatePath("tns-template-hello-world").wait(); + options.copyFrom = projectIntegrationTest.getNpmPackagePath("tns-template-hello-world").wait(); projectIntegrationTest.createProject(projectName).wait(); projectIntegrationTest.assertProject(tempFolder, projectName, "org.nativescript.myapp").wait(); @@ -146,7 +146,7 @@ describe("Project Service Tests", () => { let options = projectIntegrationTest.testInjector.resolve("options"); options.path = tempFolder; - options.copyFrom = projectIntegrationTest.getDefaultTemplatePath("tns-template-hello-world").wait(); + options.copyFrom = projectIntegrationTest.getNpmPackagePath("tns-template-hello-world").wait(); options.appid = "my.special.id"; projectIntegrationTest.createProject(projectName).wait(); @@ -166,7 +166,7 @@ describe("Project Service Tests", () => { let projectIntegrationTest = new ProjectIntegrationTest(); let workingFolderPath = temp.mkdirSync("ios_project"); - let iosTemplatePath = path.join(projectIntegrationTest.getDefaultTemplatePath("tns-ios").wait(), "framework/"); + let iosTemplatePath = path.join(projectIntegrationTest.getNpmPackagePath("tns-ios").wait(), "framework/"); childProcess.exec(`cp -R ${iosTemplatePath} ${workingFolderPath}`, { cwd: workingFolderPath }).wait(); fs.writeFile("/tmp/Podfile/testFile.txt", "Test content.").wait(); From 39a3becf5351d5d729d138a80238c7a60539ad5a Mon Sep 17 00:00:00 2001 From: Toma Popov Date: Thu, 15 Oct 2015 17:13:56 +0300 Subject: [PATCH 6/9] Change import statements. Code cleanup. Use shelljs. --- test/project-service.ts | 66 ++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 31 deletions(-) diff --git a/test/project-service.ts b/test/project-service.ts index 4757c42cf0..85b60c5510 100644 --- a/test/project-service.ts +++ b/test/project-service.ts @@ -9,18 +9,19 @@ 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 iOSProjectServiceLib = require("../lib/services/ios-project-service"); +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; } @@ -111,17 +112,17 @@ class ProjectIntegrationTest { 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("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); } } @@ -158,19 +159,19 @@ describe("Project Service Tests", () => { return; } + let testDirectoryPath = "/tmp/Podfile"; let testInjector = createInjectorForPodsTest(); let iOSProjectService: IPlatformProjectService = testInjector.resolve("iOSProjectService"); let fs: IFileSystem = testInjector.resolve("fs"); - let childProcess = testInjector.resolve("childProcess"); let projectIntegrationTest = new ProjectIntegrationTest(); let workingFolderPath = temp.mkdirSync("ios_project"); let iosTemplatePath = path.join(projectIntegrationTest.getNpmPackagePath("tns-ios").wait(), "framework/"); - childProcess.exec(`cp -R ${iosTemplatePath} ${workingFolderPath}`, { cwd: workingFolderPath }).wait(); - fs.writeFile("/tmp/Podfile/testFile.txt", "Test content.").wait(); + shell.cp("-R", iosTemplatePath, workingFolderPath); + fs.writeFile(`${testDirectoryPath}/testFile.txt`, "Test content.").wait(); - let postInstallCommmand = `\`cat /tmp/Podfile/testFile.txt > ${workingFolderPath}/copyTestFile.txt && rm -rf /tmp/Podfile\``; + let postInstallCommmand = `\`cat ${testDirectoryPath}/testFile.txt > ${workingFolderPath}/copyTestFile.txt && rm -rf ${testDirectoryPath}\``; let podfileContent = `post_install do |installer_representation| ${postInstallCommmand} end`; fs.writeFile(path.join(workingFolderPath, "Podfile"), podfileContent).wait(); @@ -179,18 +180,17 @@ describe("Project Service Tests", () => { get: () => { return { projectRoot: workingFolderPath }; } - }); + }); try { iOSProjectService.afterPrepareAllPlugins().wait(); - } catch(e) { - assert.isNotNull(e); } finally { - Object.defineProperty(iOSProjectService, "platformData", platformData); + Object.defineProperty(iOSProjectService, "platformData", platformData); } - assert.isTrue(fs.exists("/tmp/Podfile").wait()); + 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. }); }); }); @@ -205,20 +205,20 @@ 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("lockfile", stubs.LockFile); 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; } @@ -239,13 +239,17 @@ function createInjectorForPodsTest() { "USE_POD_SANDBOX": true }); testInjector.register("prompter", {}); - testInjector.register("fs", fsLib.FileSystem); - testInjector.register("staticConfig", StaticConfigLib.StaticConfig); - testInjector.register("npmInstallationManager", NpmInstallationManagerLib.NpmInstallationManager); - testInjector.register("iOSProjectService", iOSProjectServiceLib.IOSProjectService); + testInjector.register("fs", FileSystem); + testInjector.register("staticConfig", StaticConfig); + testInjector.register("npmInstallationManager", NpmInstallationManager); + testInjector.register("iOSProjectService", IOSProjectService); + testInjector.register("projectService", ProjectServiceLib.ProjectService); + testInjector.register("projectHelper", ProjectHelperLib.ProjectHelper); + testInjector.register("projectTemplatesService", stubs.ProjectTemplatesService); + testInjector.register("projectNameValidator", mockProjectNameValidator); + testInjector.register("options", Options); + testInjector.register("hostInfo", HostInfo); testInjector.register("childProcess", ChildProcess); - testInjector.register("options", optionsLib.Options); - testInjector.register("hostInfo", hostInfoLib.HostInfo); return testInjector; } From 437baaba07fd47d8af8ad2d8fc70fdf719a8f605 Mon Sep 17 00:00:00 2001 From: Toma Popov Date: Fri, 16 Oct 2015 10:51:02 +0300 Subject: [PATCH 7/9] Increase timeout to 15 000 ms. --- package.json | 2 +- test/project-service.ts | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index e723379d9b..8b9d727a8e 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/test/project-service.ts b/test/project-service.ts index 85b60c5510..eda25a9d9a 100644 --- a/test/project-service.ts +++ b/test/project-service.ts @@ -244,7 +244,6 @@ function createInjectorForPodsTest() { testInjector.register("npmInstallationManager", NpmInstallationManager); testInjector.register("iOSProjectService", IOSProjectService); testInjector.register("projectService", ProjectServiceLib.ProjectService); - testInjector.register("projectHelper", ProjectHelperLib.ProjectHelper); testInjector.register("projectTemplatesService", stubs.ProjectTemplatesService); testInjector.register("projectNameValidator", mockProjectNameValidator); testInjector.register("options", Options); From a2dfd7ddf058deaa0bb25fb860dd1268b3efa02f Mon Sep 17 00:00:00 2001 From: Toma Popov Date: Fri, 16 Oct 2015 11:50:54 +0300 Subject: [PATCH 8/9] Change test injector constructor. --- test/project-service.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/test/project-service.ts b/test/project-service.ts index eda25a9d9a..fd749d489e 100644 --- a/test/project-service.ts +++ b/test/project-service.ts @@ -233,7 +233,6 @@ function createInjectorForPodsTest() { projectName: "__PROJECT_NAME__", platformsDir: "" }); - testInjector.register("projectDataService", {}); testInjector.register("iOSEmulatorServices", {}); testInjector.register("config", { "USE_POD_SANDBOX": true @@ -244,8 +243,15 @@ function createInjectorForPodsTest() { testInjector.register("npmInstallationManager", NpmInstallationManager); testInjector.register("iOSProjectService", IOSProjectService); testInjector.register("projectService", ProjectServiceLib.ProjectService); - testInjector.register("projectTemplatesService", stubs.ProjectTemplatesService); - testInjector.register("projectNameValidator", mockProjectNameValidator); + testInjector.register("pluginsService", { + getAllInstalledPlugins: () => { + return (() => { + return []; + }).future()(); + } + }); + testInjector.register("fs", FileSystem); + testInjector.register("projectDataService", ProjectDataServiceLib.ProjectDataService); testInjector.register("options", Options); testInjector.register("hostInfo", HostInfo); testInjector.register("childProcess", ChildProcess); From 20f4b2612a86c4ba2382c7d0ac7d9937ab328c4d Mon Sep 17 00:00:00 2001 From: Toma Popov Date: Mon, 19 Oct 2015 10:11:59 +0300 Subject: [PATCH 9/9] Reorder declarations. --- test/project-service.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/test/project-service.ts b/test/project-service.ts index fd749d489e..ae7d25f867 100644 --- a/test/project-service.ts +++ b/test/project-service.ts @@ -161,21 +161,20 @@ describe("Project Service Tests", () => { 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/"); - shell.cp("-R", iosTemplatePath, workingFolderPath); - fs.writeFile(`${testDirectoryPath}/testFile.txt`, "Test content.").wait(); - 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(); - let platformData = iOSProjectService.platformData; Object.defineProperty(iOSProjectService, "platformData", { get: () => { return { projectRoot: workingFolderPath };