Skip to content

Commit a8029d4

Browse files
authored
Fix build tests failing silently (#8295)
* Prevent build tests from failing silently * Fix failing build tests * CHANGELOG
1 parent ff36aba commit a8029d4

18 files changed

Lines changed: 54 additions & 30 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#### :house: Internal
3939

4040
- Reanalyze server: redesign incremental fixpoint with delete-then-rederive strategy and predecessor tracking, improving speed on deletions. https://github.com/rescript-lang/rescript/pull/8276
41+
- Fix build tests failing silently. https://github.com/rescript-lang/rescript/pull/8295
4142

4243
# 13.0.0-alpha.2
4344

lib_dev/process.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export const {
3232
execBin,
3333
rescript,
3434
execBuild,
35+
execBuildOrThrow,
3536
execClean,
3637
} = setup();
3738

@@ -196,6 +197,25 @@ export function setup(cwd = process.cwd()) {
196197
return exec(rescript_exe, ["build", ...args], options);
197198
},
198199

200+
/**
201+
* Execute ReScript `build` command directly and throw on non-zero exit
202+
* while preserving captured stdout/stderr for quiet successful tests.
203+
*
204+
* @param {string[]} [args]
205+
* @param {ExecOptions} [options]
206+
* @return {Promise<ExecResult>}
207+
*/
208+
async execBuildOrThrow(args = [], options = {}) {
209+
const out = await exec(rescript_exe, ["build", ...args], options);
210+
if (out.status !== 0) {
211+
const err = new Error("ReScript build failed");
212+
err.stack = out.stdout + out.stderr;
213+
Object.assign(err, { execResult: out });
214+
throw err;
215+
}
216+
return out;
217+
},
218+
199219
/**
200220
* Execute ReScript `clean` command directly
201221
*

tests/build_tests/case3/input.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import fs from "node:fs/promises";
55
import path from "node:path";
66
import { setup } from "#dev/process";
77

8-
const { execBuild, execClean } = setup(import.meta.dirname);
8+
const { execBuildOrThrow, execClean } = setup(import.meta.dirname);
99

1010
await execClean();
11-
await execBuild();
11+
await execBuildOrThrow();
1212

1313
const o = await fs.readFile(path.join("src", "hello.res.js"), "ascii");
1414
assert.ok(/HelloGen\.f/.test(o));
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import * as assert from "node:assert";
22
import { setup } from "#dev/process";
33

4-
const { execClean, execBuild } = setup(import.meta.dirname);
4+
const { execClean, execBuildOrThrow } = setup(import.meta.dirname);
55

66
await execClean();
7-
await execBuild();
7+
await execBuildOrThrow();
88

99
const x = await import("./src/demo.res.js");
1010
assert.equal(x.v, 42);

tests/build_tests/devonly/input.js

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

33
import { setup } from "#dev/process";
44

5-
const { execBuild } = setup(import.meta.dirname);
5+
const { execBuildOrThrow } = setup(import.meta.dirname);
66

7-
await execBuild();
7+
await execBuildOrThrow();

tests/build_tests/exports/input.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
import { setup } from "#dev/process";
44

5-
const { execBuild, execClean } = setup(import.meta.dirname);
5+
const { execBuildOrThrow, execClean } = setup(import.meta.dirname);
66

7-
await execBuild();
7+
await execClean();
8+
await execBuildOrThrow();
89
await execClean();

tests/build_tests/hyphen2/input.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { setup } from "#dev/process";
44

5-
const { execBuild, execClean } = setup(import.meta.dirname);
5+
const { execBuildOrThrow, execClean } = setup(import.meta.dirname);
66

7-
await execBuild();
7+
await execBuildOrThrow();
88
await execClean();

tests/build_tests/jsx_settings_inheritance/input.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { setup } from "#dev/process";
44

5-
const { execBuild, execClean } = setup(import.meta.dirname);
5+
const { execBuildOrThrow, execClean } = setup(import.meta.dirname);
66

77
await execClean();
8-
await execBuild();
8+
await execBuildOrThrow();

tests/build_tests/nested/input.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import * as fs from "node:fs/promises";
55
import * as path from "node:path";
66
import { setup } from "#dev/process";
77

8-
const { execBuild, execClean } = setup(import.meta.dirname);
8+
const { execBuildOrThrow, execClean } = setup(import.meta.dirname);
99

10-
await execBuild();
10+
await execBuildOrThrow();
1111

1212
const content = await fs.readFile(
1313
path.join(import.meta.dirname, "src", "demo.js"),

tests/build_tests/nnest/input.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import * as fs from "node:fs/promises";
55
import * as path from "node:path";
66
import { setup } from "#dev/process";
77

8-
const { execBuild, execClean } = setup(import.meta.dirname);
8+
const { execBuildOrThrow, execClean } = setup(import.meta.dirname);
99

10-
await execBuild();
10+
await execBuildOrThrow();
1111

1212
const content = await fs.readFile(
1313
path.join(import.meta.dirname, "src", "demo.js"),

0 commit comments

Comments
 (0)