Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions Import/index.js
Original file line number Diff line number Diff line change
@@ -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");
});
Expand Down
23 changes: 8 additions & 15 deletions Require/index.js
Original file line number Diff line number Diff line change
@@ -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);

Expand Down Expand Up @@ -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);
Expand All @@ -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';

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions Workers/WorkerEntryUrl.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const evalWorkerUrl = new URL("./EvalWorker.js", import.meta.url);
48 changes: 48 additions & 0 deletions Workers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down