Skip to content

Commit aafc860

Browse files
committed
Fix runtime test output suffix
1 parent 7ed91f7 commit aafc860

1 file changed

Lines changed: 20 additions & 10 deletions

File tree

tests/index.js

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { execFileSync, execSync, spawnSync } from "child_process";
2+
import * as fs from "fs";
23
import { fileURLToPath, pathToFileURL } from "url";
34
import * as path from "path";
45
import { exit } from "process";
@@ -7,15 +8,21 @@ const currentFileName = fileURLToPath(import.meta.url);
78
const currentDir = path.dirname(currentFileName);
89
const repoRoot = path.resolve(currentDir, "..");
910
const testsDir = path.join(repoRoot, "tests");
11+
const rescriptConfig = JSON.parse(fs.readFileSync(path.join(repoRoot, "rescript.json"), "utf8"));
12+
const compiledSuffix = rescriptConfig.suffix ?? ".js";
1013

1114
const runtimeTests = [
12-
"FetchAPI/Headers__test.res.js",
13-
"FetchAPI/Request__test.res.js",
14-
"FetchAPI/Response__test.res.js",
15-
"FetchAPI/URLSearchParams__test.res.js",
16-
"URLAPI/URL__test.res.js",
15+
"FetchAPI/Headers__test.res",
16+
"FetchAPI/Request__test.res",
17+
"FetchAPI/Response__test.res",
18+
"FetchAPI/URLSearchParams__test.res",
19+
"URLAPI/URL__test.res",
1720
];
1821

22+
const compiledRuntimeTests = runtimeTests.map((testFile) =>
23+
testFile.replace(/\.res$/, compiledSuffix),
24+
);
25+
1926
// Compile all tests
2027
execSync("npm run build", { cwd: repoRoot, stdio: "inherit" });
2128

@@ -24,7 +31,7 @@ const warningYellow = "\x1b[33m";
2431
const errorRed = "\x1b[31m";
2532
const resetColor = "\x1b[0m";
2633

27-
for (const testFile of runtimeTests) {
34+
for (const testFile of compiledRuntimeTests) {
2835
const absoluteTestFile = path.join(testsDir, testFile);
2936
const result = spawnSync(
3037
process.execPath,
@@ -54,16 +61,19 @@ for (const testFile of runtimeTests) {
5461
}
5562

5663
// Assert generated test output stayed in sync.
57-
const gitDff = execFileSync("git", ["ls-files", "--modified", "--", "*.res.js"], {
64+
const gitDiff = execFileSync("git", ["ls-files", "--modified", "--", ...compiledRuntimeTests], {
5865
cwd: testsDir,
5966
}).toString();
60-
if (!gitDff) {
67+
if (!gitDiff) {
6168
console.log(`${successGreen}✅ No unstaged generated test difference!${resetColor}`);
6269
exit(0);
6370
} else {
6471
console.log(
65-
`${warningYellow}⚠️ There are unstaged differences in generated tests! Did you break a test?\n${gitDff}${resetColor}`,
72+
`${warningYellow}⚠️ There are unstaged differences in generated tests! Did you break a test?\n${gitDiff}${resetColor}`,
6673
);
67-
execSync("git --no-pager diff .", { stdio: "inherit", cwd: testsDir });
74+
execFileSync("git", ["--no-pager", "diff", "--", ...compiledRuntimeTests], {
75+
stdio: "inherit",
76+
cwd: testsDir,
77+
});
6878
exit(1);
6979
}

0 commit comments

Comments
 (0)