From 2f9ae4f80b51c7418afac582462acb9e6b89b2e5 Mon Sep 17 00:00:00 2001 From: Camillo Bruni Date: Mon, 14 Jul 2025 18:32:03 +0200 Subject: [PATCH 1/5] adding basic unittests --- cli.js | 29 +------------------------ package-lock.json | 6 +++--- package.json | 4 ++-- shell-config.js | 52 +++++++++++++++++++++++++++++++++++++++++++++ tests/run-shell.mjs | 1 + 5 files changed, 59 insertions(+), 33 deletions(-) create mode 100644 shell-config.js diff --git a/cli.js b/cli.js index 7a3a5ccb..1e11c5de 100644 --- a/cli.js +++ b/cli.js @@ -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() { diff --git a/package-lock.json b/package-lock.json index a6582c83..bf0ad8aa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1695,9 +1695,9 @@ } }, "node_modules/debug": { - "version": "4.3.7", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.7.tgz", - "integrity": "sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ==", + "version": "4.4.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.1.tgz", + "integrity": "sha512-KcKCqiftBJcZr++7ykoDIEwSa3XWowTfNPo92BYxjXiyYEVrUQh2aLyhxBCwww+heortUFxEJYcRzosstTEBYQ==", "dev": true, "dependencies": { "ms": "^2.1.3" diff --git a/package.json b/package.json index efc89908..e43c51c9 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "test:spidermonkey": "node tests/run-shell.mjs --shell spidermonkey" }, "devDependencies": { + "@actions/core": "^1.11.1", "@babel/core": "^7.21.3", "@babel/eslint-parser": "^7.21.3", "@babel/plugin-proposal-decorators": "^7.21.0", @@ -39,7 +40,6 @@ "jsvu": "^2.5.1", "local-web-server": "^5.4.0", "prettier": "^2.8.3", - "selenium-webdriver": "^4.8.0", - "@actions/core": "^1.11.1" + "selenium-webdriver": "^4.8.0" } } diff --git a/shell-config.js b/shell-config.js new file mode 100644 index 00000000..5e38e0c5 --- /dev/null +++ b/shell-config.js @@ -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; diff --git a/tests/run-shell.mjs b/tests/run-shell.mjs index 6b3422ec..b3fe52ee 100644 --- a/tests/run-shell.mjs +++ b/tests/run-shell.mjs @@ -133,6 +133,7 @@ function sh(binary, args) { async function runTests() { const shellBinary = logGroup(`Installing JavaScript Shell: ${SHELL_NAME}`, testSetup); let success = true; + success &&= runTest("Run Unittests", () => sh(shellBinary, ["tests/unittests.js"])); success &&= runTest("Run Complete Suite", () => sh(shellBinary, [CLI_PATH])); success &&= runTest("Run Single Suite", () => { const singleTestArgs = [...BASE_CLI_ARGS_WITH_OPTIONS, "proxy-mobx"]; From 7861918f8d6befb59559ebecf96fdb81350a944f Mon Sep 17 00:00:00 2001 From: Camillo Bruni Date: Mon, 14 Jul 2025 18:32:49 +0200 Subject: [PATCH 2/5] name --- tests/run-shell.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/run-shell.mjs b/tests/run-shell.mjs index b3fe52ee..eb14a8d6 100644 --- a/tests/run-shell.mjs +++ b/tests/run-shell.mjs @@ -133,7 +133,7 @@ function sh(binary, args) { async function runTests() { const shellBinary = logGroup(`Installing JavaScript Shell: ${SHELL_NAME}`, testSetup); let success = true; - success &&= runTest("Run Unittests", () => sh(shellBinary, ["tests/unittests.js"])); + success &&= runTest("Run UnitTests", () => sh(shellBinary, ["tests/unittests.js"])); success &&= runTest("Run Complete Suite", () => sh(shellBinary, [CLI_PATH])); success &&= runTest("Run Single Suite", () => { const singleTestArgs = [...BASE_CLI_ARGS_WITH_OPTIONS, "proxy-mobx"]; From 57cd1b9eca295d1b07f095a62cb542f17cf5e5a3 Mon Sep 17 00:00:00 2001 From: Camillo Bruni Date: Mon, 14 Jul 2025 18:38:38 +0200 Subject: [PATCH 3/5] partial revert --- package-lock.json | 6 +++--- package.json | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index bf0ad8aa..a6582c83 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1695,9 +1695,9 @@ } }, "node_modules/debug": { - "version": "4.4.1", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.1.tgz", - "integrity": "sha512-KcKCqiftBJcZr++7ykoDIEwSa3XWowTfNPo92BYxjXiyYEVrUQh2aLyhxBCwww+heortUFxEJYcRzosstTEBYQ==", + "version": "4.3.7", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.7.tgz", + "integrity": "sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ==", "dev": true, "dependencies": { "ms": "^2.1.3" diff --git a/package.json b/package.json index e43c51c9..efc89908 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,6 @@ "test:spidermonkey": "node tests/run-shell.mjs --shell spidermonkey" }, "devDependencies": { - "@actions/core": "^1.11.1", "@babel/core": "^7.21.3", "@babel/eslint-parser": "^7.21.3", "@babel/plugin-proposal-decorators": "^7.21.0", @@ -40,6 +39,7 @@ "jsvu": "^2.5.1", "local-web-server": "^5.4.0", "prettier": "^2.8.3", - "selenium-webdriver": "^4.8.0" + "selenium-webdriver": "^4.8.0", + "@actions/core": "^1.11.1" } } From 84601fc589776e40d81539a959d95337d24549d9 Mon Sep 17 00:00:00 2001 From: Camillo Bruni Date: Mon, 14 Jul 2025 18:56:43 +0200 Subject: [PATCH 4/5] fix cli args --- tests/run-shell.mjs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/tests/run-shell.mjs b/tests/run-shell.mjs index eb14a8d6..213a37ee 100644 --- a/tests/run-shell.mjs +++ b/tests/run-shell.mjs @@ -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; @@ -133,11 +135,10 @@ function sh(binary, args) { async function runTests() { const shellBinary = logGroup(`Installing JavaScript Shell: ${SHELL_NAME}`, testSetup); let success = true; - success &&= runTest("Run UnitTests", () => sh(shellBinary, ["tests/unittests.js"])); - 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) From e00596d5ee1341aa01663e1ce64c4bbceac5777c Mon Sep 17 00:00:00 2001 From: Camillo Bruni Date: Mon, 14 Jul 2025 18:56:56 +0200 Subject: [PATCH 5/5] adding --- tests/unit-tests.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 tests/unit-tests.js diff --git a/tests/unit-tests.js b/tests/unit-tests.js new file mode 100644 index 00000000..29fd07b0 --- /dev/null +++ b/tests/unit-tests.js @@ -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")) + } +})(); \ No newline at end of file