Skip to content

Commit 39a3bec

Browse files
committed
Change import statements. Code cleanup. Use shelljs.
1 parent 64c6f0b commit 39a3bec

File tree

1 file changed

+35
-31
lines changed

1 file changed

+35
-31
lines changed

test/project-service.ts

+35-31
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,19 @@ 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";
1111
import * as ProjectHelperLib from "../lib/common/project-helper";
12-
import * as StaticConfigLib from "../lib/config";
12+
import {StaticConfig} from "../lib/config";
1313
import * as NpmLib from "../lib/node-package-manager";
14-
import * as NpmInstallationManagerLib from "../lib/npm-installation-manager";
14+
import {NpmInstallationManager} from "../lib/npm-installation-manager";
1515
import * as HttpClientLib from "../lib/common/http-client";
16-
import * as fsLib from "../lib/common/file-system";
16+
import {FileSystem} from "../lib/common/file-system";
1717
import * as path from "path";
1818
import temp = require("temp");
1919
import * as helpers from "../lib/common/helpers";
2020
import {assert} from "chai";
21-
import * as optionsLib from "../lib/options";
22-
import * as hostInfoLib from "../lib/common/host-info";
23-
import iOSProjectServiceLib = require("../lib/services/ios-project-service");
21+
import {Options} from "../lib/options";
22+
import {HostInfo} from "../lib/common/host-info";
23+
import {IOSProjectService} from "../lib/services/ios-project-service";
24+
import * as shell from "shelljs";
2425

2526
let mockProjectNameValidator = {
2627
validate: () => { return true; }
@@ -111,17 +112,17 @@ class ProjectIntegrationTest {
111112
this.testInjector.register("projectTemplatesService", stubs.ProjectTemplatesService);
112113
this.testInjector.register("projectNameValidator", mockProjectNameValidator);
113114

114-
this.testInjector.register("fs", fsLib.FileSystem);
115+
this.testInjector.register("fs", FileSystem);
115116
this.testInjector.register("projectDataService", ProjectDataServiceLib.ProjectDataService);
116-
this.testInjector.register("staticConfig", StaticConfigLib.StaticConfig);
117+
this.testInjector.register("staticConfig", StaticConfig);
117118

118-
this.testInjector.register("npmInstallationManager", NpmInstallationManagerLib.NpmInstallationManager);
119+
this.testInjector.register("npmInstallationManager", NpmInstallationManager);
119120
this.testInjector.register("npm", NpmLib.NodePackageManager);
120121
this.testInjector.register("httpClient", HttpClientLib.HttpClient);
121122
this.testInjector.register("lockfile", stubs.LockFile);
122123

123-
this.testInjector.register("options", optionsLib.Options);
124-
this.testInjector.register("hostInfo", hostInfoLib.HostInfo);
124+
this.testInjector.register("options", Options);
125+
this.testInjector.register("hostInfo", HostInfo);
125126
}
126127
}
127128

@@ -158,19 +159,19 @@ describe("Project Service Tests", () => {
158159
return;
159160
}
160161

162+
let testDirectoryPath = "/tmp/Podfile";
161163
let testInjector = createInjectorForPodsTest();
162164

163165
let iOSProjectService: IPlatformProjectService = testInjector.resolve("iOSProjectService");
164166
let fs: IFileSystem = testInjector.resolve("fs");
165-
let childProcess = testInjector.resolve("childProcess");
166167
let projectIntegrationTest = new ProjectIntegrationTest();
167168
let workingFolderPath = temp.mkdirSync("ios_project");
168169

169170
let iosTemplatePath = path.join(projectIntegrationTest.getNpmPackagePath("tns-ios").wait(), "framework/");
170-
childProcess.exec(`cp -R ${iosTemplatePath} ${workingFolderPath}`, { cwd: workingFolderPath }).wait();
171-
fs.writeFile("/tmp/Podfile/testFile.txt", "Test content.").wait();
171+
shell.cp("-R", iosTemplatePath, workingFolderPath);
172+
fs.writeFile(`${testDirectoryPath}/testFile.txt`, "Test content.").wait();
172173

173-
let postInstallCommmand = `\`cat /tmp/Podfile/testFile.txt > ${workingFolderPath}/copyTestFile.txt && rm -rf /tmp/Podfile\``;
174+
let postInstallCommmand = `\`cat ${testDirectoryPath}/testFile.txt > ${workingFolderPath}/copyTestFile.txt && rm -rf ${testDirectoryPath}\``;
174175
let podfileContent = `post_install do |installer_representation| ${postInstallCommmand} end`;
175176
fs.writeFile(path.join(workingFolderPath, "Podfile"), podfileContent).wait();
176177

@@ -179,18 +180,17 @@ describe("Project Service Tests", () => {
179180
get: () => {
180181
return { projectRoot: workingFolderPath };
181182
}
182-
});
183+
});
183184

