diff --git a/lib/commands/appstore-upload.ts b/lib/commands/appstore-upload.ts index ca142c8e64..03168cde65 100644 --- a/lib/commands/appstore-upload.ts +++ b/lib/commands/appstore-upload.ts @@ -56,7 +56,11 @@ export class PublishIOS implements ICommand { if (!ipaFilePath) { const platform = this.$devicePlatformsConstants.iOS; // No .ipa path provided, build .ipa on out own. - const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: !!this.$options.bundle, release: this.$options.release }; + const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { + bundle: !!this.$options.bundle, + release: this.$options.release, + useHotModuleReload: false + }; const platformInfo: IPreparePlatformInfo = { platform, appFilesUpdaterOptions, diff --git a/lib/commands/build.ts b/lib/commands/build.ts index f90fb8a510..12dadd6e22 100644 --- a/lib/commands/build.ts +++ b/lib/commands/build.ts @@ -15,7 +15,11 @@ export abstract class BuildCommandBase extends ValidatePlatformCommandBase { public async executeCore(args: string[]): Promise { const platform = args[0].toLowerCase(); - const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: !!this.$options.bundle, release: this.$options.release }; + const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { + bundle: !!this.$options.bundle, + release: this.$options.release, + useHotModuleReload: this.$options.hmr + }; const platformInfo: IPreparePlatformInfo = { platform, appFilesUpdaterOptions, diff --git a/lib/commands/clean-app.ts b/lib/commands/clean-app.ts index bd938a3209..e22c1a4c64 100644 --- a/lib/commands/clean-app.ts +++ b/lib/commands/clean-app.ts @@ -16,7 +16,11 @@ export class CleanAppCommandBase extends ValidatePlatformCommandBase implements } public async execute(args: string[]): Promise { - const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: !!this.$options.bundle, release: this.$options.release }; + const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { + bundle: !!this.$options.bundle, + release: this.$options.release, + useHotModuleReload: false + }; const platformInfo: IPreparePlatformInfo = { appFilesUpdaterOptions, platform: this.platform.toLowerCase(), diff --git a/lib/commands/prepare.ts b/lib/commands/prepare.ts index 114e42da47..409ddf16c6 100644 --- a/lib/commands/prepare.ts +++ b/lib/commands/prepare.ts @@ -13,7 +13,11 @@ export class PrepareCommand extends ValidatePlatformCommandBase implements IComm } public async execute(args: string[]): Promise { - const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: !!this.$options.bundle, release: this.$options.release }; + const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { + bundle: !!this.$options.bundle, + release: this.$options.release, + useHotModuleReload: this.$options.hmr + }; const platformInfo: IPreparePlatformInfo = { platform: args[0], appFilesUpdaterOptions, diff --git a/lib/commands/preview.ts b/lib/commands/preview.ts index ed2848c621..0ecf450065 100644 --- a/lib/commands/preview.ts +++ b/lib/commands/preview.ts @@ -19,10 +19,11 @@ export class PreviewCommand implements ICommand { bundle: !!this.$options.bundle, release: this.$options.release, env: this.$options.env, - timeout: this.$options.timeout + timeout: this.$options.timeout, + useHotModuleReload: this.$options.hmr }); - await this.$playgroundQrCodeGenerator.generateQrCodeForCurrentApp(); + await this.$playgroundQrCodeGenerator.generateQrCodeForCurrentApp({ useHotModuleReload: this.$options.hmr }); } public async canExecute(args: string[]): Promise { diff --git a/lib/declarations.d.ts b/lib/declarations.d.ts index 7019f4a098..ac8a51bf84 100644 --- a/lib/declarations.d.ts +++ b/lib/declarations.d.ts @@ -486,7 +486,7 @@ interface IEnvOptions { interface IAndroidBuildOptionsSettings extends IAndroidReleaseOptions, IRelease { } -interface IAppFilesUpdaterOptions extends IBundle, IRelease, IOptionalWatchAllFiles { } +interface IAppFilesUpdaterOptions extends IBundle, IRelease, IOptionalWatchAllFiles, IHasUseHotModuleReloadOption { } interface IPlatformBuildData extends IAppFilesUpdaterOptions, IBuildConfig, IEnvOptions { } diff --git a/lib/definitions/livesync.d.ts b/lib/definitions/livesync.d.ts index e1bcd70ae1..6f7e3b1c32 100644 --- a/lib/definitions/livesync.d.ts +++ b/lib/definitions/livesync.d.ts @@ -180,7 +180,7 @@ interface IHasUseHotModuleReloadOption { /** * Defines if the hot module reload should be used. */ - useHotModuleReload?: boolean; + useHotModuleReload: boolean; } interface ILatestAppPackageInstalledSettings extends IDictionary> { /* empty */ } diff --git a/lib/definitions/preview-app-livesync.d.ts b/lib/definitions/preview-app-livesync.d.ts index eb70396d9f..641c2df086 100644 --- a/lib/definitions/preview-app-livesync.d.ts +++ b/lib/definitions/preview-app-livesync.d.ts @@ -10,7 +10,7 @@ declare global { interface IPreviewAppLiveSyncData extends IProjectDir, IAppFilesUpdaterOptionsComposition, IEnvOptions { } interface IPreviewSdkService { - qrCodeUrl: string; + getQrCodeUrl(options: IHasUseHotModuleReloadOption): string; connectedDevices: Device[]; initialize(getInitialFiles: (device: Device) => Promise): void; applyChanges(filesPayload: FilesPayload): Promise; @@ -29,6 +29,6 @@ declare global { interface IPlaygroundQrCodeGenerator { generateQrCodeForiOS(): Promise; generateQrCodeForAndroid(): Promise; - generateQrCodeForCurrentApp(): Promise; + generateQrCodeForCurrentApp(options: IHasUseHotModuleReloadOption): Promise; } } \ No newline at end of file diff --git a/lib/helpers/deploy-command-helper.ts b/lib/helpers/deploy-command-helper.ts index e03a6e2b92..de2d02f31a 100644 --- a/lib/helpers/deploy-command-helper.ts +++ b/lib/helpers/deploy-command-helper.ts @@ -7,7 +7,11 @@ export class DeployCommandHelper implements IDeployCommandHelper { } public getDeployPlatformInfo(platform: string): IDeployPlatformInfo { - const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: !!this.$options.bundle, release: this.$options.release }; + const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { + bundle: !!this.$options.bundle, + release: this.$options.release, + useHotModuleReload: this.$options.hmr + }; const deployOptions: IDeployPlatformOptions = { clean: this.$options.clean, device: this.$options.device, diff --git a/lib/helpers/livesync-command-helper.ts b/lib/helpers/livesync-command-helper.ts index 508ac83528..d5ab042a58 100644 --- a/lib/helpers/livesync-command-helper.ts +++ b/lib/helpers/livesync-command-helper.ts @@ -156,7 +156,8 @@ export class LiveSyncCommandHelper implements ILiveSyncCommandHelper { platform: currentPlatform, appFilesUpdaterOptions: { bundle: !!this.$options.bundle, - release: this.$options.release + release: this.$options.release, + useHotModuleReload: this.$options.hmr }, deployOptions, buildPlatform: this.$platformService.buildPlatform.bind(this.$platformService), diff --git a/lib/helpers/preview-command-helper.ts b/lib/helpers/preview-command-helper.ts index 2110dd28f6..b656f6b589 100644 --- a/lib/helpers/preview-command-helper.ts +++ b/lib/helpers/preview-command-helper.ts @@ -6,6 +6,7 @@ export class PreviewCommandHelper implements IPreviewCommandHelper { private ctrlcReader: readline.ReadLine; constructor(private $playgroundQrCodeGenerator: IPlaygroundQrCodeGenerator, + private $options: IOptions, private $processService: IProcessService) { this.$processService.attachToProcessExitSignals(this, () => { this.stopWaitingForCommand(); @@ -49,7 +50,7 @@ export class PreviewCommandHelper implements IPreviewCommandHelper { await this.$playgroundQrCodeGenerator.generateQrCodeForiOS(); return; case "c": - await this.$playgroundQrCodeGenerator.generateQrCodeForCurrentApp(); + await this.$playgroundQrCodeGenerator.generateQrCodeForCurrentApp({ useHotModuleReload: this.$options.hmr }); return; } } diff --git a/lib/services/livesync/ios-livesync-service.ts b/lib/services/livesync/ios-livesync-service.ts index e2f3f03208..2cbd5f749d 100644 --- a/lib/services/livesync/ios-livesync-service.ts +++ b/lib/services/livesync/ios-livesync-service.ts @@ -14,8 +14,8 @@ export class IOSLiveSyncService extends PlatformLiveSyncServiceBase implements I $logger: ILogger, $projectFilesProvider: IProjectFilesProvider, private $iOSDebuggerPortService: IIOSDebuggerPortService) { - super($fs, $logger, $platformsData, $projectFilesManager, $devicePathProvider, $projectFilesProvider); - } + super($fs, $logger, $platformsData, $projectFilesManager, $devicePathProvider, $projectFilesProvider); + } public async fullSync(syncInfo: IFullSyncInfo): Promise { const device = syncInfo.device; @@ -60,7 +60,13 @@ export class IOSLiveSyncService extends PlatformLiveSyncServiceBase implements I public liveSyncWatchAction(device: Mobile.IDevice, liveSyncInfo: ILiveSyncWatchInfo): Promise { if (liveSyncInfo.isReinstalled) { // In this case we should execute fullsync because iOS Runtime requires the full content of app dir to be extracted in the root of sync dir. - return this.fullSync({ projectData: liveSyncInfo.projectData, device, syncAllFiles: liveSyncInfo.syncAllFiles, liveSyncDeviceInfo: liveSyncInfo.liveSyncDeviceInfo, watch: true }); + return this.fullSync({ + projectData: liveSyncInfo.projectData, + device, syncAllFiles: liveSyncInfo.syncAllFiles, + liveSyncDeviceInfo: liveSyncInfo.liveSyncDeviceInfo, + watch: true, + useHotModuleReload: liveSyncInfo.useHotModuleReload + }); } else { return super.liveSyncWatchAction(device, liveSyncInfo); } diff --git a/lib/services/livesync/livesync-service.ts b/lib/services/livesync/livesync-service.ts index 42d308a8b4..1d908a991b 100644 --- a/lib/services/livesync/livesync-service.ts +++ b/lib/services/livesync/livesync-service.ts @@ -328,7 +328,8 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi this.$previewAppLiveSyncService.initialize({ appFilesUpdaterOptions: { bundle: liveSyncData.bundle, - release: liveSyncData.release + release: liveSyncData.release, + useHotModuleReload: liveSyncData.useHotModuleReload }, env: liveSyncData.env, projectDir: projectData.projectDir @@ -389,7 +390,8 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi appFilesUpdaterOptions: { bundle: options.bundle, release: options.release, - watchAllFiles: options.liveSyncData.watchAllFiles + watchAllFiles: options.liveSyncData.watchAllFiles, + useHotModuleReload: options.liveSyncData.useHotModuleReload }, projectData: options.projectData, env: options.env, @@ -589,7 +591,8 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi await this.$previewAppLiveSyncService.syncFiles({ appFilesUpdaterOptions: { bundle: liveSyncData.bundle, - release: liveSyncData.release + release: liveSyncData.release, + useHotModuleReload: liveSyncData.useHotModuleReload }, env: liveSyncData.env, projectDir: projectData.projectDir @@ -691,7 +694,8 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi appFilesUpdaterOptions: { bundle: liveSyncData.bundle, release: liveSyncData.release, - watchAllFiles: liveSyncData.watchAllFiles + watchAllFiles: liveSyncData.watchAllFiles, + useHotModuleReload: liveSyncData.useHotModuleReload }, platforms }, diff --git a/lib/services/livesync/playground/preview-sdk-service.ts b/lib/services/livesync/playground/preview-sdk-service.ts index 46e273677e..170b1a6740 100644 --- a/lib/services/livesync/playground/preview-sdk-service.ts +++ b/lib/services/livesync/playground/preview-sdk-service.ts @@ -13,8 +13,9 @@ export class PreviewSdkService implements IPreviewSdkService { private $config: IConfiguration) { } - public get qrCodeUrl(): string { - return `nsplay://boot?instanceId=${this.instanceId}&pKey=${PubnubKeys.PUBLISH_KEY}&sKey=${PubnubKeys.SUBSCRIBE_KEY}&template=play-ng`; + public getQrCodeUrl(options: IHasUseHotModuleReloadOption): string { + const hmrValue = options.useHotModuleReload ? "1" : "0"; + return `nsplay://boot?instanceId=${this.instanceId}&pKey=${PubnubKeys.PUBLISH_KEY}&sKey=${PubnubKeys.SUBSCRIBE_KEY}&template=play-ng&hmr=${hmrValue}`; } public initialize(getInitialFiles: (device: Device) => Promise): void { diff --git a/lib/services/livesync/playground/qr-code-generator.ts b/lib/services/livesync/playground/qr-code-generator.ts index 01c2fa6ca4..444f551207 100644 --- a/lib/services/livesync/playground/qr-code-generator.ts +++ b/lib/services/livesync/playground/qr-code-generator.ts @@ -18,8 +18,8 @@ export class PlaygroundQrCodeGenerator implements IPlaygroundQrCodeGenerator { await this.generateQrCode(PlaygroundStoreUrls.GOOGLE_PLAY_URL); } - public async generateQrCodeForCurrentApp(): Promise { - await this.generateQrCode(this.$previewSdkService.qrCodeUrl); + public async generateQrCodeForCurrentApp(options: IHasUseHotModuleReloadOption): Promise { + await this.generateQrCode(this.$previewSdkService.getQrCodeUrl(options)); } private async generateQrCode(url: string): Promise { diff --git a/lib/services/platform-environment-requirements.ts b/lib/services/platform-environment-requirements.ts index 2e6d3e5a03..da9e0b27fc 100644 --- a/lib/services/platform-environment-requirements.ts +++ b/lib/services/platform-environment-requirements.ts @@ -195,7 +195,8 @@ export class PlatformEnvironmentRequirements implements IPlatformEnvironmentRequ bundle: !!options.bundle, release: options.release, env: options.env, - timeout: options.timeout + timeout: options.timeout, + useHotModuleReload: options.hmr }); } } diff --git a/lib/services/platform-service.ts b/lib/services/platform-service.ts index f751cc888d..dcef7a3240 100644 --- a/lib/services/platform-service.ts +++ b/lib/services/platform-service.ts @@ -213,7 +213,8 @@ export class PlatformService extends EventEmitter implements IPlatformService { provision: config.provision, teamId: config.teamId, nativePlatformStatus, - skipModulesNativeCheck: preparePlatformInfo.skipModulesNativeCheck + skipModulesNativeCheck: preparePlatformInfo.skipModulesNativeCheck, + useHotModuleReload: appFilesUpdaterOptions.useHotModuleReload } }); diff --git a/lib/services/test-execution-service.ts b/lib/services/test-execution-service.ts index 62e4a5144e..e61d740655 100644 --- a/lib/services/test-execution-service.ts +++ b/lib/services/test-execution-service.ts @@ -55,7 +55,11 @@ class TestExecutionService implements ITestExecutionService { const socketIoJsUrl = `http://localhost:${this.$options.port}/socket.io/socket.io.js`; const socketIoJs = (await this.$httpClient.httpRequest(socketIoJsUrl)).body; this.$fs.writeFile(path.join(projectDir, TestExecutionService.SOCKETIO_JS_FILE_NAME), socketIoJs); - const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: !!this.$options.bundle, release: this.$options.release }; + const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { + bundle: !!this.$options.bundle, + release: this.$options.release, + useHotModuleReload: this.$options.hmr + }; const preparePlatformInfo: IPreparePlatformInfo = { platform, appFilesUpdaterOptions, @@ -125,7 +129,8 @@ class TestExecutionService implements ITestExecutionService { bundle: !!this.$options.bundle, release: this.$options.release, env: this.$options.env, - timeout: this.$options.timeout + timeout: this.$options.timeout, + useHotModuleReload: this.$options.hmr }; await this.$liveSyncService.liveSync(deviceDescriptors, liveSyncInfo); @@ -183,7 +188,11 @@ class TestExecutionService implements ITestExecutionService { this.$fs.writeFile(path.join(projectDir, TestExecutionService.CONFIG_FILE_NAME), configJs); } - const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: !!this.$options.bundle, release: this.$options.release }; + const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { + bundle: !!this.$options.bundle, + release: this.$options.release, + useHotModuleReload: this.$options.hmr + }; const preparePlatformInfo: IPreparePlatformInfo = { platform, appFilesUpdaterOptions, @@ -253,7 +262,8 @@ class TestExecutionService implements ITestExecutionService { bundle: !!this.$options.bundle, release: this.$options.release, env: this.$options.env, - timeout: this.$options.timeout + timeout: this.$options.timeout, + useHotModuleReload: this.$options.hmr }; await this.$liveSyncService.liveSync(deviceDescriptors, liveSyncInfo); diff --git a/test/helpers/preview-command-helper.ts b/test/helpers/preview-command-helper.ts index 5709fe005f..ef62d0d105 100644 --- a/test/helpers/preview-command-helper.ts +++ b/test/helpers/preview-command-helper.ts @@ -19,6 +19,7 @@ function createTestInjector() { injector.register("logger", { info: () => ({}) }); + injector.register("options", {}); injector.register("playgroundQrCodeGenerator", { generateQrCodeForAndroid: async () => { qrCodesData.isGeneratedForAndroid = true; @@ -26,7 +27,7 @@ function createTestInjector() { generateQrCodeForiOS: async () => { qrCodesData.isGeneratedForiOS = true; }, - generateQrCodeForCurrentApp: async () => { + generateQrCodeForCurrentApp: async (options: IHasUseHotModuleReloadOption) => { qrCodesData.isGeneratedForCurrentApp = true; } }); diff --git a/test/ios-project-service.ts b/test/ios-project-service.ts index 0828d9361b..e65ffd51bb 100644 --- a/test/ios-project-service.ts +++ b/test/ios-project-service.ts @@ -773,7 +773,7 @@ describe("iOS Project Service Signing", () => { describe("Check for Changes", () => { it("sets signingChanged if no Xcode project exists", async () => { const changes = {}; - await iOSProjectService.checkForChanges(changes, { bundle: false, release: false, provision: "NativeScriptDev", teamId: undefined }, projectData); + await iOSProjectService.checkForChanges(changes, { bundle: false, release: false, provision: "NativeScriptDev", teamId: undefined, useHotModuleReload: false }, projectData); assert.isTrue(!!changes.signingChanged); }); it("sets signingChanged if the Xcode projects is configured with Automatic signing, but proivsion is specified", async () => { @@ -787,7 +787,7 @@ describe("iOS Project Service Signing", () => { }; }; const changes = {}; - await iOSProjectService.checkForChanges(changes, { bundle: false, release: false, provision: "NativeScriptDev", teamId: undefined }, projectData); + await iOSProjectService.checkForChanges(changes, { bundle: false, release: false, provision: "NativeScriptDev", teamId: undefined, useHotModuleReload: false }, projectData); assert.isTrue(!!changes.signingChanged); }); it("sets signingChanged if the Xcode projects is configured with Manual signing, but the proivsion specified differs the selected in the pbxproj", async () => { @@ -806,7 +806,7 @@ describe("iOS Project Service Signing", () => { }; }; const changes = {}; - await iOSProjectService.checkForChanges(changes, { bundle: false, release: false, provision: "NativeScriptDev", teamId: undefined }, projectData); + await iOSProjectService.checkForChanges(changes, { bundle: false, release: false, provision: "NativeScriptDev", teamId: undefined, useHotModuleReload: false }, projectData); assert.isTrue(!!changes.signingChanged); }); it("does not set signingChanged if the Xcode projects is configured with Manual signing and proivsion matches", async () => { @@ -825,7 +825,7 @@ describe("iOS Project Service Signing", () => { }; }; const changes = {}; - await iOSProjectService.checkForChanges(changes, { bundle: false, release: false, provision: "NativeScriptDev", teamId: undefined }, projectData); + await iOSProjectService.checkForChanges(changes, { bundle: false, release: false, provision: "NativeScriptDev", teamId: undefined, useHotModuleReload: false }, projectData); assert.isFalse(!!changes.signingChanged); }); }); diff --git a/test/npm-support.ts b/test/npm-support.ts index 7ba520aa96..7f55ecd066 100644 --- a/test/npm-support.ts +++ b/test/npm-support.ts @@ -218,7 +218,7 @@ async function preparePlatform(testInjector: IInjector): Promise { await platformService.preparePlatform({ platform: "android", - appFilesUpdaterOptions: { bundle: !!options.bundle, release: options.release }, + appFilesUpdaterOptions: { bundle: !!options.bundle, release: options.release, useHotModuleReload: false }, platformTemplate: "", projectData, config: options, diff --git a/test/platform-service.ts b/test/platform-service.ts index 015a66a3fb..d025c66f29 100644 --- a/test/platform-service.ts +++ b/test/platform-service.ts @@ -466,7 +466,7 @@ describe('Platform Service Tests', () => { projectData.appResourcesDirectoryPath = path.join(testDirData.appFolderPath, "App_Resources"); platformService = testInjector.resolve("platformService"); - const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: false, release: release }; + const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: false, release: release, useHotModuleReload: false }; await platformService.preparePlatform({ platform: platformToTest, appFilesUpdaterOptions, @@ -903,7 +903,7 @@ describe('Platform Service Tests', () => { let warnings: string = ""; try { testInjector.resolve("$logger").warn = (text: string) => warnings += text; - const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: false, release: false }; + const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: false, release: false, useHotModuleReload: false }; await platformService.preparePlatform({ platform: "android", appFilesUpdaterOptions, diff --git a/test/project-changes-service.ts b/test/project-changes-service.ts index ba80af7566..8dd5f7946d 100644 --- a/test/project-changes-service.ts +++ b/test/project-changes-service.ts @@ -156,7 +156,8 @@ describe("Project Changes Service Tests", () => { bundle: false, release: false, provision: undefined, - teamId: undefined + teamId: undefined, + useHotModuleReload: false } }); assert.isTrue(!!iOSChanges.signingChanged, "iOS signingChanged expected to be true"); @@ -168,7 +169,8 @@ describe("Project Changes Service Tests", () => { bundle: false, release: false, provision: undefined, - teamId: undefined + teamId: undefined, + useHotModuleReload: false } }); assert.isFalse(!!androidChanges.signingChanged, "Android signingChanged expected to be false"); diff --git a/test/services/playground/preview-app-livesync-service.ts b/test/services/playground/preview-app-livesync-service.ts index 6c6437592d..492e489679 100644 --- a/test/services/playground/preview-app-livesync-service.ts +++ b/test/services/playground/preview-app-livesync-service.ts @@ -1,4 +1,5 @@ import { Yok } from "../../../lib/common/yok"; +import * as _ from 'lodash'; import { LoggerStub, ErrorsStub } from "../../stubs"; import { FilePayload, Device, FilesPayload } from "nativescript-preview-sdk"; import { PreviewAppLiveSyncService } from "../../../lib/services/livesync/playground/preview-app-livesync-service"; @@ -16,12 +17,14 @@ interface ITestCase { interface IActOptions { callGetInitialFiles: boolean; + hmr: boolean; } interface IAssertOptions { checkWarnings?: boolean; isComparePluginsOnDeviceCalled?: boolean; checkInitialFiles?: boolean; + hmr?: boolean; } interface IActInput { @@ -32,6 +35,7 @@ interface IActInput { } let isComparePluginsOnDeviceCalled = false; +let isHookCalledWithHMR = false; let applyChangesParams: FilePayload[] = []; let initialFiles: FilePayload[] = []; let readTextParams: string[] = []; @@ -57,7 +61,8 @@ const syncFilesMockData = { projectDir: projectDirPath, appFilesUpdaterOptions: { release: false, - bundle: false + bundle: false, + useHotModuleReload: false }, env: {} }; @@ -65,7 +70,7 @@ const syncFilesMockData = { class PreviewSdkServiceMock implements IPreviewSdkService { public getInitialFiles: (device: Device) => Promise; - public get qrCodeUrl() { + public getQrCodeUrl(options: IHasUseHotModuleReloadOption) { return "my_cool_qr_code_url"; } @@ -146,7 +151,9 @@ function createTestInjector(options?: { } }); injector.register("hooksService", { - executeBeforeHooks: () => ({}) + executeBeforeHooks: (name: string, args: any) => { + isHookCalledWithHMR = args.hookArgs.config.appFilesUpdaterOptions.useHotModuleReload; + } }); return injector; @@ -169,8 +176,9 @@ async function initialSync(input?: IActInput) { input = input || {}; const { previewAppLiveSyncService, previewSdkService, actOptions } = input; - - await previewAppLiveSyncService.initialize(syncFilesMockData); + const syncFilesData = _.cloneDeep(syncFilesMockData); + syncFilesData.appFilesUpdaterOptions.useHotModuleReload = actOptions.hmr; + await previewAppLiveSyncService.initialize(syncFilesData); if (actOptions.callGetInitialFiles) { await previewSdkService.getInitialFiles(deviceMockData); } @@ -181,7 +189,9 @@ async function syncFiles(input?: IActInput) { const { previewAppLiveSyncService, previewSdkService, projectFiles, actOptions } = input; - await previewAppLiveSyncService.initialize(syncFilesMockData); + const syncFilesData = _.cloneDeep(syncFilesMockData); + syncFilesData.appFilesUpdaterOptions.useHotModuleReload = actOptions.hmr; + await previewAppLiveSyncService.initialize(syncFilesData); if (actOptions.callGetInitialFiles) { await previewSdkService.getInitialFiles(deviceMockData); } @@ -193,6 +203,7 @@ async function assert(expectedFiles: string[], options?: IAssertOptions) { options = options || {}; const actualFiles = options.checkInitialFiles ? initialFiles : applyChangesParams; + chai.assert.equal(isHookCalledWithHMR, options.hmr || false); chai.assert.deepEqual(actualFiles, mapFiles(expectedFiles)); if (options.checkWarnings) { @@ -206,6 +217,7 @@ async function assert(expectedFiles: string[], options?: IAssertOptions) { function reset() { isComparePluginsOnDeviceCalled = false; + isHookCalledWithHMR = false; applyChangesParams = []; initialFiles = []; readTextParams = []; @@ -230,7 +242,8 @@ function mapFiles(files: string[]): FilePayload[] { function setDefaults(testCase: ITestCase): ITestCase { if (!testCase.actOptions) { testCase.actOptions = { - callGetInitialFiles: true + callGetInitialFiles: true, + hmr: false }; } @@ -327,6 +340,33 @@ describe("previewAppLiveSyncService", () => { } ]; + const hmrTestCases: ITestCase[] = [ + { + name: "when set to true", + appFiles: [], + expectedFiles: [], + actOptions: { + hmr: true, + callGetInitialFiles: true + }, + assertOptions: { + hmr: true + } + }, + { + name: "when set to false", + appFiles: [], + expectedFiles: [], + actOptions: { + hmr: false, + callGetInitialFiles: true + }, + assertOptions: { + hmr: false + } + } + ]; + const noAppFilesTestCases: ITestCase[] = [ { name: "should transfer correctly default project files", @@ -352,6 +392,10 @@ describe("previewAppLiveSyncService", () => { { name: "should handle correctly when no files are provided", testCases: noAppFilesTestCases + }, + { + name: "should pass the hmr option to the hook", + testCases: hmrTestCases } ]; diff --git a/test/services/preview-sdk-service.ts b/test/services/preview-sdk-service.ts new file mode 100644 index 0000000000..a4fe56ed1a --- /dev/null +++ b/test/services/preview-sdk-service.ts @@ -0,0 +1,38 @@ +import { PreviewSdkService } from "../../lib/services/livesync/playground/preview-sdk-service"; +import { Yok } from "../../lib/common/yok"; +import { assert } from "chai"; +import { LoggerStub, ErrorsStub } from "../stubs"; + +const getPreviewSdkService = (): IPreviewSdkService => { + const testInjector = new Yok(); + testInjector.register("logger", LoggerStub); + testInjector.register("errors", ErrorsStub); + testInjector.register("config", {}); + testInjector.register("previewSdkService", PreviewSdkService); + + testInjector.register("httpClient", { + httpRequest: async (options: any, proxySettings?: IProxySettings): Promise => undefined + }); + + return testInjector.resolve("previewSdkService"); +}; + +describe('PreviewSdkService', () => { + describe('getQrCodeUrl', () => { + it('sets hmr to 1 when useHotModuleReload is true', async () => { + const sdk = getPreviewSdkService(); + + const previewUrl = sdk.getQrCodeUrl({ useHotModuleReload: true }); + + assert.isTrue(previewUrl.indexOf("hmr=1") > -1); + }); + }); + + it('sets hmr to 0 when useHotModuleReload is false', async () => { + const sdk = getPreviewSdkService(); + + const previewUrl = sdk.getQrCodeUrl({ useHotModuleReload: false }); + + assert.isTrue(previewUrl.indexOf("hmr=0") > -1); + }); +});