Skip to content

Commit fd5d56e

Browse files
committed
fix tests
1 parent bcd94bd commit fd5d56e

File tree

3 files changed

+18
-24
lines changed

3 files changed

+18
-24
lines changed

lib_dev/process.js

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import * as path from "node:path";
33
import { bsc_exe, rescript_exe } from "#cli/bins";
44

55
/**
6+
* @typedef {{
7+
* throwOnFail?: boolean,
8+
* } & child_process.SpawnOptions} ExecOptions
9+
*
610
* @typedef {{
711
* status: number,
812
* stdout: string,
@@ -20,24 +24,18 @@ const signals = {
2024
export const { exec, node, npx, mocha, bsc, rescript, execBuild, execClean } =
2125
setup();
2226

23-
/**
24-
* @typedef {{
25-
* throwOnExit?: boolean,
26-
* }} ExecOptions
27-
*/
28-
2927
/**
3028
* @param {string} [cwd]
3129
*/
3230
export function setup(cwd = process.cwd()) {
3331
/**
3432
* @param {string} command
3533
* @param {string[]} [args]
36-
* @param {child_process.SpawnOptions & ExecOptions} [options]
34+
* @param {ExecOptions} [options]
3735
* @return {Promise<ExecResult>}
3836
*/
3937
async function exec(command, args = [], options = {}) {
40-
const { throwOnExit = true } = options;
38+
const { throwOnFail = options.stdio === "inherit" } = options;
4139

4240
const stdoutChunks = [];
4341
const stderrChunks = [];
@@ -63,20 +61,16 @@ export function setup(cwd = process.cwd()) {
6361
});
6462

6563
subprocess.once("close", (exitCode, signal) => {
66-
const stdout = stdoutChunks.length
67-
? Buffer.concat(stdoutChunks).toString("utf8")
68-
: null;
69-
const stderr = stdoutChunks.length
70-
? Buffer.concat(stderrChunks).toString("utf8")
71-
: null;
64+
const stdout = Buffer.concat(stdoutChunks).toString("utf8");
65+
const stderr = Buffer.concat(stderrChunks).toString("utf8");
7266

7367
let code = exitCode ?? 1;
7468
if (signals[signal]) {
7569
// + 128 is standard POSIX practice, see also https://nodejs.org/api/process.html#exit-codes
7670
code = signals[signal] + 128;
7771
}
7872

79-
if (throwOnExit && code !== 0) {
73+
if (throwOnFail && code !== 0) {
8074
reject({ status: code, stdout, stderr });
8175
} else {
8276
resolve({ status: code, stdout, stderr });
@@ -92,7 +86,7 @@ export function setup(cwd = process.cwd()) {
9286
* `node` CLI
9387
*
9488
* @param {string[]} [args]
95-
* @param {child_process.SpawnOptions} [options]
89+
* @param {ExecOptions} [options]
9690
* @return {Promise<ExecResult>}
9791
*/
9892
node(args = [], options = {}) {
@@ -103,7 +97,7 @@ export function setup(cwd = process.cwd()) {
10397
* `npx` CLI
10498
*
10599
* @param {string[]} [args]
106-
* @param {child_process.SpawnOptions} [options]
100+
* @param {ExecOptions} [options]
107101
* @return {Promise<ExecResult>}
108102
*/
109103
npx(args = [], options = {}) {
@@ -114,7 +108,7 @@ export function setup(cwd = process.cwd()) {
114108
* Mocha CLI
115109
*
116110
* @param {string[]} [args]
117-
* @param {child_process.SpawnOptions} [options]
111+
* @param {ExecOptions} [options]
118112
* @return {Promise<ExecResult>}
119113
*/
120114
mocha(args = [], options = {}) {
@@ -132,7 +126,7 @@ export function setup(cwd = process.cwd()) {
132126
* | (string & {})
133127
* )} command
134128
* @param {string[]} [args]
135-
* @param {child_process.SpawnOptions} [options]
129+
* @param {ExecOptions} [options]
136130
* @return {Promise<ExecResult>}
137131
*/
138132
rescript(command, args = [], options = {}) {
@@ -144,7 +138,7 @@ export function setup(cwd = process.cwd()) {
144138
* `bsc` CLI
145139
*
146140
* @param {string[]} [args]
147-
* @param {child_process.SpawnOptions} [options]
141+
* @param {ExecOptions} [options]
148142
* @return {Promise<ExecResult>}
149143
*/
150144
bsc(args = [], options = {}) {
@@ -155,7 +149,7 @@ export function setup(cwd = process.cwd()) {
155149
* Execute ReScript `build` command directly
156150
*
157151
* @param {string[]} [args]
158-
* @param {child_process.SpawnOptions} [options]
152+
* @param {ExecOptions} [options]
159153
* @return {Promise<ExecResult>}
160154
*/
161155
execBuild(args = [], options = {}) {
@@ -166,7 +160,7 @@ export function setup(cwd = process.cwd()) {
166160
* Execute ReScript `clean` command directly
167161
*
168162
* @param {string[]} [args]
169-
* @param {child_process.SpawnOptions} [options]
163+
* @param {ExecOptions} [options]
170164
* @return {Promise<ExecResult>}
171165
*/
172166
execClean(args = [], options = {}) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"./package.json": "./package.json"
7474
},
7575
"imports": {
76-
"#cli/bins": "./cli/common/bins.js",
76+
"#cli/*": "./cli/common/*.js",
7777
"#dev/*": "./lib_dev/*.js",
7878
"#lib/minisocket": "./lib/minisocket.js"
7979
},

scripts/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ if (process.argv.includes("-all")) {
5555
}
5656

5757
if (formatTest) {
58-
await exec("bash", ["scripts/format_check.sh"], {
58+
await exec("./scripts/format_check.sh", [], {
5959
cwd: projectDir,
6060
stdio: "inherit",
6161
});

0 commit comments

Comments
 (0)