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 }); + } + }); + }); }); });