diff --git a/Import/index.js b/Import/index.js index 867c071..f73c7a2 100644 --- a/Import/index.js +++ b/Import/index.js @@ -1,17 +1,13 @@ describe("TNS import", function () { - // The V8-based iOS runtime (@nativescript/ios); the legacy JSC runtime exposes TNSRuntime. - // It does not support ES `import` statements in CommonJS (.js) modules - - // apps are expected to be transpiled/bundled. - var isV8iOS = !!global.NSObject && !global.TNSRuntime; - + beforeEach(TNSClearOutput); afterEach(TNSClearOutput); - (isV8iOS ? xit : it)("JSON files", function () { + it("JSON files", function () { require("./ImportJSON"); expect(TNSGetOutput()).toBe("testValue"); }); - (isV8iOS ? xit : it)("CommonJS", function () { + it("CommonJS", function () { require("./ImportCommonJS"); expect(TNSGetOutput()).toBe("42"); }); diff --git a/Require/index.js b/Require/index.js index b858f03..9c80b7a 100644 --- a/Require/index.js +++ b/Require/index.js @@ -1,8 +1,5 @@ describe("TNS require", function () { - // The V8-based iOS runtime (@nativescript/ios); the legacy JSC runtime exposes TNSRuntime - var isV8iOS = !!global.NSObject && !global.TNSRuntime; - beforeEach(TNSClearOutput); afterEach(TNSClearOutput); @@ -187,15 +184,13 @@ describe("TNS require", function () { expect(TNSGetOutput()).toBe(expected); }); - // In debug builds the v8-ios runtime suppresses module load errors instead of - // throwing, to keep the app alive for hot-reload, so these cannot be asserted there. - (isV8iOS ? xit : it)("can can catch a syntax error in module", function () { + it("can can catch a syntax error in module", function () { require("./SyntaxErrorInModule"); var expected = 'main started SyntaxError main ended'; expect(TNSGetOutput()).toBe(expected); }); - (isV8iOS ? xit : it)("can can catch a runtime error in module", function () { + it("can can catch a runtime error in module", function () { require("./RuntimeErrorInModule"); var expected = 'main started ReferenceError main ended'; expect(TNSGetOutput()).toBe(expected); @@ -219,7 +214,7 @@ describe("TNS require", function () { expect(result.title).toBe(expected); }); - xit("require directory with index.json and no package.json", function () { + it("require directory with index.json and no package.json", function () { var result = require("./DirectoryWithIndexJson"); var expected = 'string from index.json'; @@ -313,19 +308,17 @@ describe("TNS require", function () { }); // node_modules tests - // The v8-ios runtime does not implement node_modules hierarchy traversal - // (apps are expected to be bundled), so these are skipped there. - (isV8iOS ? xit : it)('should traverse correctly through node_modules till outer module is found', function () { + it('should traverse correctly through node_modules till outer module is found', function () { require("./node_modules/FindInOuterNodeModules"); var expected = 'main started in FindInOuterNodeModules module main ended'; expect(TNSGetOutput()).toBe(expected); }); - (isV8iOS ? xit : it)('should traverse correctly through any folders till outer module is found', function () { + it('should traverse correctly through any folders till outer module is found', function () { require("./node_modules/FindsIndexJs"); var expected = 'main started in FindsIndexJs module main ended'; expect(TNSGetOutput()).toBe(expected); }); - (isV8iOS ? xit : it)('should traverse correctly through inner node modules first', function () { + it('should traverse correctly through inner node modules first', function () { require("./node_modules/FindsInnerNodeModulesFirst"); var expected = 'main started in FindsInnerNodeModulesFirst module main ended'; expect(TNSGetOutput()).toBe(expected); @@ -335,7 +328,7 @@ describe("TNS require", function () { var expected = 'main started from module folder main ended'; expect(TNSGetOutput()).toBe(expected); }); - (isV8iOS ? xit : it)('should traverse node_modules and find package.json if present', function () { + it('should traverse node_modules and find package.json if present', function () { require("./node_modules/FindsPackageJson"); var expected = 'main started in FindsPackageJson module main ended'; expect(TNSGetOutput()).toBe(expected); @@ -346,7 +339,7 @@ describe("TNS require", function () { expect(TNSGetOutput()).toBe(expected); }); - (isV8iOS ? xit : it)('should check node_modules hierarchy before checking app/tns_modules', function () { + it('should check node_modules hierarchy before checking app/tns_modules', function () { var actual = require("./node_modules/NodeModulesAndTnsModulesConflict"); var expected = 'package installed in local node_modules folder'; expect(actual).toBe(expected); diff --git a/Workers/WorkerEntryUrl.mjs b/Workers/WorkerEntryUrl.mjs new file mode 100644 index 0000000..24d7a73 --- /dev/null +++ b/Workers/WorkerEntryUrl.mjs @@ -0,0 +1 @@ +export const evalWorkerUrl = new URL("./EvalWorker.js", import.meta.url); diff --git a/Workers/index.js b/Workers/index.js index ba9e6cf..f15fc18 100644 --- a/Workers/index.js +++ b/Workers/index.js @@ -4,6 +4,9 @@ describe("TNS Workers", () => { // Runtimes that serialize worker messages with the V8 structured clone // serializer (Android and @nativescript/ios); the legacy JSC runtime uses JSON var isStructuredClone = !global.NSObject || isV8iOS; + // Runtimes that load modules through runtime-common (Android and + // @nativescript/ios) + var isRuntimeCommon = !global.NSObject || isV8iOS; let expectedAliveRuntimes = 1; // Main thread's TNSRuntime var originalTimeout; var DEFAULT_TIMEOUT_BEFORE_ASSERT = 500; @@ -68,6 +71,51 @@ describe("TNS Workers", () => { }); } + // Bundlers name a worker as new Worker(new URL("./w.js", import.meta.url)). + (isRuntimeCommon ? it : xit)("Should run an entry named by a file: URL from import.meta.url", (done) => { + var url = require("./WorkerEntryUrl.mjs").evalWorkerUrl; + expect(url.protocol).toBe("file:"); + var worker = new Worker(url, { type: "module" }); + worker.onerror = (e) => { + worker.terminate(); + failSpec(done, e.message); + return true; + }; + worker.onmessage = (msg) => { + expect(msg.data).toBe(42); + worker.terminate(); + done(); + }; + worker.postMessage({ eval: "postMessage(42);" }); + }); + + (isRuntimeCommon ? it : xit)("Should run an entry named by a file: URL string without its extension", (done) => { + var href = require("./WorkerEntryUrl.mjs").evalWorkerUrl.href.replace(/\.js$/, ""); + var worker = new Worker(href); + worker.onerror = (e) => { + worker.terminate(); + failSpec(done, e.message); + return true; + }; + worker.onmessage = (msg) => { + expect(msg.data).toBe(42); + worker.terminate(); + done(); + }; + worker.postMessage({ eval: "postMessage(42);" }); + }); + + (isRuntimeCommon ? it : xit)("Should throw ERR_INVALID_URL_SCHEME for an entry URL of another scheme", () => { + var error; + try { + new Worker("data:text/javascript,postMessage(1)"); + } catch (e) { + error = e; + } + expect(error instanceof TypeError).toBe(true); + expect(error && error.code).toBe("ERR_INVALID_URL_SCHEME"); + }); + it("Should throw exception when parameter is not a proper string", () => { // with object parameter expect(() => new Worker({ filename: "./EvalWorker.js" })).toThrow();