diff --git a/apps/automated/.gitignore b/apps/automated/.gitignore index 512c68e15a..e9dc6c6f24 100644 --- a/apps/automated/.gitignore +++ b/apps/automated/.gitignore @@ -1 +1,2 @@ !webpack.config.js +hooks \ No newline at end of file diff --git a/apps/automated/package.json b/apps/automated/package.json index e02cd5ac00..511558f4e6 100644 --- a/apps/automated/package.json +++ b/apps/automated/package.json @@ -12,7 +12,7 @@ }, "devDependencies": { "@nativescript/android": "~8.9.0", - "@nativescript/ios": "~8.9.0", + "@nativescript/ios": "esm", "@nativescript/visionos": "~8.9.0", "@nativescript/webpack": "file:../../dist/packages/webpack5", "circular-dependency-plugin": "^5.2.2", diff --git a/apps/automated/project.json b/apps/automated/project.json index 1043e4d290..6e10fc8752 100644 --- a/apps/automated/project.json +++ b/apps/automated/project.json @@ -33,7 +33,12 @@ "forDevice": false, "prepare": false }, - "configurations": {}, + "defaultConfiguration": "main", + "configurations": { + "main": { + "flags": "--env.commonjs" + } + }, "dependsOn": ["^build"] }, "prepare": { diff --git a/apps/automated/src/xml-parser-tests/xml-with-namespaces.xml b/apps/automated/src/assets/xml-with-namespaces.xml similarity index 100% rename from apps/automated/src/xml-parser-tests/xml-with-namespaces.xml rename to apps/automated/src/assets/xml-with-namespaces.xml diff --git a/apps/automated/src/xml-parser-tests/xml.expected b/apps/automated/src/assets/xml.expected similarity index 96% rename from apps/automated/src/xml-parser-tests/xml.expected rename to apps/automated/src/assets/xml.expected index 5cdb47fc44..45a1441970 100644 --- a/apps/automated/src/xml-parser-tests/xml.expected +++ b/apps/automated/src/assets/xml.expected @@ -1 +1 @@ -{"eventType":"StartElement","position":{"line":2,"column":1},"elementName":"DocumentElement","attributes":{"param":"value"}}{"eventType":"StartElement","position":{"line":3,"column":3},"elementName":"First.Element","attributes":{"some.attr":"some.value"}}{"eventType":"Text","position":{"line":3,"column":41},"data":"\n ¶ Some Text ®\n "}{"eventType":"EndElement","position":{"line":5,"column":3},"elementName":"First.Element"}{"eventType":"StartElement","position":{"line":7,"column":3},"elementName":"SecondElement","attributes":{"param2":"something"}}{"eventType":"Text","position":{"line":7,"column":37},"data":"\n Pre-Text "}{"eventType":"StartElement","position":{"line":8,"column":14},"elementName":"Inline"}{"eventType":"Text","position":{"line":8,"column":22},"data":"Inlined text"}{"eventType":"EndElement","position":{"line":8,"column":34},"elementName":"Inline"}{"eventType":"Text","position":{"line":8,"column":43},"data":" Post-text.\n "}{"eventType":"EndElement","position":{"line":9,"column":3},"elementName":"SecondElement"}{"eventType":"StartElement","position":{"line":10,"column":3},"elementName":"entities"}{"eventType":"Text","position":{"line":10,"column":13},"data":"Xml tags begin with \"<\" and end with \">\" Ampersand is & and apostrophe is '"}{"eventType":"EndElement","position":{"line":10,"column":123},"elementName":"entities"}{"eventType":"StartElement","position":{"line":11,"column":3},"elementName":"script"}{"eventType":"CDATA","position":{"line":12,"column":5},"data":"\nfunction sum(a,b)\n{\n return a+b;\n}\n"}{"eventType":"EndElement","position":{"line":18,"column":3},"elementName":"script"}{"eventType":"Comment","position":{"line":19,"column":3},"data":"\n Hello,\n I am a multi-line XML comment.\n"}{"eventType":"EndElement","position":{"line":23,"column":1},"elementName":"DocumentElement"} +{"eventType":"StartElement","position":{"line":2,"column":1},"elementName":"DocumentElement","attributes":{"param":"value"}}{"eventType":"StartElement","position":{"line":3,"column":3},"elementName":"First.Element","attributes":{"some.attr":"some.value"}}{"eventType":"Text","position":{"line":3,"column":41},"data":"\n ¶ Some Text ®\n "}{"eventType":"EndElement","position":{"line":5,"column":3},"elementName":"First.Element"}{"eventType":"StartElement","position":{"line":7,"column":3},"elementName":"SecondElement","attributes":{"param2":"something"}}{"eventType":"Text","position":{"line":7,"column":37},"data":"\n Pre-Text "}{"eventType":"StartElement","position":{"line":8,"column":14},"elementName":"Inline"}{"eventType":"Text","position":{"line":8,"column":22},"data":"Inlined text"}{"eventType":"EndElement","position":{"line":8,"column":34},"elementName":"Inline"}{"eventType":"Text","position":{"line":8,"column":43},"data":" Post-text.\n "}{"eventType":"EndElement","position":{"line":9,"column":3},"elementName":"SecondElement"}{"eventType":"StartElement","position":{"line":10,"column":3},"elementName":"entities"}{"eventType":"Text","position":{"line":10,"column":13},"data":"Xml tags begin with \"<\" and end with \">\" Ampersand is & and apostrophe is '"}{"eventType":"EndElement","position":{"line":10,"column":123},"elementName":"entities"}{"eventType":"StartElement","position":{"line":11,"column":3},"elementName":"script"}{"eventType":"CDATA","position":{"line":12,"column":5},"data":"\nfunction sum(a,b)\n{\n return a+b;\n}\n"}{"eventType":"EndElement","position":{"line":18,"column":3},"elementName":"script"}{"eventType":"Comment","position":{"line":19,"column":3},"data":"\n Hello,\n I am a multi-line XML comment.\n"}{"eventType":"EndElement","position":{"line":23,"column":1},"elementName":"DocumentElement"} \ No newline at end of file diff --git a/apps/automated/src/xml-parser-tests/xml.xml b/apps/automated/src/assets/xml.xml similarity index 96% rename from apps/automated/src/xml-parser-tests/xml.xml rename to apps/automated/src/assets/xml.xml index 93a55b0186..3b9a16b9a5 100644 --- a/apps/automated/src/xml-parser-tests/xml.xml +++ b/apps/automated/src/assets/xml.xml @@ -20,4 +20,4 @@ function sum(a,b) Hello, I am a multi-line XML comment. --> - + \ No newline at end of file diff --git a/apps/automated/src/debugger/dom-node-tests.ts b/apps/automated/src/debugger/dom-node-tests.ts index 52b8b8ad88..80d76e21c4 100644 --- a/apps/automated/src/debugger/dom-node-tests.ts +++ b/apps/automated/src/debugger/dom-node-tests.ts @@ -1,15 +1,9 @@ import { assert, assertEqual } from '../tk-unit'; -import { DOMNode } from '@nativescript/core/debugger/dom-node'; +import { DOMNode } from '@nativescript/core/debugger/dom-types'; import { attachDOMInspectorCommandCallbacks, attachCSSInspectorCommandCallbacks, attachDOMInspectorEventCallbacks } from '@nativescript/core/debugger/devtools-elements'; import { InspectorCommands, InspectorEvents } from '@nativescript/core/debugger/devtools-elements'; -import { unsetValue } from '@nativescript/core/ui/core/properties'; -import { Button } from '@nativescript/core/ui/button'; -import { Slider } from '@nativescript/core/ui/slider'; -import { Label } from '@nativescript/core/ui/label'; +import { unsetValue, Button, Slider, Label, TextView, StackLayout, isAndroid } from '@nativescript/core'; import { textProperty } from '@nativescript/core/ui/text-base'; -import { TextView } from '@nativescript/core/ui/text-view'; -import { StackLayout } from '@nativescript/core/ui/layouts/stack-layout'; -import { isAndroid } from '@nativescript/core/platform'; let originalInspectorGlobal: InspectorCommands & InspectorEvents; diff --git a/apps/automated/src/file-system/file-system-tests.ts b/apps/automated/src/file-system/file-system-tests.ts index 559d3126cc..b78254ae01 100644 --- a/apps/automated/src/file-system/file-system-tests.ts +++ b/apps/automated/src/file-system/file-system-tests.ts @@ -186,15 +186,15 @@ export var testFileRead = function () { // << file-system-example-text }; -export var testFileReadWriteBinary = function () { +export function testFileReadWriteBinary() { // >> file-system-read-binary - var fileName = 'logo.png'; - var error; + const fileName = 'logo.png'; + let error; + const appFolder = fs.knownFolders.currentApp().path; + const sourceFile = fs.File.fromPath(appFolder + '/assets/' + fileName); + const destinationFile = fs.knownFolders.documents().getFile(fileName); - var sourceFile = fs.File.fromPath(__dirname + '/assets/' + fileName); - var destinationFile = fs.knownFolders.documents().getFile(fileName); - - var source = sourceFile.readSync((e) => { + const source = sourceFile.readSync((e) => { error = e; }); @@ -203,7 +203,7 @@ export var testFileReadWriteBinary = function () { }); // >> (hide) - var destination = destinationFile.readSync((e) => { + const destination = destinationFile.readSync((e) => { error = e; }); TKUnit.assertNull(error); @@ -216,14 +216,14 @@ export var testFileReadWriteBinary = function () { destinationFile.removeSync(); // << (hide) // << file-system-read-binary -}; +} -export var testFileReadWriteBinaryAsync = function () { +export function testFileReadWriteBinaryAsync() { // >> file-system-read-binary-async - var fileName = 'logo.png'; - - var sourceFile = fs.File.fromPath(__dirname + '/assets/' + fileName); - var destinationFile = fs.knownFolders.documents().getFile(fileName); + const fileName = 'logo.png'; + const appFolder = fs.knownFolders.currentApp().path; + const sourceFile = fs.File.fromPath(appFolder + '/assets/' + fileName); + const destinationFile = fs.knownFolders.documents().getFile(fileName); // Read the file sourceFile.read().then( @@ -263,7 +263,7 @@ export var testFileReadWriteBinaryAsync = function () { }, ); // << file-system-read-binary-async -}; +} export var testGetKnownFolders = function () { // >> file-system-known-folders @@ -425,11 +425,11 @@ export var testFileNameExtension = function () { var file = documents.getFile('Test.txt'); // Getting the file name "Test.txt". var fileName = file.name; - // Getting the file extension ".txt". + // Getting the file extension "txt". var fileExtension = file.extension; // >> (hide) TKUnit.assert(fileName === 'Test.txt', 'Wrong file name.'); - TKUnit.assert(fileExtension === '.txt', 'Wrong extension.'); + TKUnit.assert(fileExtension === 'txt', 'Wrong extension.'); file.remove(); // << (hide) // << file-system-extension @@ -633,7 +633,7 @@ export function test_FSEntity_Properties() { var documents = fs.knownFolders.documents(); var file = documents.getFile('Test_File.txt'); - TKUnit.assert(file.extension === '.txt', 'FileEntity.extension not working.'); + TKUnit.assert(file.extension === 'txt', 'FileEntity.extension not working.'); TKUnit.assert(file.isLocked === false, 'FileEntity.isLocked not working.'); TKUnit.assert(file.lastModified instanceof Date, 'FileEntity.lastModified not working.'); TKUnit.assert(file.size === 0, 'FileEntity.size not working.'); @@ -746,7 +746,7 @@ export function testAndroidCreate() { export function test_FileAppend(done) { const content = 'Hello World'; - const hello_world = global.isIOS ? NSString.stringWithString(content).dataUsingEncoding(NSUTF8StringEncoding) : new java.lang.String(content).getBytes('UTF-8'); + const hello_world = __APPLE__ ? NSString.stringWithString(content).dataUsingEncoding(NSUTF8StringEncoding) : new java.lang.String(content).getBytes('UTF-8'); const file = fs.File.fromPath(fs.path.join(fs.knownFolders.temp().path, `${Date.now()}-app.txt`)); file .appendText('Hello') diff --git a/apps/automated/src/globals/globals-tests.ts b/apps/automated/src/globals/globals-tests.ts index 65c10e14d4..9bd0244651 100644 --- a/apps/automated/src/globals/globals-tests.ts +++ b/apps/automated/src/globals/globals-tests.ts @@ -23,8 +23,8 @@ export function test_global_registerModule() { TKUnit.assert(typeof global.registerModule === 'function', 'global.registerModule not a function'); } -export function test_global_registerWebpackModules() { - TKUnit.assert(typeof global.registerWebpackModules === 'function', 'global.registerWebpackModules not a function'); +export function test_global_registerBundlerModules() { + TKUnit.assert(typeof global.registerBundlerModules === 'function', 'global.registerBundlerModules not a function'); } export function test_global_loadModule() { diff --git a/apps/automated/src/navigation/custom-transition.ios.ts b/apps/automated/src/navigation/custom-transition.ios.ts index 16a0138899..644b9c4743 100644 --- a/apps/automated/src/navigation/custom-transition.ios.ts +++ b/apps/automated/src/navigation/custom-transition.ios.ts @@ -1,5 +1,4 @@ import { PageTransition, SharedTransition, SharedTransitionAnimationType, SharedTransitionHelper, Transition, Utils } from '@nativescript/core'; -import { CORE_ANIMATION_DEFAULTS } from '@nativescript/core/utils'; export class CustomTransition extends Transition { constructor(duration: number, curve: any) { @@ -32,7 +31,7 @@ export class CustomTransition extends Transition { }, (finished) => { transitionContext.completeTransition(finished); - } + }, ); } } @@ -90,7 +89,7 @@ class PageTransitionController extends NSObject implements UIViewControllerAnima } } } - return CORE_ANIMATION_DEFAULTS.duration; + return Utils.CORE_ANIMATION_DEFAULTS.duration; } animateTransition(transitionContext: UIViewControllerContextTransitioning): void { diff --git a/apps/automated/src/pages/property-bindings.ts b/apps/automated/src/pages/property-bindings.ts index 12a9ec9fcd..cb7c3f8bca 100644 --- a/apps/automated/src/pages/property-bindings.ts +++ b/apps/automated/src/pages/property-bindings.ts @@ -8,7 +8,7 @@ import { Trace } from '@nativescript/core'; import * as gridModule from '@nativescript/core/ui/layouts/grid-layout'; import * as sliders from '@nativescript/core/ui/slider'; import * as switches from '@nativescript/core/ui/switch'; -import * as bindable from '@nativescript/core/ui/core/bindable'; +import type { BindingOptions } from '@nativescript/core/ui/core/bindable/bindable-types'; Trace.enable(); //Trace.setCategories(Trace.categories.Style + " ," + Trace.categories.Binding); @@ -64,7 +64,7 @@ export function createPage() { slider.value = desc.value; stack.addChild(slider); - var options: bindable.BindingOptions = { + var options: BindingOptions = { sourceProperty: 'value', targetProperty: desc.name, }; @@ -82,7 +82,7 @@ export function createPage() { sw.horizontalAlignment = 'left'; stack.addChild(sw); - var options: bindable.BindingOptions = { + var options: BindingOptions = { sourceProperty: 'checked', targetProperty: desc.name, }; @@ -99,7 +99,7 @@ export function createPage() { txt.text = desc.value; stack.addChild(txt); - var options: bindable.BindingOptions = { + var options: BindingOptions = { sourceProperty: 'text', targetProperty: desc.name, }; diff --git a/apps/automated/src/test-runner.ts b/apps/automated/src/test-runner.ts index 33a4c6858e..bd507b7170 100644 --- a/apps/automated/src/test-runner.ts +++ b/apps/automated/src/test-runner.ts @@ -2,7 +2,7 @@ import * as TKUnit from './tk-unit'; import './ui-test'; -import { isIOS, isAndroid, Application, Device, platformNames, Trace, Button, Frame, StackLayout, Page, TextView, Utils, Color } from '@nativescript/core'; +import { isAndroid, Device, platformNames, Trace, Button, Frame, StackLayout, Page, TextView, Utils, Color } from '@nativescript/core'; Frame.defaultAnimatedNavigation = false; export function isRunningOnEmulator(): boolean { @@ -147,7 +147,7 @@ import * as scrollViewSafeAreaTests from './ui/scroll-view/scroll-view-safe-area import * as repeaterSafeAreaTests from './ui/repeater/repeater-safe-area-tests'; import * as webViewSafeAreaTests from './ui/web-view/web-view-safe-area-tests'; -if (isIOS && Utils.ios.MajorVersion > 10) { +if (__APPLE__ && Utils.SDK_VERSION > 10) { allTests['SAFEAREALAYOUT'] = safeAreaLayoutTests; allTests['SAFEAREA-LISTVIEW'] = safeAreaListViewtTests; allTests['SAFEAREA-SCROLL-VIEW'] = scrollViewSafeAreaTests; diff --git a/apps/automated/src/tk-unit.ts b/apps/automated/src/tk-unit.ts index c875f60f4c..3c79c6dffc 100644 --- a/apps/automated/src/tk-unit.ts +++ b/apps/automated/src/tk-unit.ts @@ -11,8 +11,7 @@ */ -import { isIOS, Trace, Device } from '@nativescript/core'; -import * as types from '@nativescript/core/utils/types'; +import { Trace, Device, Utils } from '@nativescript/core'; const sdkVersion = parseInt(Device.sdkVersion); @@ -172,10 +171,10 @@ export function assertFalse(test: boolean, message?: string) { export function assertNotEqual(actual: any, expected: any, message?: string) { let equals = false; - if (types.isUndefined(actual) && types.isUndefined(expected)) { + if (Utils.isUndefined(actual) && Utils.isUndefined(expected)) { equals = true; - } else if (!types.isNullOrUndefined(actual) && !types.isNullOrUndefined(expected)) { - if (types.isFunction(actual.equals)) { + } else if (!Utils.isNullOrUndefined(actual) && !Utils.isNullOrUndefined(expected)) { + if (Utils.isFunction(actual.equals)) { // Use the equals method if (actual.equals(expected)) { equals = true; @@ -191,7 +190,7 @@ export function assertNotEqual(actual: any, expected: any, message?: string) { } export function assertEqual(actual: T, expected: T, message: string = '') { - if (!types.isNullOrUndefined(actual) && !types.isNullOrUndefined(expected) && types.getClass(actual) === types.getClass(expected) && types.isFunction((actual).equals)) { + if (!Utils.isNullOrUndefined(actual) && !Utils.isNullOrUndefined(expected) && Utils.getClass(actual) === Utils.getClass(expected) && Utils.isFunction((actual).equals)) { // Use the equals method if (!(actual).equals(expected)) { throw new Error(`${message} Actual: <${actual}>(${typeof actual}). Expected: <${expected}>(${typeof expected})`); @@ -352,7 +351,7 @@ export function waitUntilReady(isReady: () => boolean, timeoutSec: number = 5, s return; } - if (isIOS) { + if (__APPLE__) { const timeoutMs = timeoutSec * 1000; let totalWaitTime = 0; while (true) { diff --git a/apps/automated/src/ui-helper.ts b/apps/automated/src/ui-helper.ts index 487ba37cf0..3e1879dbec 100644 --- a/apps/automated/src/ui-helper.ts +++ b/apps/automated/src/ui-helper.ts @@ -1,4 +1,4 @@ -import { Color, Button, FormattedString, Span, ActionBar, Builder, isIOS, unsetValue, View, ViewBase, Frame, NavigationEntry, LayoutBase, StackLayout, Page, TabView, TabViewItem, Utils } from '@nativescript/core'; +import { Color, Button, FormattedString, Span, ActionBar, Builder, unsetValue, View, ViewBase, Frame, NavigationEntry, LayoutBase, StackLayout, Page, TabView, TabViewItem, Utils } from '@nativescript/core'; import * as TKUnit from './tk-unit'; @@ -255,7 +255,7 @@ export function assertTabSelectedTabTextColor(testView: ViewBase, hexColor: stri } export function forceGC() { - if (isIOS) { + if (__APPLE__) { /* tslint:disable:no-unused-expression */ // Could cause GC on the next call. new ArrayBuffer(4 * 1024 * 1024); @@ -295,7 +295,7 @@ export function _generateFormattedString(): FormattedString { export function nativeView_recycling_test(createNew: () => View, createLayout?: () => LayoutBase, nativeGetters?: Map any>, customSetters?: Map) { return; - // if (isIOS) { + // if (__APPLE__) { // // recycling not implemented yet. // return; // } diff --git a/apps/automated/src/ui/action-bar/action-bar-tests-common.ts b/apps/automated/src/ui/action-bar/action-bar-tests-common.ts index b0abe4c7ed..708414ff1f 100644 --- a/apps/automated/src/ui/action-bar/action-bar-tests-common.ts +++ b/apps/automated/src/ui/action-bar/action-bar-tests-common.ts @@ -1,16 +1,6 @@ import * as TKUnit from '../../tk-unit'; import * as helper from '../../ui-helper'; -import { Builder } from '@nativescript/core/ui/builder'; -import { Label } from '@nativescript/core/ui/label'; -import { Button } from '@nativescript/core/ui/button'; -import { Page } from '@nativescript/core/ui/page'; -import { View, isIOS } from '@nativescript/core'; -import { fromObject } from '@nativescript/core/data/observable'; -import { Frame } from '@nativescript/core/ui/frame'; - -// >> actionbar-common-require -import * as actionBarModule from '@nativescript/core/ui/action-bar'; -// << actionbar-common-require +import { View, fromObject, Frame, Page, Button, Label, Builder, ActionItem, ActionBar } from '@nativescript/core'; export function test_actionItem_inherit_bindingContext() { let page: Page; @@ -20,7 +10,7 @@ export function test_actionItem_inherit_bindingContext() { const pageFactory = function (): Page { page = new Page(); page.bindingContext = context; - const actionItem = new actionBarModule.ActionItem(); + const actionItem = new ActionItem(); actionItem.bind({ sourceProperty: 'text', @@ -164,7 +154,7 @@ export function test_Setting_ActionItems_doesnt_thrown() { const pageFactory = function (): Page { page = new Page(); - const actionItem = new actionBarModule.ActionItem(); + const actionItem = new ActionItem(); actionItem.text = 'Item'; page.actionBar.actionItems.addItem(actionItem); @@ -286,12 +276,12 @@ export function test_ActionBarVisibility_Never_ShouldNotShowDeclaredActionBar() - ` + `, ); helper.navigate(() => page); let actionBarHidden = false; - if (isIOS) { + if (__APPLE__) { actionBarHidden = page.actionBar.nativeView.hidden; } else { actionBarHidden = !page.actionBar.nativeView.isShown(); @@ -314,12 +304,12 @@ export function test_ActionBarVisibility_Always_ShouldShownHiddenActionBar() { - ` + `, ); helper.navigate(() => page); let actionBarHidden = false; - if (isIOS) { + if (__APPLE__) { actionBarHidden = page.actionBar.nativeView.hidden; } else { actionBarHidden = !page.actionBar.nativeView.isShown(); @@ -342,12 +332,12 @@ export function test_ActionBarVisibility_Auto_ShouldRespectPageActionBarHiddenPr - ` + `, ); helper.navigate(() => page); let actionBarHidden = false; - if (isIOS) { + if (__APPLE__) { actionBarHidden = page.actionBar.nativeView.hidden; } else { actionBarHidden = !page.actionBar.nativeView.isShown(); @@ -391,5 +381,5 @@ export function createPageAndNavigate() { } export function test_recycling() { - helper.nativeView_recycling_test(() => new actionBarModule.ActionBar()); + helper.nativeView_recycling_test(() => new ActionBar()); } diff --git a/apps/automated/src/ui/activity-indicator/activity-indicator-tests.ts b/apps/automated/src/ui/activity-indicator/activity-indicator-tests.ts index 2b9c32a3a4..b06a470ec8 100644 --- a/apps/automated/src/ui/activity-indicator/activity-indicator-tests.ts +++ b/apps/automated/src/ui/activity-indicator/activity-indicator-tests.ts @@ -49,8 +49,8 @@ export function test_set_TNS_value_updates_native_value() { } // Uncomment this when find way to check android Drawable color set by setColorFilter() method. -if (__APPLE__) { - exports.test_set_color = function () { +export function test_set_color() { + if (__APPLE__) { var ai = new activityIndicatorModule.ActivityIndicator(); ai.color = new color.Color('red'); @@ -59,7 +59,7 @@ if (__APPLE__) { } helper.buildUIAndRunTest(ai, testAction); - }; + } } // This method is only for the code snippet diff --git a/apps/automated/src/ui/animation/animation-tests.ts b/apps/automated/src/ui/animation/animation-tests.ts index ad75839ce4..75bbbd6f0d 100644 --- a/apps/automated/src/ui/animation/animation-tests.ts +++ b/apps/automated/src/ui/animation/animation-tests.ts @@ -1,11 +1,6 @@ import * as TKUnit from '../../tk-unit'; import * as helper from '../../ui-helper'; -import * as viewModule from '@nativescript/core/ui/core/view'; -import { Label } from '@nativescript/core/ui/label'; -import { StackLayout } from '@nativescript/core/ui/layouts/stack-layout'; -import * as colorModule from '@nativescript/core/color'; -import { CoreTypes, PercentLength } from '@nativescript/core'; -import { AnimationPromise, AnimationDefinition, Animation } from '@nativescript/core/ui/animation'; +import { AnimationPromise, AnimationDefinition, Animation, CoreTypes, PercentLength, Label, StackLayout, View, Color } from '@nativescript/core'; // >> animation-require // import * as animation from '@nativescript/core/ui/animation'; @@ -38,7 +33,7 @@ export function test_AnimatingProperties(done) { label .animate({ opacity: 0.75, - backgroundColor: new colorModule.Color('Red'), + backgroundColor: new Color('Red'), translate: { x: 100, y: 100 }, scale: { x: 2, y: 2 }, rotate: 180, @@ -79,7 +74,7 @@ export function test_PlayRejectsWhenAlreadyPlayingAnimation(done) { if (e === 'Animation is already playing.') { done(); } - } + }, ); } @@ -269,7 +264,7 @@ export function test_AnimateOpacity(done) { export function test_AnimateOpacity_ShouldThrow_IfNotNumber() { var label = new Label(); - helper.buildUIAndRunTest(label, (views: Array) => { + helper.buildUIAndRunTest(label, (views: Array) => { TKUnit.assertThrows(() => { label.animate({ opacity: '0.75' }); }, 'Setting opacity to a non number should throw.'); @@ -278,7 +273,7 @@ export function test_AnimateOpacity_ShouldThrow_IfNotNumber() { export function test_AnimateDelay_ShouldThrow_IfNotNumber() { var label = new Label(); - helper.buildUIAndRunTest(label, (views: Array) => { + helper.buildUIAndRunTest(label, (views: Array) => { TKUnit.assertThrows(() => { label.animate({ delay: '1' }); }, 'Setting delay to a non number should throw.'); @@ -287,7 +282,7 @@ export function test_AnimateDelay_ShouldThrow_IfNotNumber() { export function test_AnimateDuration_ShouldThrow_IfNotNumber() { var label = new Label(); - helper.buildUIAndRunTest(label, (views: Array) => { + helper.buildUIAndRunTest(label, (views: Array) => { TKUnit.assertThrows(() => { label.animate({ duration: '1' }); }, 'Setting duration to a non number should throw.'); @@ -296,7 +291,7 @@ export function test_AnimateDuration_ShouldThrow_IfNotNumber() { export function test_AnimateIterations_ShouldThrow_IfNotNumber() { var label = new Label(); - helper.buildUIAndRunTest(label, (views: Array) => { + helper.buildUIAndRunTest(label, (views: Array) => { TKUnit.assertThrows(() => { label.animate({ iterations: '1' }); }, 'Setting iterations to a non number should throw.'); @@ -305,7 +300,7 @@ export function test_AnimateIterations_ShouldThrow_IfNotNumber() { export function test_AnimateRotate_ShouldThrow_IfNotNumber() { var label = new Label(); - helper.buildUIAndRunTest(label, (views: Array) => { + helper.buildUIAndRunTest(label, (views: Array) => { TKUnit.assertThrows(() => { label.animate({ rotate: '1' }); }, 'Setting rotate to a non number should throw.'); @@ -314,7 +309,7 @@ export function test_AnimateRotate_ShouldThrow_IfNotNumber() { export function test_AnimateScale_ShouldThrow_IfNotPair() { var label = new Label(); - helper.buildUIAndRunTest(label, (views: Array) => { + helper.buildUIAndRunTest(label, (views: Array) => { TKUnit.assertThrows(() => { label.animate({ scale: '1' }); }, 'Setting scale to a non Pair should throw.'); @@ -323,7 +318,7 @@ export function test_AnimateScale_ShouldThrow_IfNotPair() { export function test_AnimateTranslate_ShouldThrow_IfNotPair() { var label = new Label(); - helper.buildUIAndRunTest(label, (views: Array) => { + helper.buildUIAndRunTest(label, (views: Array) => { TKUnit.assertThrows(() => { label.animate({ translate: '1' }); }, 'Setting translate to a non Pair should throw.'); @@ -332,7 +327,7 @@ export function test_AnimateTranslate_ShouldThrow_IfNotPair() { export function test_AnimateBackgroundColor_ShouldThrow_IfNotValidColorStringOrColor() { var label = new Label(); - helper.buildUIAndRunTest(label, (views: Array) => { + helper.buildUIAndRunTest(label, (views: Array) => { TKUnit.assertThrows(() => { label.animate({ backgroundColor: 'test' }); }, 'Setting backgroundColor to a not valid color string or Color should throw.'); @@ -341,12 +336,12 @@ export function test_AnimateBackgroundColor_ShouldThrow_IfNotValidColorStringOrC export function test_AnimateBackgroundColor(done) { let label = prepareTest(); - var red = new colorModule.Color('Red'); + var red = new Color('Red'); label .animate({ backgroundColor: red, duration: 5 }) .then(() => { - TKUnit.assert((label.backgroundColor).equals(red)); + TKUnit.assert((label.backgroundColor).equals(red)); done(); }) .catch((e) => { @@ -357,12 +352,12 @@ export function test_AnimateBackgroundColor(done) { export function test_AnimateBackgroundColor_FromString(done) { let label = prepareTest(); var expected = 'Red'; - var clr = new colorModule.Color(expected); + var clr = new Color(expected); label .animate({ backgroundColor: expected, duration: 5 }) .then(() => { - TKUnit.assert((label.backgroundColor).equals(clr)); + TKUnit.assert((label.backgroundColor).equals(clr)); done(); }) .catch((e) => { @@ -505,7 +500,7 @@ export function test_AnimateExtent_Should_AcceptNumberValuesAsDip(done) { export function test_AnimateExtent_Should_ThrowIfCannotParsePercentLength() { const label = new Label(); - helper.buildUIAndRunTest(label, (views: Array) => { + helper.buildUIAndRunTest(label, (views: Array) => { TKUnit.assertThrows(() => { label.animate({ width: '-frog%' }); }, 'Invalid percent string should throw'); @@ -610,7 +605,7 @@ export function test_PlayPromiseIsResolvedWhenAnimationFinishes(done) { function onRejected(e) { TKUnit.assert(false, 'Animation play promise should be resolved, not rejected.'); done(e); - } + }, ); } @@ -627,14 +622,14 @@ export function test_PlayPromiseIsRejectedWhenAnimationIsCancelled(done) { function onRejected(e) { TKUnit.assert(animation.isPlaying === false, 'Animation.isPlaying should be false when animation play promise is rejected.'); done(); - } + }, ); animation.cancel(); } -function assertIOSNativeTransformIsCorrect(view: viewModule.View) { - if (global.isIOS) { +function assertIOSNativeTransformIsCorrect(view: View) { + if (__APPLE__) { var errorMessage = (require('@nativescript/core/ui/animation'))._getTransformMismatchErrorMessage(view); if (errorMessage) { TKUnit.assert(false, errorMessage); diff --git a/apps/automated/src/ui/button/button-tests.ts b/apps/automated/src/ui/button/button-tests.ts index 6161b4feaf..07f9a1b112 100644 --- a/apps/automated/src/ui/button/button-tests.ts +++ b/apps/automated/src/ui/button/button-tests.ts @@ -1,12 +1,7 @@ import * as TKUnit from '../../tk-unit'; import * as helper from '../../ui-helper'; -import { View, EventData, Button, Observable, Color, Page, FormattedString } from '@nativescript/core'; +import { View, EventData, Button, Observable, Color, Page, FormattedString, BindingOptions, Span } from '@nativescript/core'; import * as buttonTestsNative from './button-tests-native'; -import * as spanModule from '@nativescript/core/text/span'; - -// >> button-require-others -import { BindingOptions } from '@nativescript/core/ui/core/bindable'; -// << button-require-others export function test_recycling() { helper.nativeView_recycling_test(() => new Button()); @@ -326,13 +321,13 @@ export var testNativeTextAlignmentFromLocal = function () { }; export var test_WhenFormattedTextPropertyChanges_TextIsUpdated_Button = function () { - var firstSpan = new spanModule.Span(); + var firstSpan = new Span(); firstSpan.fontSize = 10; firstSpan.text = 'First'; - var secondSpan = new spanModule.Span(); + var secondSpan = new Span(); secondSpan.fontSize = 15; secondSpan.text = 'Second'; - var thirdSpan = new spanModule.Span(); + var thirdSpan = new Span(); thirdSpan.fontSize = 20; thirdSpan.text = 'Third'; var formattedString1 = new FormattedString(); @@ -392,7 +387,7 @@ export function test_setting_formattedText_With_UnknownFont_DoesNotCrash() { helper.buildUIAndRunTest(btn, function (views) { TKUnit.waitUntilReady(() => btn.isLayoutValid); - let span = new spanModule.Span(); + let span = new Span(); span.text = 'Login'; let formattedString = new FormattedString(); formattedString.spans.push(span); diff --git a/apps/automated/src/ui/core/bindable/bindable-tests.ts b/apps/automated/src/ui/core/bindable/bindable-tests.ts index 8007ee0ff3..825db61c91 100644 --- a/apps/automated/src/ui/core/bindable/bindable-tests.ts +++ b/apps/automated/src/ui/core/bindable/bindable-tests.ts @@ -1,11 +1,7 @@ -import { Observable, fromObject, fromObjectRecursive } from '@nativescript/core/data/observable'; -import { ViewBase } from '@nativescript/core/ui/core/view-base'; -import { BindingOptions } from '@nativescript/core/ui/core/bindable'; +import { Application, View, Button, Page, StackLayout, Label, TextField, Trace, BindingOptions, ViewBase, Observable, fromObject, fromObjectRecursive, Utils } from '@nativescript/core'; import * as TKUnit from '../../../tk-unit'; -import * as types from '@nativescript/core/utils/types'; import * as helper from '../../../ui-helper'; import * as bindingBuilder from '@nativescript/core/ui/builder/binding-builder'; -import { Application, View, Button, Page, StackLayout, Label, TextField, Trace } from '@nativescript/core'; declare var WeakRef: any; // // For information and examples how to use bindings please refer to special [**Data binding**](../../../../bindings.md) topic. @@ -17,8 +13,8 @@ declare var WeakRef: any; export function test_Bindable_Members() { const obj = new Label(); - TKUnit.assert(types.isDefined(obj.bind), 'Bindable.bind not defined'); - TKUnit.assert(types.isDefined(obj.unbind), 'Bindable.unbind not defined'); + TKUnit.assert(Utils.isDefined(obj.bind), 'Bindable.bind not defined'); + TKUnit.assert(Utils.isDefined(obj.unbind), 'Bindable.unbind not defined'); } export function test_Binding_to_bindingContext_of_View() { @@ -502,7 +498,7 @@ export function test_bindingToNestedPropertyWithValueSyntax() { sourceProperty: '$value.testProperty', targetProperty: 'targetPropertyName', }, - bindingSource + bindingSource, ); TKUnit.assertEqual(testElement.get('targetPropertyName'), 'testValue'); @@ -706,7 +702,7 @@ export function test_UpdatingNestedPropertyViaBinding() { targetProperty: 'text', twoWay: true, }, - viewModel + viewModel, ); const testElement2 = new Label(); @@ -717,7 +713,7 @@ export function test_UpdatingNestedPropertyViaBinding() { targetProperty: 'text', twoWay: true, }, - viewModel + viewModel, ); TKUnit.assertEqual(testElement.get('text'), expectedValue1); @@ -803,7 +799,7 @@ export function test_NestedPropertiesBinding() { targetProperty: 'targetProperty', twoWay: true, }, - viewModel + viewModel, ); TKUnit.assertEqual(target1.get('targetProperty'), expectedValue); @@ -835,7 +831,7 @@ export function test_WrongNestedPropertiesBinding() { targetProperty: 'targetProperty', twoWay: true, }, - viewModel + viewModel, ); TKUnit.assertNotEqual(errorMessage, undefined); @@ -856,7 +852,7 @@ export function test_NestedPropertiesBindingTwoTargets() { targetProperty: 'targetProperty', twoWay: true, }, - viewModel + viewModel, ); const target2 = new Label(); @@ -866,7 +862,7 @@ export function test_NestedPropertiesBindingTwoTargets() { targetProperty: 'targetProp', twoWay: true, }, - viewModel + viewModel, ); TKUnit.assertEqual(target1.get('targetProperty'), expectedText); @@ -897,7 +893,7 @@ export function test_NestedPropertiesBindingTwoTargetsAndSecondChange() { targetProperty: 'targetProperty', twoWay: true, }, - viewModel + viewModel, ); const target2 = new Label(); @@ -907,7 +903,7 @@ export function test_NestedPropertiesBindingTwoTargetsAndSecondChange() { targetProperty: 'targetProp', twoWay: true, }, - viewModel + viewModel, ); TKUnit.assertEqual(target1.get('targetProperty'), expectedText); @@ -948,7 +944,7 @@ export function test_NestedPropertiesBindingTwoTargetsAndRegularChange() { targetProperty: 'targetProperty', twoWay: true, }, - viewModel + viewModel, ); const target2 = new Label(); @@ -958,7 +954,7 @@ export function test_NestedPropertiesBindingTwoTargetsAndRegularChange() { targetProperty: 'targetProp', twoWay: true, }, - viewModel + viewModel, ); TKUnit.assertEqual(target1.get('targetProperty'), expectedText); @@ -998,7 +994,7 @@ export function test_NestedPropertiesBindingTwoTargetsAndReplacingSomeNestedObje targetProperty: 'targetProperty', twoWay: true, }, - viewModel + viewModel, ); const target2 = new Label(); @@ -1008,7 +1004,7 @@ export function test_NestedPropertiesBindingTwoTargetsAndReplacingSomeNestedObje targetProperty: 'targetProp', twoWay: true, }, - viewModel + viewModel, ); TKUnit.assertEqual(target1.get('targetProperty'), expectedText); @@ -1050,7 +1046,7 @@ export function test_NullSourcePropertyShouldNotCrash() { targetProperty: 'targetProp', expression: 'convFunc(field)', }, - model + model, ); TKUnit.assertEqual(target.get('targetProp'), convFunc(expectedValue)); @@ -1123,7 +1119,7 @@ export function test_SupportFunctionsInExpressions() { targetProperty: 'text', expression: "isVisible() ? 'visible' : 'collapsed'", }, - model + model, ); model.set('anyColor', 'blue'); @@ -1151,7 +1147,7 @@ export function test_$ValueSupportWithinExpression() { targetProperty: 'text', expression: "$value.anyColor === 'red' ? 'red' : 'blue'", }, - model + model, ); model.set('anyColor', 'blue'); @@ -1230,7 +1226,7 @@ export function test_BindingToPropertiesWithSameNames() { targetProperty: 'targetProperty', twoWay: true, }, - model + model, ); const target2 = new Label(); @@ -1240,7 +1236,7 @@ export function test_BindingToPropertiesWithSameNames() { targetProperty: 'targetProp', twoWay: true, }, - model + model, ); model.item.set('seconds', model.item.seconds + 1); @@ -1273,7 +1269,7 @@ export function test_BindingToPropertiesWithSameNamesSecondCase() { targetProperty: 'targetProperty', twoWay: true, }, - model + model, ); const target2 = new Label(); @@ -1283,7 +1279,7 @@ export function test_BindingToPropertiesWithSameNamesSecondCase() { targetProperty: 'targetProp', twoWay: true, }, - model + model, ); model.item.set('seconds', model.item.seconds + 1); @@ -1372,7 +1368,7 @@ export function test_Observable_from_nested_json_binds_correctly() { sourceProperty: 'firstObject.secondObject.dummyProperty', targetProperty: 'text', }, - model + model, ); model.get('firstObject').get('secondObject').set('dummyProperty', expectedValue); @@ -1396,7 +1392,7 @@ export function test_Observable_from_nested_json_binds_correctly_when_upper_obje sourceProperty: 'firstObject.secondObject.dummyProperty', targetProperty: 'text', }, - model + model, ); model.get('firstObject').set('secondObject', fromObject({ dummyProperty: expectedValue })); diff --git a/apps/automated/src/ui/frame/frame-tests.android.ts b/apps/automated/src/ui/frame/frame-tests.android.ts index f4df1d9160..0a18547250 100644 --- a/apps/automated/src/ui/frame/frame-tests.android.ts +++ b/apps/automated/src/ui/frame/frame-tests.android.ts @@ -1,7 +1,5 @@ -import { Frame } from '@nativescript/core/ui/frame'; import * as TKUnit from '../../tk-unit'; -import { unsetValue } from '@nativescript/core/ui/core/view'; -import { PercentLength } from '@nativescript/core/ui/styling/style-properties'; +import { PercentLength, unsetValue, Frame } from '@nativescript/core'; export * from './frame-tests-common'; export function test_percent_width_and_height_set_to_page_support() { diff --git a/apps/automated/src/ui/image/image-tests.ts b/apps/automated/src/ui/image/image-tests.ts index 9be0666b9f..875c889e5b 100644 --- a/apps/automated/src/ui/image/image-tests.ts +++ b/apps/automated/src/ui/image/image-tests.ts @@ -15,7 +15,7 @@ import { ImageSource } from '@nativescript/core/image-source'; import * as ViewModule from '@nativescript/core/ui/core/view'; import * as helper from '../../ui-helper'; import * as color from '@nativescript/core/color'; -import * as backgroundModule from '@nativescript/core/ui/styling/background'; +import * as appHelpers from '@nativescript/core/application/helpers-common'; import { Application } from '@nativescript/core'; const imagePath = '~/assets/logo.png'; @@ -23,8 +23,8 @@ export function test_recycling() { helper.nativeView_recycling_test(() => new Image()); } -if (global.isAndroid) { - (backgroundModule).initImageCache(Application.android.startActivity, (backgroundModule).CacheMode.memory); // use memory cache only. +if (__ANDROID__) { + appHelpers.initImageCache(Application.android.startActivity, appHelpers.CacheMode.memory); // use memory cache only. } const expectLayoutRequest = __APPLE__ && Utils.SDK_VERSION >= 18; @@ -65,7 +65,7 @@ function runImageTestSync(image: ImageModule.Image, src: string) { image.src = src; - let imageSourceAvailable = global.isIOS ? !!image.imageSource : true; + let imageSourceAvailable = __APPLE__ ? !!image.imageSource : true; TKUnit.assertFalse(image.isLoading, 'Image.isLoading should be false.'); TKUnit.assertTrue(imageSourceAvailable, 'imageSource should be set.'); } @@ -78,7 +78,7 @@ function runImageTestAsync(image: ImageModule.Image, src: string, done: (e: any) image.off(IMAGE_LOADED_EVENT, handler); try { - let imageSourceAvailable = global.isIOS ? !!image.imageSource : true; + let imageSourceAvailable = __APPLE__ ? !!image.imageSource : true; TKUnit.assertFalse(image.isLoading, 'Image.isLoading should be false.'); TKUnit.assertTrue(imageSourceAvailable, 'imageSource should be set.'); done(null); @@ -255,7 +255,7 @@ export const test_SettingStretch_none = function () { }; function ios(func: T): T { - return global.isIOS ? func : undefined; + return __APPLE__ ? func : undefined; } export const test_SettingImageSourceWhenSizedToParentDoesNotRequestLayout = ios(() => { diff --git a/apps/automated/src/ui/label/label-tests.ts b/apps/automated/src/ui/label/label-tests.ts index 92311ab24d..ada8f29584 100644 --- a/apps/automated/src/ui/label/label-tests.ts +++ b/apps/automated/src/ui/label/label-tests.ts @@ -1,51 +1,34 @@ import * as TKUnit from '../../tk-unit'; import * as testModule from '../../ui-test'; - -//>> label-require -import * as LabelModule from '@nativescript/core/ui/label'; -// << label-require - -import * as types from '@nativescript/core/utils/types'; -import * as colorModule from '@nativescript/core/color'; -import * as utils from '@nativescript/core/utils'; -import * as observableModule from '@nativescript/core/data/observable'; -import * as bindable from '@nativescript/core/ui/core/bindable'; -import { CoreTypes, Span, FormattedString, Utils } from '@nativescript/core'; +import { Label, GridLayout, LayoutBase, StackLayout, BindingOptions, CoreTypes, Span, FormattedString, Utils, Color, Observable, path } from '@nativescript/core'; import * as labelTestsNative from './label-tests-native'; -import * as fs from '@nativescript/core/file-system'; - -import { StackLayout } from '@nativescript/core/ui/layouts/stack-layout'; -import { GridLayout } from '@nativescript/core/ui/layouts/grid-layout'; -import { isIOS, isAndroid, isApple } from '@nativescript/core/platform'; -import { Label } from '@nativescript/core/ui/label'; -import { LayoutBase } from '@nativescript/core/ui/layouts/layout-base'; import * as helper from '../../ui-helper'; const testDir = 'ui/label'; const expectLayoutRequest = __APPLE__ && Utils.SDK_VERSION >= 18; -export class LabelTest extends testModule.UITest { - public create(): LabelModule.Label { - const label = new LabelModule.Label(); +export class LabelTest extends testModule.UITest