Skip to content

Commit a4da96c

Browse files
committed
Create new test injector. Mock 'iOSProjectService' and improve integration test.
1 parent 5bcca4c commit a4da96c

File tree

1 file changed

+49
-10
lines changed

1 file changed

+49
-10
lines changed

test/project-service.ts

+49-10
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import yok = require('../lib/common/yok');
55
import stubs = require('./stubs');
66
import * as constants from "./../lib/constants";
7-
import * as ChildProcessLib from "../lib/common/child-process";
7+
import {ChildProcess} from "../lib/common/child-process";
88
import * as ProjectServiceLib from "../lib/services/project-service";
99
import * as ProjectDataServiceLib from "../lib/services/project-data-service";
1010
import * as ProjectDataLib from "../lib/project-data";
@@ -20,6 +20,7 @@ import * as helpers from "../lib/common/helpers";
2020
import {assert} from "chai";
2121
import * as optionsLib from "../lib/options";
2222
import * as hostInfoLib from "../lib/common/host-info";
23+
import iOSProjectServiceLib = require("../lib/services/ios-project-service");
2324

2425
let mockProjectNameValidator = {
2526
validate: () => { return true; }
@@ -102,7 +103,7 @@ class ProjectIntegrationTest {
102103

103104
private createTestInjector(): void {
104105
this.testInjector = new yok.Yok();
105-
this.testInjector.register("childProcess", ChildProcessLib.ChildProcess);
106+
this.testInjector.register("childProcess", ChildProcess);
106107
this.testInjector.register("errors", stubs.ErrorsStub);
107108
this.testInjector.register('logger', stubs.LoggerStub);
108109
this.testInjector.register("projectService", ProjectServiceLib.ProjectService);
@@ -157,9 +158,10 @@ describe("Project Service Tests", () => {
157158
return;
158159
}
159160

160-
let testInjector = createTestInjector();
161+
let testInjector = createInjectorForPodsTest();
162+
163+
let iOSProjectService: IPlatformProjectService = testInjector.resolve("iOSProjectService");
161164
let fs: IFileSystem = testInjector.resolve("fs");
162-
let config = testInjector.resolve("config");
163165
let childProcess = testInjector.resolve("childProcess");
164166
let projectIntegrationTest = new ProjectIntegrationTest();
165167
let workingFolderPath = temp.mkdirSync("ios_project");
@@ -172,8 +174,20 @@ describe("Project Service Tests", () => {
172174
let podfileContent = `post_install do |installer_representation| ${postInstallCommmand} end`;
173175
fs.writeFile(path.join(workingFolderPath, "Podfile"), podfileContent).wait();
174176

175-
let podTool = config.USE_POD_SANDBOX ? "sandbox-pod" : "pod";
176-
childProcess.spawnFromEvent(podTool, ["install"], "close", { cwd: workingFolderPath, stdio: 'inherit' }).wait();
177+
let platformData = iOSProjectService.platformData;
178+
Object.defineProperty(iOSProjectService, "platformData", {
179+
get: () => {
180+
return { projectRoot: workingFolderPath };
181+
}
182+
});
183+
184+
try {
185+
iOSProjectService.afterPrepareAllPlugins().wait();
186+
} catch(e) {
187+
assert.isNotNull(e);
188+
} finally {
189+
Object.defineProperty(iOSProjectService, "platformData", platformData);
190+
}
177191

178192
assert.isTrue(fs.exists("/tmp/Podfile").wait());
179193
assert.isTrue(fs.exists(path.join(workingFolderPath, "copyTestFile.txt")).wait());
@@ -189,6 +203,7 @@ function createTestInjector() {
189203
testInjector.register("projectService", ProjectServiceLib.ProjectService);
190204
testInjector.register("projectHelper", ProjectHelperLib.ProjectHelper);
191205
testInjector.register("projectTemplatesService", stubs.ProjectTemplatesService);
206+
testInjector.register("projectNameValidator", mockProjectNameValidator);
192207

193208
testInjector.register("fs", fsLib.FileSystem);
194209
testInjector.register("projectDataService", ProjectDataServiceLib.ProjectDataService);
@@ -197,12 +212,9 @@ function createTestInjector() {
197212

198213
testInjector.register("npmInstallationManager", NpmInstallationManagerLib.NpmInstallationManager);
199214
testInjector.register("httpClient", HttpClientLib.HttpClient);
200-
testInjector.register("config", {
201-
"USE_POD_SANDBOX": true
202-
});
203215
testInjector.register("lockfile", stubs.LockFile);
204216

205-
testInjector.register("childProcess", ChildProcessLib.ChildProcess);
217+
testInjector.register("childProcess", ChildProcess);
206218

207219
testInjector.register('projectData', ProjectDataLib.ProjectData);
208220
testInjector.register("options", optionsLib.Options);
@@ -211,6 +223,33 @@ function createTestInjector() {
211223
return testInjector;
212224
}
213225

226+
function createInjectorForPodsTest() {
227+
let testInjector = new yok.Yok();
228+
229+
testInjector.register("errors", stubs.ErrorsStub);
230+
testInjector.register('logger', stubs.LoggerStub);
231+
testInjector.register("projectHelper", {});
232+
testInjector.register("projectData", {
233+
projectName: "__PROJECT_NAME__",
234+
platformsDir: ""
235+
});
236+
testInjector.register("projectDataService", {});
237+
testInjector.register("iOSEmulatorServices", {});
238+
testInjector.register("config", {
239+
"USE_POD_SANDBOX": true
240+
});
241+
testInjector.register("prompter", {});
242+
testInjector.register("fs", fsLib.FileSystem);
243+
testInjector.register("staticConfig", StaticConfigLib.StaticConfig);
244+
testInjector.register("npmInstallationManager", NpmInstallationManagerLib.NpmInstallationManager);
245+
testInjector.register("iOSProjectService", iOSProjectServiceLib.IOSProjectService);
246+
testInjector.register("childProcess", ChildProcess);
247+
testInjector.register("options", optionsLib.Options);
248+
testInjector.register("hostInfo", hostInfoLib.HostInfo);
249+
250+
return testInjector;
251+
}
252+
214253
describe("project upgrade procedure tests", () => {
215254
it("should throw error when no nativescript project folder specified", () => {
216255
let testInjector = createTestInjector();

0 commit comments

Comments
 (0)