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/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..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,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) 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