Skip to content

Commit ef24226

Browse files
author
Dimitar Kerezov
committed
Add tests
1 parent 5425ca9 commit ef24226

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

test/platform-service.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as yok from "../lib/common/yok";
22
import * as stubs from "./stubs";
33
import * as PlatformServiceLib from "../lib/services/platform-service";
44
import * as StaticConfigLib from "../lib/config";
5+
import { VERSION_STRING } from "../lib/constants";
56
import * as fsLib from "../lib/common/file-system";
67
import * as optionsLib from "../lib/options";
78
import * as hostInfoLib from "../lib/common/host-info";
@@ -129,6 +130,45 @@ describe('Platform Service Tests', () => {
129130
assert.equal(errorMessage, err.message);
130131
}
131132
});
133+
it("should respect platform version in package.json's nativescript key", async () => {
134+
const versionString = "2.5.0";
135+
let fs = testInjector.resolve("fs");
136+
fs.exists = () => false;
137+
138+
let nsValueObject: any = {};
139+
nsValueObject[VERSION_STRING] = versionString;
140+
let projectDataService = testInjector.resolve("projectDataService");
141+
projectDataService.getNSValue = () => nsValueObject;
142+
143+
let npmInstallationManager = testInjector.resolve("npmInstallationManager");
144+
npmInstallationManager.install = (packageName: string, packageDir: string, options: INpmInstallOptions) => {
145+
assert.deepEqual(options.version, versionString);
146+
return "";
147+
};
148+
149+
let projectData: IProjectData = testInjector.resolve("projectData");
150+
151+
await platformService.addPlatforms(["android"], "", projectData, null);
152+
await platformService.addPlatforms(["ios"], "", projectData, null);
153+
});
154+
it("should install latest platform if no information found in package.json's nativescript key", async () => {
155+
let fs = testInjector.resolve("fs");
156+
fs.exists = () => false;
157+
158+
let projectDataService = testInjector.resolve("projectDataService");
159+
projectDataService.getNSValue = (): any => null;
160+
161+
let npmInstallationManager = testInjector.resolve("npmInstallationManager");
162+
npmInstallationManager.install = (packageName: string, packageDir: string, options: INpmInstallOptions) => {
163+
assert.deepEqual(options.version, undefined);
164+
return "";
165+
};
166+
167+
let projectData: IProjectData = testInjector.resolve("projectData");
168+
169+
await platformService.addPlatforms(["android"], "", projectData, null);
170+
await platformService.addPlatforms(["ios"], "", projectData, null);
171+
});
132172
});
133173
describe("#add platform(ios)", () => {
134174
it("should call validate method", async () => {
@@ -173,7 +213,7 @@ describe('Platform Service Tests', () => {
173213
});
174214

175215
describe("remove platform unit tests", () => {
176-
it("should fail when platforms are not added", async () => {
216+
it("should fail when platforms are not added", async () => {
177217
const ExpectedErrorsCaught = 2;
178218
let errorsCaught = 0;
179219
let projectData: IProjectData = testInjector.resolve("projectData");

0 commit comments

Comments
 (0)