From efdd7e625c04e9b01a9d966883f0dccc6dfd61db Mon Sep 17 00:00:00 2001 From: Alexander Vakrilov Date: Wed, 21 Aug 2019 16:45:00 +0300 Subject: [PATCH] fix-next: Add accidentally removed System.import (#7706) --- tests/app/globals/globals-tests.ts | 48 +++++++++++++++++++ tests/app/test-runner.ts | 3 ++ tns-core-modules/globals/core/globals-core.ts | 12 +++++ 3 files changed, 63 insertions(+) create mode 100644 tests/app/globals/globals-tests.ts diff --git a/tests/app/globals/globals-tests.ts b/tests/app/globals/globals-tests.ts new file mode 100644 index 000000000..48ba9d59d --- /dev/null +++ b/tests/app/globals/globals-tests.ts @@ -0,0 +1,48 @@ +import "tns-core-modules/globals"; +import * as TKUnit from "../tk-unit"; + +declare var System: any; +export function test_global_system_import() { + TKUnit.assert(System, "System not defined"); + TKUnit.assert(typeof System.import === "function", "System.import not a function"); + + TKUnit.assert((global).System, "global.System not defined"); + TKUnit.assert(typeof (global).System.import === "function", "global.System.import not a function"); +} + +export function test_global_zonedCallback() { + TKUnit.assert(typeof zonedCallback === "function", "zonedCallback not defined"); + TKUnit.assert(typeof global.zonedCallback === "function", "global.zonedCallback not a function"); +} + +export function test_global_moduleMerge() { + TKUnit.assert(typeof global.moduleMerge === "function", "global.moduleMerge not a function"); +} + +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_loadModule() { + TKUnit.assert(typeof global.loadModule === "function", "global.loadModule not a function"); +} + +export function test_global_moduleExists() { + TKUnit.assert(typeof global.moduleExists === "function", "global.moduleExists not a function"); +} + +export function test_global_getRegisteredModules() { + TKUnit.assert(typeof global.getRegisteredModules === "function", "global.getRegisteredModules not a function"); +} + +export function test_global_Deprecated() { + TKUnit.assert(typeof global.Deprecated === "function", "global.Deprecated not a function"); +} + +export function test_global_Experimental() { + TKUnit.assert(typeof global.Experimental === "function", "global.Experimental not a function"); +} diff --git a/tests/app/test-runner.ts b/tests/app/test-runner.ts index f69f899f1..8bc3ef189 100644 --- a/tests/app/test-runner.ts +++ b/tests/app/test-runner.ts @@ -31,6 +31,9 @@ export function isRunningOnEmulator(): boolean { export const allTests = {}; +import * as globalsTests from "./globals/globals-tests"; +allTests["GLOBALS"] = globalsTests; + import * as domNodeTest from "./debugger/dom-node-tests"; allTests["DOM-NODE"] = domNodeTest; diff --git a/tns-core-modules/globals/core/globals-core.ts b/tns-core-modules/globals/core/globals-core.ts index dfa37d4df..17d17f25b 100644 --- a/tns-core-modules/globals/core/globals-core.ts +++ b/tns-core-modules/globals/core/globals-core.ts @@ -23,3 +23,15 @@ global.zonedCallback = function (callback: Function): Function { return callback; } }; + +(global).System = { + import(path) { + return new Promise((resolve, reject) => { + try { + resolve(global.require(path)); + } catch (e) { + reject(e); + } + }); + } +};