Skip to content

Commit 7a50011

Browse files
committed
fix
1 parent 77082a3 commit 7a50011

File tree

2 files changed

+57
-18
lines changed

2 files changed

+57
-18
lines changed

lib_dev/process.js

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,17 @@ const signals = {
2121
SIGTERM: 15,
2222
};
2323

24-
export const { exec, node, yarn, mocha, bsc, rescript, execBuild, execClean } =
25-
setup();
24+
export const {
25+
shell,
26+
node,
27+
yarn,
28+
mocha,
29+
bsc,
30+
rescript,
31+
execBin,
32+
execBuild,
33+
execClean,
34+
} = setup();
2635

2736
/**
2837
* @param {string} [cwd]
@@ -71,7 +80,11 @@ export function setup(cwd = process.cwd()) {
7180
}
7281

7382
if (throwOnFail && code !== 0) {
74-
reject({ status: code, stdout, stderr });
83+
reject(
84+
new Error(
85+
`Command ${command} exited with non-zero status: ${code}`,
86+
),
87+
);
7588
} else {
7689
resolve({ status: code, stdout, stderr });
7790
}
@@ -80,32 +93,44 @@ export function setup(cwd = process.cwd()) {
8093
}
8194

8295
return {
83-
exec,
96+
/**
97+
* bash shell script
98+
*
99+
* @param {string} script
100+
* @param {string[]} [args]
101+
* @param {ExecOptions} [options]
102+
* @return {Promise<ExecResult>}
103+
*/
104+
shell(script, args = [], options = {}) {
105+
return exec("bash", [script, ...args], options);
106+
},
84107

85108
/**
86-
* `node` CLI
109+
* Execute JavaScript on Node.js
87110
*
111+
* @param {string} script
88112
* @param {string[]} [args]
89113
* @param {ExecOptions} [options]
90114
* @return {Promise<ExecResult>}
91115
*/
92-
node(args = [], options = {}) {
93-
return exec("node", args, options);
116+
node(script, args = [], options = {}) {
117+
return exec("node", [script, ...args], options);
94118
},
95119

96120
/**
97-
* `yarn` CLI
121+
* Execute Yarn command
98122
*
123+
* @param {string} command
99124
* @param {string[]} [args]
100125
* @param {ExecOptions} [options]
101126
* @return {Promise<ExecResult>}
102127
*/
103-
yarn(args = [], options = {}) {
104-
return exec("yarn", args, options);
128+
yarn(command, args = [], options = {}) {
129+
return exec("yarn", [...command.split(" "), ...args], options);
105130
},
106131

107132
/**
108-
* Mocha CLI
133+
* Execute Mocha CLI
109134
*
110135
* @param {string[]} [args]
111136
* @param {ExecOptions} [options]
@@ -168,5 +193,18 @@ export function setup(cwd = process.cwd()) {
168193
execClean(args = [], options = {}) {
169194
return exec(rescript_exe, ["clean", ...args], options);
170195
},
196+
197+
/**
198+
* Execute any binary or wrapper.
199+
* It should support Windows as well
200+
*
201+
* @param {string} bin
202+
* @param {string[]} [args]
203+
* @param {ExecOptions} [options]
204+
* @return {Promise<ExecResult>}
205+
*/
206+
execBin(bin, args = [], options = {}) {
207+
return exec(bin, args, options);
208+
},
171209
};
172210
}

scripts/test.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ import {
1212
} from "#dev/paths";
1313

1414
import {
15-
exec,
15+
execBin,
1616
execBuild,
1717
execClean,
1818
mocha,
1919
node,
2020
rescript,
21+
shell,
2122
} from "#dev/process";
2223

2324
let ounitTest = false;
@@ -55,7 +56,7 @@ if (process.argv.includes("-all")) {
5556
}
5657

5758
if (formatTest) {
58-
await exec("./scripts/format_check.sh", [], {
59+
await shell("./scripts/format_check.sh", [], {
5960
cwd: projectDir,
6061
stdio: "inherit",
6162
});
@@ -65,7 +66,7 @@ if (ounitTest) {
6566
if (process.platform === "win32") {
6667
console.log("Skipping OUnit tests on Windows");
6768
} else {
68-
await exec(ounitTestBin, [], {
69+
await execBin(ounitTestBin, [], {
6970
stdio: "inherit",
7071
});
7172
}
@@ -87,12 +88,12 @@ if (mochaTest) {
8788
stdio: "inherit",
8889
});
8990

90-
await node(["tests/tests/src/core/Core_TestSuite.mjs"], {
91+
await node("tests/tests/src/core/Core_TestSuite.mjs", [], {
9192
cwd: projectDir,
9293
stdio: "inherit",
9394
});
9495

95-
await node(["tests/tests/src/core/Core_TempTests.mjs"], {
96+
await node("tests/tests/src/core/Core_TempTests.mjs", [], {
9697
cwd: projectDir,
9798
stdio: "inherit",
9899
});
@@ -115,7 +116,7 @@ if (bsbTest) {
115116
console.log(`testing ${file}`);
116117

117118
// note existsSync test already ensure that it is a directory
118-
const out = await exec("node", ["input.js"], { cwd: testDir });
119+
const out = await node("input.js", [], { cwd: testDir });
119120
console.log(out.stdout);
120121

121122
if (out.status === 0) {
@@ -159,7 +160,7 @@ if (runtimeDocstrings) {
159160
});
160161

161162
// Generate rescript file with all tests `generated_mocha_test.res`
162-
await node([path.join(docstringTestDir, "DocTest.res.js")], {
163+
await node(path.join(docstringTestDir, "DocTest.res.js"), [], {
163164
cwd: projectDir,
164165
stdio: "inherit",
165166
});

0 commit comments

Comments
 (0)