-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathplatform-command-helper.ts
107 lines (90 loc) · 3.1 KB
/
platform-command-helper.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import { assert } from "chai";
import * as _ from "lodash";
import { InjectorStub, TempServiceStub } from "../stubs";
import { MobileHelper } from "../../lib/common/mobile/mobile-helper";
import { DevicePlatformsConstants } from "../../lib/common/mobile/device-platforms-constants";
import { PlatformCommandHelper } from "../../lib/helpers/platform-command-helper";
import { IPlatformCommandHelper } from "../../lib/declarations";
import { IInjector } from "../../lib/common/definitions/yok";
let isAddPlatformCalled = false;
const projectDir = "/my/path/to/project";
const projectData: any = {
projectDir,
platformsDir: "/my/path/to/project/platforms",
};
function createTestInjector() {
const injector = new InjectorStub();
injector.register("addPlatformService", {
addPlatform: () => ({}),
});
injector.register("platformController", {
addPlatform: () => (isAddPlatformCalled = true),
});
injector.register("pacoteService", {
extractPackage: () => ({}),
});
injector.register("platformValidationService", {
validatePlatform: () => ({}),
validatePlatformInstalled: () => ({}),
});
injector.register("platformCommandHelper", PlatformCommandHelper);
injector.register("mobileHelper", MobileHelper);
injector.register("devicePlatformsConstants", DevicePlatformsConstants);
injector.register("tempService", TempServiceStub);
return injector;
}
describe("PlatformCommandHelper", () => {
let injector: IInjector = null;
let platformCommandHelper: IPlatformCommandHelper = null;
beforeEach(() => {
injector = createTestInjector();
platformCommandHelper = injector.resolve("platformCommandHelper");
});
describe("add platforms unit tests", () => {
_.each(
["Android", "ANDROID", "android", "iOS", "IOS", "ios"],
(platform) => {
beforeEach(() => {
isAddPlatformCalled = false;
});
it(`should not fail if platform is not normalized - ${platform}`, async () => {
const fs = injector.resolve("fs");
fs.exists = () => false;
await platformCommandHelper.addPlatforms(
[platform],
projectData,
null
);
assert.isTrue(isAddPlatformCalled);
});
}
);
_.each(["ios", "android"], (platform) => {
it(`should fail if ${platform} platform is already installed`, async () => {
(<any>platformCommandHelper).isPlatformAdded = () => true;
await assert.isRejected(
platformCommandHelper.addPlatforms([platform], projectData, ""),
`Platform ${platform} already added`
);
});
});
});
describe("clean platforms unit tests", () => {
_.each(["ios", "anroid"], (platform) => {
it(`should preserve the specified in the project nativescript version for ${platform}`, async () => {
let versionData = { version: "5.3.1" };
const projectDataService = injector.resolve("projectDataService");
projectDataService.getNSValue = () => versionData;
projectDataService.removeNSProperty = () => {
versionData = null;
};
(<any>platformCommandHelper).isPlatformAdded = () => false;
await platformCommandHelper.cleanPlatforms(
[platform],
injector.resolve("projectData"),
""
);
});
});
});
});