184185
try {
185186
iOSProjectService.afterPrepareAllPlugins().wait();
186-
} catch(e) {
187-
assert.isNotNull(e);
188187
} finally {
189-
Object.defineProperty(iOSProjectService, "platformData", platformData);
188+
Object.defineProperty(iOSProjectService, "platformData", platformData);
190189
}
191190

192-
assert.isTrue(fs.exists("/tmp/Podfile").wait());
191+
assert.isTrue(fs.exists(testDirectoryPath).wait());
193192
assert.isTrue(fs.exists(path.join(workingFolderPath, "copyTestFile.txt")).wait());
193+
fs.deleteDirectory(testDirectoryPath).wait(); // Clean up 'tmp' after test ends.
194194
});
195195
});
196196
});
@@ -205,20 +205,20 @@ function createTestInjector() {
205205
testInjector.register("projectTemplatesService", stubs.ProjectTemplatesService);
206206
testInjector.register("projectNameValidator", mockProjectNameValidator);
207207

208-
testInjector.register("fs", fsLib.FileSystem);
208+
testInjector.register("fs", FileSystem);
209209
testInjector.register("projectDataService", ProjectDataServiceLib.ProjectDataService);
210210

211-
testInjector.register("staticConfig", StaticConfigLib.StaticConfig);
211+
testInjector.register("staticConfig", StaticConfig);
212212

213-
testInjector.register("npmInstallationManager", NpmInstallationManagerLib.NpmInstallationManager);
213+
testInjector.register("npmInstallationManager", NpmInstallationManager);
214214
testInjector.register("httpClient", HttpClientLib.HttpClient);
215215
testInjector.register("lockfile", stubs.LockFile);
216216

217217
testInjector.register("childProcess", ChildProcess);
218218

219219
testInjector.register('projectData', ProjectDataLib.ProjectData);
220-
testInjector.register("options", optionsLib.Options);
221-
testInjector.register("hostInfo", hostInfoLib.HostInfo);
220+
testInjector.register("options", Options);
221+
testInjector.register("hostInfo", HostInfo);
222222

223223
return testInjector;
224224
}
@@ -239,13 +239,17 @@ function createInjectorForPodsTest() {
239239
"USE_POD_SANDBOX": true
240240
});
241241
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);
242+
testInjector.register("fs", FileSystem);
243+
testInjector.register("staticConfig", StaticConfig);
244+
testInjector.register("npmInstallationManager", NpmInstallationManager);
245+
testInjector.register("iOSProjectService", IOSProjectService);
246+
testInjector.register("projectService", ProjectServiceLib.ProjectService);
247+
testInjector.register("projectHelper", ProjectHelperLib.ProjectHelper);
248+
testInjector.register("projectTemplatesService", stubs.ProjectTemplatesService);
249+
testInjector.register("projectNameValidator", mockProjectNameValidator);
250+
testInjector.register("options", Options);
251+
testInjector.register("hostInfo", HostInfo);
246252
testInjector.register("childProcess", ChildProcess);
247-
testInjector.register("options", optionsLib.Options);
248-
testInjector.register("hostInfo", hostInfoLib.HostInfo);
249253

250254
return testInjector;
251255
}

0 commit comments

Comments
 (0)