-
-
Notifications
You must be signed in to change notification settings - Fork 197
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
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b6b80de
Add 'sandbox-pod' command. Implement test.
e2l3n c7bf25a
Fix incorrect spacing.
e2l3n 5bcca4c
Add OS check.
e2l3n a4da96c
Create new test injector. Mock 'iOSProjectService' and improve integr…
e2l3n 64c6f0b
Change method name.
e2l3n 39a3bec
Change import statements. Code cleanup. Use shelljs.
e2l3n 437baab
Increase timeout to 15 000 ms.
e2l3n a2dfd7d
Change test injector constructor.
e2l3n 20f4b26
Reorder declarations.
e2l3n File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; } | ||
|
@@ -39,21 +40,20 @@ class ProjectIntegrationTest { | |
return projectService.createProject(projectName); | ||
} | ||
|
||
public getDefaultTemplatePath(): IFuture<string> { | ||
public getDefaultTemplatePath(templateName: 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, 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"); | ||
|
@@ -103,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); | ||
|
@@ -118,7 +118,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 +134,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 +146,52 @@ 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 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 = 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.getDefaultTemplatePath("tns-ios").wait(), "framework/"); | ||
childProcess.exec(`cp -R ${iosTemplatePath} ${workingFolderPath}`, { cwd: workingFolderPath }).wait(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should use either $fs or shelljs |
||
fs.writeFile("/tmp/Podfile/testFile.txt", "Test content.").wait(); | ||
|
||
let postInstallCommmand = `\`cat /tmp/Podfile/testFile.txt > ${workingFolderPath}/copyTestFile.txt && rm -rf /tmp/Podfile\``; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. magic constant used more than once - consider making it a symbol |
||
let podfileContent = `post_install do |installer_representation| ${postInstallCommmand} end`; | ||
fs.writeFile(path.join(workingFolderPath, "Podfile"), podfileContent).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()); | ||
}); | ||
}); | ||
}); | ||
|
||
|
@@ -173,10 +212,9 @@ function createTestInjector() { | |
|
||
testInjector.register("npmInstallationManager", NpmInstallationManagerLib.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); | ||
|
@@ -185,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(); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function should be renamed for example
getNpmPackagePath(packageName: string)