mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
fix(hmr): support for multi module replacement
This commit is contained in:
3
tests/app/livesync/livesync-button-page.scss
Normal file
3
tests/app/livesync/livesync-button-page.scss
Normal file
@@ -0,0 +1,3 @@
|
||||
Button {
|
||||
color: cyan;
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import * as app from "tns-core-modules/application/application";
|
||||
import * as frame from "tns-core-modules/ui/frame";
|
||||
|
||||
import { Color } from "tns-core-modules/color";
|
||||
import { isAndroid } from "tns-core-modules/platform";
|
||||
import { createViewFromEntry } from "tns-core-modules/ui/builder";
|
||||
import { Page } from "tns-core-modules/ui/page";
|
||||
import { Frame } from "tns-core-modules/ui/frame";
|
||||
@@ -20,6 +19,7 @@ const buttonHtmlPageFileName = "./livesync/livesync-button-page.html";
|
||||
const buttonXmlPageFileName = "./livesync/livesync-button-page.xml";
|
||||
const buttonJsPageFileName = "./livesync/livesync-button-page.js";
|
||||
const buttonTsPageFileName = "./livesync/livesync-button-page.ts";
|
||||
const buttonScssPageFileName = "./livesync/livesync-button-page.scss";
|
||||
const labelPageModuleName = "livesync/livesync-label-page";
|
||||
|
||||
const green = new Color("green");
|
||||
@@ -60,6 +60,36 @@ export function test_onLiveSync_ModuleContext_Markup_XmlFile() {
|
||||
_test_onLiveSync_ModuleReplace({ type: "markup", path: buttonXmlPageFileName });
|
||||
}
|
||||
|
||||
export function test_onLiveSync_ModuleContext_Markup_Script_XmlFile() {
|
||||
_test_onLiveSync_ModuleReplace_Multiple([
|
||||
{ type: "script", path: buttonTsPageFileName },
|
||||
{ type: "markup", path: buttonXmlPageFileName }
|
||||
]);
|
||||
}
|
||||
|
||||
export function test_onLiveSync_ModuleContext_Markup_Script_Style_XmlFile() {
|
||||
_test_onLiveSync_ModuleReplace_Multiple([
|
||||
{ type: "script", path: buttonTsPageFileName },
|
||||
{ type: "markup", path: buttonXmlPageFileName },
|
||||
{ type: "style", path: buttonScssPageFileName }
|
||||
]);
|
||||
}
|
||||
|
||||
export function test_onLiveSync_ModuleContext_Markup_Script_HtmlFile() {
|
||||
_test_onLiveSync_ModuleReplace_Multiple([
|
||||
{ type: "script", path: buttonTsPageFileName },
|
||||
{ type: "markup", path: buttonHtmlPageFileName }
|
||||
]);
|
||||
}
|
||||
|
||||
export function test_onLiveSync_ModuleContext_Markup_Script_Style_HtmlFile() {
|
||||
_test_onLiveSync_ModuleReplace_Multiple([
|
||||
{ type: "script", path: buttonTsPageFileName },
|
||||
{ type: "markup", path: buttonHtmlPageFileName },
|
||||
{ type: "style", path: buttonScssPageFileName }
|
||||
]);
|
||||
}
|
||||
|
||||
export function setUp() {
|
||||
const labelPage = <Page>createViewFromEntry(({ moduleName: labelPageModuleName }));
|
||||
helper.navigate(() => labelPage);
|
||||
@@ -121,6 +151,28 @@ function _test_onLiveSync_ModuleReplace(context: { type, path }) {
|
||||
TKUnit.assertEqual(pageBeforeNavigation, pageAfterBackNavigation, "Pages are different!");
|
||||
}
|
||||
|
||||
function _test_onLiveSync_ModuleReplace_Multiple(context: { type: string, path: string }[]) {
|
||||
const pageBeforeNavigation = helper.getCurrentPage();
|
||||
const buttonPage = <Page>createViewFromEntry(({ moduleName: buttonPageModuleName }));
|
||||
helper.navigateWithHistory(() => buttonPage);
|
||||
|
||||
context.forEach(item => {
|
||||
global.__onLiveSync(item);
|
||||
});
|
||||
|
||||
const topmostFrame = frame.topmost();
|
||||
waitUntilLivesyncComplete(topmostFrame);
|
||||
TKUnit.assertTrue(topmostFrame.currentPage.getViewById("button").isLoaded, "Button page is NOT loaded!");
|
||||
TKUnit.assertEqual(topmostFrame.backStack.length, 1, "Backstack is clean!");
|
||||
TKUnit.assertTrue(topmostFrame.canGoBack(), "Can NOT go back!");
|
||||
|
||||
helper.goBack();
|
||||
const pageAfterBackNavigation = helper.getCurrentPage();
|
||||
TKUnit.assertTrue(topmostFrame.currentPage.getViewById("label").isLoaded, "Label page is NOT loaded!");
|
||||
TKUnit.assertEqual(topmostFrame.backStack.length, 0, "Backstack is NOT clean!");
|
||||
TKUnit.assertEqual(pageBeforeNavigation, pageAfterBackNavigation, "Pages are different!");
|
||||
}
|
||||
|
||||
function _test_onLiveSync_ModuleContext_TypeStyle(context: { type, path }) {
|
||||
const pageBeforeNavigation = helper.getCurrentPage();
|
||||
const buttonPage = <Page>createViewFromEntry(({ moduleName: buttonPageModuleName }));
|
||||
@@ -146,5 +198,5 @@ function _test_onLiveSync_ModuleContext_TypeStyle(context: { type, path }) {
|
||||
}
|
||||
|
||||
function waitUntilLivesyncComplete(frame: Frame) {
|
||||
TKUnit.waitUntilReady(() => frame._executingEntry === null);
|
||||
TKUnit.waitUntilReady(() => frame.navigationQueueIsEmpty());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user