|
|
|
@@ -3,40 +3,57 @@ import * as TKUnit from "../tk-unit";
|
|
|
|
|
|
|
|
|
|
import * as app from "tns-core-modules/application/application";
|
|
|
|
|
import * as frame from "tns-core-modules/ui/frame";
|
|
|
|
|
import * as fs from "tns-core-modules/file-system";
|
|
|
|
|
import { Color } from "tns-core-modules/color";
|
|
|
|
|
import { createViewFromEntry } from "tns-core-modules/ui/builder";
|
|
|
|
|
import { Page } from "tns-core-modules/ui/page";
|
|
|
|
|
import { Frame } from "tns-core-modules/ui/frame";
|
|
|
|
|
|
|
|
|
|
const appCssFileName = "/application-page.css";
|
|
|
|
|
const appNewCssFileName = "app-new-page.css";
|
|
|
|
|
const appNewScssFileName = "app-new-sass-page.css";
|
|
|
|
|
const buttonCssFileName = "/button-page.css";
|
|
|
|
|
const LIVESYNC_FOLDER = "livesync/";
|
|
|
|
|
|
|
|
|
|
const buttonPageModuleName = "livesync/livesync-button-page";
|
|
|
|
|
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 appCssFileName = `${LIVESYNC_FOLDER}application-page.css`;
|
|
|
|
|
const appNewCssFileName = `${LIVESYNC_FOLDER}app-new-page.css`;
|
|
|
|
|
// `.scss` module registers in webpack as `.css`
|
|
|
|
|
// https://github.com/NativeScript/NativeScript/blob/5.4.2/tns-core-modules/globals/globals.ts#L32-L33
|
|
|
|
|
const appNewScssFileNameAsCss = `${LIVESYNC_FOLDER}app-new-scss-page.css`;
|
|
|
|
|
const appNewScssFileName = `${LIVESYNC_FOLDER}app-new-scss-page.scss`;
|
|
|
|
|
|
|
|
|
|
const buttonCssModuleName = `${LIVESYNC_FOLDER}button-css-page`;
|
|
|
|
|
const buttonScssModuleName = `${LIVESYNC_FOLDER}button-scss-page`;
|
|
|
|
|
const buttonCssFileName = `${LIVESYNC_FOLDER}button-css-page.css`;
|
|
|
|
|
const buttonScssFileName = `${LIVESYNC_FOLDER}button-scss-page.scss`;
|
|
|
|
|
|
|
|
|
|
const buttonPageModuleName = `${LIVESYNC_FOLDER}livesync-button-page`;
|
|
|
|
|
const buttonHtmlPageFileName = `${LIVESYNC_FOLDER}livesync-button-page.html`;
|
|
|
|
|
const buttonXmlPageFileName = `${LIVESYNC_FOLDER}livesync-button-page.xml`;
|
|
|
|
|
const buttonJsPageFileName = `${LIVESYNC_FOLDER}livesync-button-page.js`;
|
|
|
|
|
const buttonTsPageFileName = `${LIVESYNC_FOLDER}livesync-button-page.ts`;
|
|
|
|
|
const buttonScssPageFileName = `${LIVESYNC_FOLDER}livesync-button-page.scss`;
|
|
|
|
|
const labelPageModuleName = `${LIVESYNC_FOLDER}livesync-label-page`;
|
|
|
|
|
|
|
|
|
|
const green = new Color("green");
|
|
|
|
|
|
|
|
|
|
export function setUp() {
|
|
|
|
|
const labelPage = <Page>createViewFromEntry(({ moduleName: labelPageModuleName }));
|
|
|
|
|
helper.navigate(() => labelPage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function tearDown() {
|
|
|
|
|
app.setCssFileName(appCssFileName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function test_onLiveSync_ModuleContext_AppStyle_AppNewCss() {
|
|
|
|
|
_test_onLiveSync_ModuleContext_AppStyle(appNewCssFileName);
|
|
|
|
|
_test_onLiveSync_ModuleContext_AppStyle(appNewCssFileName, appNewCssFileName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function test_onLiveSync_ModuleContext_AppStyle_AppNewScss() {
|
|
|
|
|
_test_onLiveSync_ModuleContext_AppStyle(appNewScssFileName);
|
|
|
|
|
_test_onLiveSync_ModuleContext_AppStyle(appNewScssFileNameAsCss, appNewScssFileName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function test_onLiveSync_ModuleContext_ContextUndefined() {
|
|
|
|
|
export function test_onLiveSync_ModuleContext_Undefined() {
|
|
|
|
|
_test_onLiveSync_ModuleContext({ type: undefined, path: undefined });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function test_onLiveSync_ModuleContext_ModuleUndefined() {
|
|
|
|
|
export function test_onLiveSync_ModuleContext_PathUndefined() {
|
|
|
|
|
_test_onLiveSync_ModuleContext({ type: "script", path: undefined });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -49,7 +66,11 @@ export function test_onLiveSync_ModuleContext_Script_TsFile() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function test_onLiveSync_ModuleContext_Style_CssFile() {
|
|
|
|
|
_test_onLiveSync_ModuleContext_TypeStyle({ type: "style", path: fs.knownFolders.currentApp().path + buttonCssFileName });
|
|
|
|
|
_test_onLiveSync_ModuleContext_TypeStyle(buttonCssModuleName, buttonCssFileName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function test_onLiveSync_ModuleContext_Style_ScssFile() {
|
|
|
|
|
_test_onLiveSync_ModuleContext_TypeStyle(buttonScssModuleName, buttonScssFileName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function test_onLiveSync_ModuleContext_Markup_HtmlFile() {
|
|
|
|
@@ -60,14 +81,14 @@ export function test_onLiveSync_ModuleContext_Markup_XmlFile() {
|
|
|
|
|
_test_onLiveSync_ModuleReplace({ type: "markup", path: buttonXmlPageFileName });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function test_onLiveSync_ModuleContext_Markup_Script_XmlFile() {
|
|
|
|
|
export function test_onLiveSync_ModuleContext_MarkupXml_ScriptTs_Files() {
|
|
|
|
|
_test_onLiveSync_ModuleReplace_Multiple([
|
|
|
|
|
{ type: "script", path: buttonTsPageFileName },
|
|
|
|
|
{ type: "markup", path: buttonXmlPageFileName }
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function test_onLiveSync_ModuleContext_Markup_Script_Style_XmlFile() {
|
|
|
|
|
export function test_onLiveSync_ModuleContext_MarkupXml_ScriptTs_StyleScss_Files() {
|
|
|
|
|
_test_onLiveSync_ModuleReplace_Multiple([
|
|
|
|
|
{ type: "script", path: buttonTsPageFileName },
|
|
|
|
|
{ type: "markup", path: buttonXmlPageFileName },
|
|
|
|
@@ -75,14 +96,14 @@ export function test_onLiveSync_ModuleContext_Markup_Script_Style_XmlFile() {
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function test_onLiveSync_ModuleContext_Markup_Script_HtmlFile() {
|
|
|
|
|
export function test_onLiveSync_ModuleContext_MarkupHtml_ScriptTs_Files() {
|
|
|
|
|
_test_onLiveSync_ModuleReplace_Multiple([
|
|
|
|
|
{ type: "script", path: buttonTsPageFileName },
|
|
|
|
|
{ type: "markup", path: buttonHtmlPageFileName }
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function test_onLiveSync_ModuleContext_Markup_Script_Style_HtmlFile() {
|
|
|
|
|
export function test_onLiveSync_ModuleContext_MarkupHtml_ScriptTs_StyleScss_Files() {
|
|
|
|
|
_test_onLiveSync_ModuleReplace_Multiple([
|
|
|
|
|
{ type: "script", path: buttonTsPageFileName },
|
|
|
|
|
{ type: "markup", path: buttonHtmlPageFileName },
|
|
|
|
@@ -90,23 +111,14 @@ export function test_onLiveSync_ModuleContext_Markup_Script_Style_HtmlFile() {
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function setUp() {
|
|
|
|
|
const labelPage = <Page>createViewFromEntry(({ moduleName: labelPageModuleName }));
|
|
|
|
|
helper.navigate(() => labelPage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function tearDown() {
|
|
|
|
|
app.setCssFileName(fs.knownFolders.currentApp().path + appCssFileName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _test_onLiveSync_ModuleContext_AppStyle(styleFileName: string) {
|
|
|
|
|
function _test_onLiveSync_ModuleContext_AppStyle(appStyleFileName: string, livesyncStyleFileName: string) {
|
|
|
|
|
const pageBeforeNavigation = helper.getCurrentPage();
|
|
|
|
|
const buttonPage = <Page>createViewFromEntry(({ moduleName: buttonPageModuleName }));
|
|
|
|
|
helper.navigateWithHistory(() => buttonPage);
|
|
|
|
|
|
|
|
|
|
app.setCssFileName(fs.knownFolders.currentApp().path + "/" + styleFileName);
|
|
|
|
|
app.setCssFileName(appStyleFileName);
|
|
|
|
|
const pageBeforeLiveSync = helper.getCurrentPage();
|
|
|
|
|
global.__onLiveSync({ type: "style", path: fs.knownFolders.currentApp().path + "/" + styleFileName });
|
|
|
|
|
livesync({ type: "style", path: livesyncStyleFileName });
|
|
|
|
|
|
|
|
|
|
const pageAfterLiveSync = helper.getCurrentPage();
|
|
|
|
|
TKUnit.waitUntilReady(() => pageAfterLiveSync.getViewById("button").style.color.toString() === green.toString());
|
|
|
|
@@ -121,10 +133,10 @@ function _test_onLiveSync_ModuleContext_AppStyle(styleFileName: string) {
|
|
|
|
|
TKUnit.assertTrue(pageAfterNavigationBack._cssState.isSelectorsLatestVersionApplied(), "Latest selectors version is NOT applied!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _test_onLiveSync_ModuleContext(context: { type, path }) {
|
|
|
|
|
function _test_onLiveSync_ModuleContext(context: ModuleContext) {
|
|
|
|
|
const buttonPage = <Page>createViewFromEntry(({ moduleName: buttonPageModuleName }));
|
|
|
|
|
helper.navigateWithHistory(() => buttonPage);
|
|
|
|
|
global.__onLiveSync({ type: context.type, path: context.path });
|
|
|
|
|
livesync({ type: context.type, path: context.path });
|
|
|
|
|
|
|
|
|
|
TKUnit.waitUntilReady(() => !!frame.topmost());
|
|
|
|
|
const topmostFrame = frame.topmost();
|
|
|
|
@@ -132,12 +144,12 @@ function _test_onLiveSync_ModuleContext(context: { type, path }) {
|
|
|
|
|
TKUnit.assertTrue(topmostFrame.currentPage.getViewById("label").isLoaded);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _test_onLiveSync_ModuleReplace(context: { type, path }) {
|
|
|
|
|
function _test_onLiveSync_ModuleReplace(context: ModuleContext) {
|
|
|
|
|
const pageBeforeNavigation = helper.getCurrentPage();
|
|
|
|
|
const buttonPage = <Page>createViewFromEntry(({ moduleName: buttonPageModuleName }));
|
|
|
|
|
helper.navigateWithHistory(() => buttonPage);
|
|
|
|
|
|
|
|
|
|
global.__onLiveSync({ type: context.type, path: context.path });
|
|
|
|
|
livesync({ type: context.type, path: context.path });
|
|
|
|
|
const topmostFrame = frame.topmost();
|
|
|
|
|
waitUntilLivesyncComplete(topmostFrame);
|
|
|
|
|
TKUnit.assertTrue(topmostFrame.currentPage.getViewById("button").isLoaded, "Button page is NOT loaded!");
|
|
|
|
@@ -151,37 +163,15 @@ 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 }) {
|
|
|
|
|
function _test_onLiveSync_ModuleContext_TypeStyle(styleModuleName: string, livesyncStyleFileName: string) {
|
|
|
|
|
const pageBeforeNavigation = helper.getCurrentPage();
|
|
|
|
|
const buttonPage = <Page>createViewFromEntry(({ moduleName: buttonPageModuleName }));
|
|
|
|
|
helper.navigateWithHistory(() => buttonPage);
|
|
|
|
|
|
|
|
|
|
const pageBeforeLiveSync = helper.getCurrentPage();
|
|
|
|
|
pageBeforeLiveSync._moduleName = "button-page";
|
|
|
|
|
pageBeforeLiveSync._moduleName = styleModuleName;
|
|
|
|
|
|
|
|
|
|
global.__onLiveSync({ type: context.type, path: context.path });
|
|
|
|
|
livesync({ type: "style", path: livesyncStyleFileName });
|
|
|
|
|
const topmostFrame = frame.topmost();
|
|
|
|
|
waitUntilLivesyncComplete(topmostFrame);
|
|
|
|
|
|
|
|
|
@@ -197,6 +187,33 @@ function _test_onLiveSync_ModuleContext_TypeStyle(context: { type, path }) {
|
|
|
|
|
TKUnit.assertTrue(pageAfterNavigationBack._cssState.isSelectorsLatestVersionApplied(), "Latest selectors version is NOT applied!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _test_onLiveSync_ModuleReplace_Multiple(context: ModuleContext[]) {
|
|
|
|
|
const pageBeforeNavigation = helper.getCurrentPage();
|
|
|
|
|
const buttonPage = <Page>createViewFromEntry(({ moduleName: buttonPageModuleName }));
|
|
|
|
|
helper.navigateWithHistory(() => buttonPage);
|
|
|
|
|
|
|
|
|
|
context.forEach(item => {
|
|
|
|
|
livesync(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 livesync(context: ModuleContext) {
|
|
|
|
|
const ls = (<any>global).__hmrSyncBackup || global.__onLiveSync;
|
|
|
|
|
ls(context);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function waitUntilLivesyncComplete(frame: Frame) {
|
|
|
|
|
TKUnit.waitUntilReady(() => frame.navigationQueueIsEmpty());
|
|
|
|
|
}
|
|
|
|
|