From 91f9b8f27494b2eb21ebce7c46582fa685762e8b Mon Sep 17 00:00:00 2001 From: fatme Date: Tue, 27 Nov 2018 14:33:53 +0200 Subject: [PATCH] fix: execute correctly local build after cloud build from sidekick Reset prepare info when native platform status is not alreadyPrepared in order to ensure the project will be prepared and all properties of this._prepareInfo will be correctly populated. --- lib/services/project-changes-service.ts | 2 +- test/project-changes-service.ts | 46 +++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/lib/services/project-changes-service.ts b/lib/services/project-changes-service.ts index ac3be05546..5ee4b39c08 100644 --- a/lib/services/project-changes-service.ts +++ b/lib/services/project-changes-service.ts @@ -171,7 +171,7 @@ export class ProjectChangesService implements IProjectChangesService { public setNativePlatformStatus(platform: string, projectData: IProjectData, addedPlatform: IAddedNativePlatform): void { this._prepareInfo = this._prepareInfo || this.getPrepareInfo(platform, projectData); - if (this._prepareInfo) { + if (this._prepareInfo && addedPlatform.nativePlatformStatus === NativePlatformStatus.alreadyPrepared) { this._prepareInfo.nativePlatformStatus = addedPlatform.nativePlatformStatus; } else { this._prepareInfo = { diff --git a/test/project-changes-service.ts b/test/project-changes-service.ts index 47eae49639..b42b5d318e 100644 --- a/test/project-changes-service.ts +++ b/test/project-changes-service.ts @@ -187,5 +187,51 @@ describe("Project Changes Service Tests", () => { assert.deepEqual(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({ + platform, + projectData: serviceTest.projectData, + projectChangesOptions: { + bundle: false, + release: false, + provision: undefined, + teamId: undefined, + useHotModuleReload: false + } + }); + serviceTest.projectChangesService.savePrepareInfo(platform, serviceTest.projectData); + const prepareInfo = serviceTest.projectChangesService.getPrepareInfo(platform, serviceTest.projectData); + + serviceTest.projectChangesService.setNativePlatformStatus(platform, serviceTest.projectData, { nativePlatformStatus: Constants.NativePlatformStatus.alreadyPrepared }); + + const actualPrepareInfo = serviceTest.projectChangesService.getPrepareInfo(platform, serviceTest.projectData); + prepareInfo.nativePlatformStatus = Constants.NativePlatformStatus.alreadyPrepared; + assert.deepEqual(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({ + platform, + projectData: serviceTest.projectData, + projectChangesOptions: { + bundle: false, + release: false, + provision: undefined, + teamId: undefined, + useHotModuleReload: false + } + }); + serviceTest.projectChangesService.setNativePlatformStatus(platform, serviceTest.projectData, { nativePlatformStatus: nativePlatformStatus }); + + const actualPrepareInfo = serviceTest.projectChangesService.getPrepareInfo(platform, serviceTest.projectData); + assert.deepEqual(actualPrepareInfo, { nativePlatformStatus: nativePlatformStatus }); + } + }); + }); }); });