Skip to content

Commit bd63c99

Browse files
committed
fix run
1 parent 7365f3f commit bd63c99

File tree

1 file changed

+73
-18
lines changed

1 file changed

+73
-18
lines changed

tests/run-shell.mjs

Lines changed: 73 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
import commandLineArgs from "command-line-args";
44
import commandLineUsage from "command-line-usage";
5+
import { spawnSync } from "child_process";
6+
import { fileURLToPath } from "url";
7+
import { styleText } from 'node:util';
8+
import * as path from "path";
9+
import * as fs from "fs";
10+
import * as os from 'os';
11+
512

613
const optionDefinitions = [
714
{ name: "shell", type: String, description: "Set the shell to test, choices are [jsc, v8, spidermonkey]." },
@@ -38,29 +45,77 @@ const JS_SHELL= options?.shell;
3845
if (!JS_SHELL)
3946
printHelp("No javascript shell specified, use --shell");
4047

41-
let shellName;
42-
switch (JS_SHELL) {
43-
case "javascriptcore":
44-
case "jsc": {
45-
shellName = "javascriptcore";
46-
break;
47-
}
48-
case "spidermonkey": {
49-
shellName = "spidermonkey";
50-
break;
51-
}
52-
case "v8": {
53-
shellName = "v8";
54-
break;
55-
}
56-
default: {
57-
printHelp(`Invalid shell "${JS_SHELL}", choices are: "jsc", "spidermonkey" and "v8)`);
48+
const SHELL_NAME = (function() {
49+
switch (JS_SHELL) {
50+
case "javascriptcore":
51+
case "jsc": {
52+
return "javascriptcore";
5853
}
54+
case "spidermonkey": {
55+
return "spidermonkey";
56+
}
57+
case "v8": {
58+
return "v8";
59+
}
60+
default: {
61+
printHelp(`Invalid shell "${JS_SHELL}", choices are: "jsc", "spidermonkey" and "v8)`);
62+
}
63+
}
64+
})();
65+
66+
const FILE_PATH = fileURLToPath(import.meta.url);
67+
const SRC_DIR = path.dirname(path.dirname(FILE_PATH));
68+
const CLI_PATH = path.join(SRC_DIR, "cli.js");
69+
70+
const BASE_CLI_ARGS_WITH_OPTIONS = [CLI_PATH];
71+
if (SHELL_NAME != "spidermonkey")
72+
BASE_CLI_ARGS_WITH_OPTIONS.push("--");
73+
Object.freeze(BASE_CLI_ARGS_WITH_OPTIONS);
74+
75+
const SPAWN_OPTIONS = {
76+
stdio: ["inherit", "inherit", "inherit"]
77+
};
78+
79+
function log(...args) {
80+
const text = args.join(" ")
81+
console.log(styleText("yellow", text))
82+
}
83+
84+
function sh(binary, args) {
85+
const cmd = `${binary} ${args.join(" ")}`;
86+
console.log(styleText("cyan", cmd));
87+
const result = spawnSync(binary, args, SPAWN_OPTIONS);
88+
if (result.status || result.error) {
89+
console.error(result.error);
90+
throw new Error(`Shell CMD failed: ${binary} ${args.join(" ")}`);
91+
}
5992
}
6093

94+
async function testShell() {
95+
log(`Installing JavaScript Shell: ${SHELL_NAME}`);
96+
sh("jsvu", [`--engines=${SHELL_NAME}`]);
97+
const shellBinary = path.join(os.homedir(), ".jsvu/bin", SHELL_NAME);
98+
if (!fs.existsSync(shellBinary))
99+
throw new Error(`Could not find shell binary: ${shellBinary}`);
100+
log("");
101+
log(`Installed JavaScript Shell: ${shellBinary}`);
102+
log("");
103+
testDefaultRun(shellBinary);
104+
}
105+
106+
function testDefaultRun(shellBinary) {
107+
108+
log("=".repeat(80))
109+
log("Run Complete Suite");
110+
log(".".repeat(80))
111+
sh(shellBinary, [CLI_PATH])
61112

62-
function testShell() {
113+
log("=".repeat(80))
114+
log("Run Single Suite");
115+
log(".".repeat(80))
63116

117+
const singleTestArgs = [...BASE_CLI_ARGS_WITH_OPTIONS, "proxy-mobx"];
118+
sh(shellBinary, singleTestArgs);
64119
}
65120

66121
setImmediate(testShell);

0 commit comments

Comments
 (0)