GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — nativescript-cli/test/project-changes-service.ts at main · NativeScript/nativescript-cli Expand file tree/ Copy pathproject-changes-service.tsMore file actions 298 lines (269 loc) · 8.78 KB / Copy pathproject-changes-service.tsFile metadata and controls298 lines (269 loc) · 8.78 KB 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 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 import { BaseServiceTest } from "./base-service-test"; import { mkdtempSync } from "fs"; import { tmpdir } from "os"; import * as path from "path"; import * as _ from "lodash"; import { assert } from "chai"; import { PlatformsDataService } from "../lib/services/platforms-data-service"; import { ProjectChangesService } from "../lib/services/project-changes-service"; import * as Constants from "../lib/constants"; import { FileSystem } from "../lib/common/file-system"; import { HooksServiceStub, LoggerStub } from "./stubs"; import { IProjectData } from "../lib/definitions/project"; import { IPlatformData } from "../lib/definitions/platform"; import { IFileSystem } from "../lib/common/declarations"; import { IProjectChangesInfo, IPrepareInfo, } from "../lib/definitions/project-changes"; // start tracking temporary folders/files class ProjectChangesServiceTest extends BaseServiceTest { public projectDir: string; constructor() { super(); } initInjector(): void { this.projectDir = mkdtempSync(path.join(tmpdir(), "projectDir-")); this.injector.register("projectData", { projectDir: this.projectDir, }); this.injector.register("platformsDataService", PlatformsDataService); this.injector.register("androidProjectService", {}); this.injector.register("iOSProjectService", {}); this.injector.register("fs", FileSystem); this.injector.register("devicePlatformsConstants", {}); this.injector.register("devicePlatformsConstants", {}); this.injector.register("projectChangesService", ProjectChangesService); this.injector.register("filesHashService", { generateHashes: () => Promise.resolve({}), }); this.injector.register("logger", LoggerStub); this.injector.register("hooksService", HooksServiceStub); this.injector.register("nodeModulesDependenciesBuilder", {}); this.injector.register("options", {}); const fs = this.injector.resolve<IFileSystem>("fs"); fs.writeJson(path.join(this.projectDir, Constants.PACKAGE_JSON_FILE_NAME), { nativescript: { id: "org.nativescript.test", }, }); } get projectChangesService(): IProjectChangesService { return this.injector.resolve("projectChangesService"); } get projectData(): IProjectData { return this.injector.resolve("projectData"); } get getNativeProjectDataService(): any { return this.injector.resolve("platformsDataService"); } getPlatformData(platform: string): IPlatformData { return <any>{ projectRoot: path.join( this.projectDir, "platforms", platform.toLowerCase(), ), platformProjectService: { checkForChanges: async (changesInfo: IProjectChangesInfo) => { changesInfo.signingChanged = true; }, }, }; } } describe("Project Changes Service Tests", () => { let serviceTest: ProjectChangesServiceTest; beforeEach(() => { serviceTest = new ProjectChangesServiceTest(); const platformsDir = path.join( serviceTest.projectDir, Constants.PLATFORMS_DIR_NAME, ); serviceTest.getNativeProjectDataService.getPlatformData = ( platform: string, ) => { if (platform.toLowerCase() === "ios") { return { projectRoot: path.join(platformsDir, platform), get platformProjectService(): any { return { checkForChanges(changesInfo: IProjectChangesInfo): void { changesInfo.signingChanged = true; }, }; }, }; } else { return { projectRoot: path.join(platformsDir, platform), get platformProjectService(): any { return { checkForChanges(changesInfo: IProjectChangesInfo): void { /* no android changes */ }, }; }, }; } }; }); describe("Get Prepare Info File Path", () => { it("Gets the correct Prepare Info path for ios/android", () => { for (const platform of ["ios", "android"]) { const actualPrepareInfoPath = serviceTest.projectChangesService.getPrepareInfoFilePath( serviceTest.getPlatformData(platform), ); const expectedPrepareInfoPath = path.join( serviceTest.projectDir, Constants.PLATFORMS_DIR_NAME, platform, ".nsprepareinfo", ); assert.equal(actualPrepareInfoPath, expectedPrepareInfoPath); } }); }); describe("Get Prepare Info", () => { it("Returns empty if file path doesn't exists", () => { for (const platform of ["ios", "android"]) { const projectInfo = serviceTest.projectChangesService.getPrepareInfo( serviceTest.getPlatformData(platform), ); assert.isNull(projectInfo); } }); it("Reads the Prepare Info correctly", () => { const fs: FileSystem = serviceTest.resolve("fs"); for (const platform of ["ios", "android"]) { // arrange const prepareInfoPath = path.join( serviceTest.projectDir, Constants.PLATFORMS_DIR_NAME, platform, ".nsprepareinfo", ); const expectedPrepareInfo: IPrepareInfo = { time: new Date().toString(), bundle: true, release: false, changesRequireBuild: true, changesRequireBuildTime: new Date().toString(), iOSProvisioningProfileUUID: "provisioning_profile_test", projectFileHash: "", nativePlatformStatus: Constants.NativePlatformStatus.requiresPlatformAdd, appFilesHashes: {}, }; fs.writeJson(prepareInfoPath, expectedPrepareInfo); // act const actualPrepareInfo = serviceTest.projectChangesService.getPrepareInfo( serviceTest.getPlatformData(platform), ); // assert assert.deepStrictEqual(actualPrepareInfo, expectedPrepareInfo); } }); }); describe("Accumulates Changes From Project Services", () => { it("accumulates changes from the project service", async () => { const iOSChanges = await serviceTest.projectChangesService.checkForChanges( serviceTest.getPlatformData("ios"), serviceTest.projectData, <any>{ provision: undefined, teamId: undefined, }, ); assert.isTrue( !!iOSChanges.signingChanged, "iOS signingChanged expected to be true", ); }); }); describe("setNativePlatformStatus", () => { it("creates prepare info and sets only the native platform status when there isn't an existing prepare info", async () => { for (const platform of ["ios", "android"]) { await serviceTest.projectChangesService.setNativePlatformStatus( serviceTest.getPlatformData(platform), serviceTest.projectData, { nativePlatformStatus: Constants.NativePlatformStatus.requiresPrepare, }, ); const actualPrepareInfo = serviceTest.projectChangesService.getPrepareInfo( serviceTest.getPlatformData(platform), ); assert.deepStrictEqual(actualPrepareInfo, { nativePlatformStatus: Constants.NativePlatformStatus.requiresPrepare, }); } }); it(`shouldn't reset prepare info when native platform status is ${Constants.NativePlatformStatus.alreadyPrepared} and there is existing prepare info`, async () => { for (const platform of ["ios", "android"]) { await serviceTest.projectChangesService.checkForChanges( serviceTest.getPlatformData(platform), serviceTest.projectData, <any>{}, ); await serviceTest.projectChangesService.savePrepareInfo( serviceTest.getPlatformData(platform), serviceTest.projectData, null, ); const prepareInfo = serviceTest.projectChangesService.getPrepareInfo( serviceTest.getPlatformData(platform), ); await serviceTest.projectChangesService.setNativePlatformStatus( serviceTest.getPlatformData(platform), serviceTest.projectData, { nativePlatformStatus: Constants.NativePlatformStatus.alreadyPrepared, }, ); const actualPrepareInfo = serviceTest.projectChangesService.getPrepareInfo( serviceTest.getPlatformData(platform), ); prepareInfo.nativePlatformStatus = Constants.NativePlatformStatus.alreadyPrepared; assert.deepStrictEqual(actualPrepareInfo, prepareInfo); } }); _.each( [ Constants.NativePlatformStatus.requiresPlatformAdd, Constants.NativePlatformStatus.requiresPrepare, ], (nativePlatformStatus) => { it(`should reset prepare info when native platform status is ${nativePlatformStatus} and there is existing prepare info`, async () => { for (const platform of ["ios", "android"]) { await serviceTest.projectChangesService.checkForChanges( serviceTest.getPlatformData(platform), serviceTest.projectData, <any>{}, ); await serviceTest.projectChangesService.setNativePlatformStatus( serviceTest.getPlatformData(platform), serviceTest.projectData, { nativePlatformStatus: nativePlatformStatus }, ); const actualPrepareInfo = serviceTest.projectChangesService.getPrepareInfo( serviceTest.getPlatformData(platform), ); assert.deepStrictEqual(actualPrepareInfo, { nativePlatformStatus: nativePlatformStatus, }); } }); }, ); }); }); |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |