Skip to content

Add basic unittests #94

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 15, 2025
Merged
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
29 changes: 1 addition & 28 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,7 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/

const isInBrowser = false;
console = {
log: globalThis?.console?.log ?? print,
error: globalThis?.console?.error ?? print,
}

const isD8 = typeof Realm !== "undefined";
if (isD8)
globalThis.readFile = read;
const isSpiderMonkey = typeof newGlobal !== "undefined";
if (isSpiderMonkey) {
globalThis.readFile = readRelativeToScript;
globalThis.arguments = scriptArgs;
}

if (typeof arguments !== "undefined" && arguments.length > 0)
testList = arguments.slice();
if (typeof testList === "undefined")
testList = undefined;

if (typeof testIterationCount === "undefined")
testIterationCount = undefined;

if (typeof runMode !== "undefined" && runMode == "RAMification")
RAMification = true;
else
RAMification = false;

load("./shell-config.js")
load("./JetStreamDriver.js");

async function runJetStream() {
Expand Down
52 changes: 52 additions & 0 deletions shell-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (C) 2018 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/

const isInBrowser = false;
console = {
log: globalThis?.console?.log ?? print,
error: globalThis?.console?.error ?? print,
}

const isD8 = typeof Realm !== "undefined";
if (isD8)
globalThis.readFile = read;
const isSpiderMonkey = typeof newGlobal !== "undefined";
if (isSpiderMonkey) {
globalThis.readFile = readRelativeToScript;
globalThis.arguments = scriptArgs;
}

if (typeof arguments !== "undefined" && arguments.length > 0)
testList = arguments.slice();
if (typeof testList === "undefined")
testList = undefined;

if (typeof testIterationCount === "undefined")
testIterationCount = undefined;

if (typeof runMode !== "undefined" && runMode == "RAMification")
RAMification = true;
else
RAMification = false;
16 changes: 9 additions & 7 deletions tests/run-shell.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,13 @@ const SHELL_NAME = (function() {
const FILE_PATH = fileURLToPath(import.meta.url);
const SRC_DIR = path.dirname(path.dirname(FILE_PATH));
const CLI_PATH = path.join(SRC_DIR, "cli.js");
const UNIT_TEST_PATH = path.join(SRC_DIR, "tests", "unit-tests.js");

const BASE_CLI_ARGS_WITH_OPTIONS = [CLI_PATH];
if (SHELL_NAME != "spidermonkey")
BASE_CLI_ARGS_WITH_OPTIONS.push("--");
Object.freeze(BASE_CLI_ARGS_WITH_OPTIONS);
function convertCliArgs(cli, ...cliArgs) {
if (SHELL_NAME == "spidermonkey")
return [cli, ...cliArgs]
return [cli, "--", ...cliArgs];
}

const GITHUB_ACTIONS_OUTPUT = "GITHUB_ACTIONS_OUTPUT" in process.env;

Expand Down Expand Up @@ -133,10 +135,10 @@ function sh(binary, args) {
async function runTests() {
const shellBinary = logGroup(`Installing JavaScript Shell: ${SHELL_NAME}`, testSetup);
let success = true;
success &&= runTest("Run Complete Suite", () => sh(shellBinary, [CLI_PATH]));
success &&= runTest("Run UnitTests", () => sh(shellBinary, [UNIT_TEST_PATH]));
success &&= runTest("Run Complete Suite", () => sh(shellBinary, convertCliArgs(CLI_PATH)));
success &&= runTest("Run Single Suite", () => {
const singleTestArgs = [...BASE_CLI_ARGS_WITH_OPTIONS, "proxy-mobx"];
sh(shellBinary, singleTestArgs);
sh(shellBinary, convertCliArgs(CLI_PATH, "proxy-mobx"));
});
if (!success) {
process.exit(1)
Expand Down
14 changes: 14 additions & 0 deletions tests/unit-tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
load("shell-config.js")
load("JetStreamDriver.js");

function assertTrue(condition, message) {
if (!condition) {
throw new Error(message || "Assertion failed");
}
}

(function testTagsAreStrings() {
for (const benchmark of BENCHMARKS) {
benchmark.tags.forEach(tag => assertTrue(typeof(tag) == "string"))
}
})();
Loading