Skip to content

Commit dcfcbe3

Browse files
committed
tests: always delete stale output (lib folder)
1 parent 9c6856d commit dcfcbe3

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

scripts/test.js

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const cp = require("child_process");
33
const path = require("path");
44
const fs = require("fs");
55
const os = require("os");
6+
const glob = require("glob");
67
const { rescript_exe } = require("#cli/bin_path");
78

89
const duneBinDir = require("./dune").duneBinDir;
@@ -105,6 +106,18 @@ async function runTests() {
105106
} else {
106107
console.log(`testing ${file}`);
107108

109+
// Remove lib directory with stale output
110+
const libFolders = glob.sync(`${buildTestDir}/**/lib`);
111+
112+
libFolders.forEach((libFolder) => {
113+
if (
114+
fs.existsSync(libFolder) &&
115+
fs.lstatSync(libFolder).isDirectory()
116+
) {
117+
fs.rmSync(libFolder, { recursive: true });
118+
}
119+
});
120+
108121
// note existsSync test already ensure that it is a directory
109122
const out = await exec(`node`, ["input.js"], { cwd: testDir });
110123
console.log(out.stdout);
@@ -128,16 +141,24 @@ async function runTests() {
128141
console.log(`Skipping docstrings tests on ${process.platform}`);
129142
} else if (process.platform === "darwin" && os.release().startsWith("22")) {
130143
// Workaround for intermittent hangs in CI
131-
console.log("Skipping docstrings tests on macOS 13")
144+
console.log("Skipping docstrings tests on macOS 13");
132145
} else {
133146
console.log("Running runtime docstrings tests");
134147

148+
const docstringsTestsDir = path.join("tests", "docstring_tests");
149+
135150
const generated_mocha_test_res = path.join(
136-
"tests",
137-
"docstring_tests",
151+
docstringsTestsDir,
138152
"generated_mocha_test.res",
139153
);
140154

155+
const libFolder = path.join(docstringsTestsDir, "lib");
156+
157+
// Remove stale lib directory
158+
if (fs.existsSync(libFolder) && fs.lstatSync(libFolder).isDirectory()) {
159+
fs.rmSync(libFolder, { recursive: true });
160+
}
161+
141162
// Remove `generated_mocha_test.res` if file exists
142163
if (fs.existsSync(generated_mocha_test_res)) {
143164
console.log(`Removing ${generated_mocha_test_res}`);
@@ -150,17 +171,14 @@ async function runTests() {
150171
});
151172

152173
// Generate rescript file with all tests `generated_mocha_test.res`
153-
cp.execSync(
154-
`node ${path.join("tests", "docstring_tests", "DocTest.res.mjs")}`,
155-
{
156-
cwd: path.join(__dirname, ".."),
157-
stdio: [0, 1, 2],
158-
},
159-
);
174+
cp.execSync(`node ${path.join(docstringsTestsDir, "DocTest.res.mjs")}`, {
175+
cwd: path.join(__dirname, ".."),
176+
stdio: [0, 1, 2],
177+
});
160178

161179
// Build again to check if generated_mocha_test.res has syntax or type erros
162180
cp.execSync(`${rescript_exe} build`, {
163-
cwd: path.join(__dirname, "..", "tests/docstring_tests"),
181+
cwd: path.join(__dirname, "..", docstringsTestsDir),
164182
stdio: [0, 1, 2],
165183
});
166184

@@ -173,7 +191,7 @@ async function runTests() {
173191

174192
console.log("Run mocha test");
175193
cp.execSync(
176-
`npx mocha ${path.join("tests", "docstring_tests", "generated_mocha_test.res.mjs")}`,
194+
`npx mocha ${path.join(docstringsTestsDir, "generated_mocha_test.res.mjs")}`,
177195
{
178196
cwd: path.join(__dirname, ".."),
179197
stdio: [0, 1, 2],

0 commit comments

Comments
 (0)