@@ -3,6 +3,7 @@ const cp = require("child_process");
3
3
const path = require ( "path" ) ;
4
4
const fs = require ( "fs" ) ;
5
5
const os = require ( "os" ) ;
6
+ const glob = require ( "glob" ) ;
6
7
const { rescript_exe } = require ( "#cli/bin_path" ) ;
7
8
8
9
const duneBinDir = require ( "./dune" ) . duneBinDir ;
@@ -105,6 +106,18 @@ async function runTests() {
105
106
} else {
106
107
console . log ( `testing ${ file } ` ) ;
107
108
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
+
108
121
// note existsSync test already ensure that it is a directory
109
122
const out = await exec ( `node` , [ "input.js" ] , { cwd : testDir } ) ;
110
123
console . log ( out . stdout ) ;
@@ -128,16 +141,24 @@ async function runTests() {
128
141
console . log ( `Skipping docstrings tests on ${ process . platform } ` ) ;
129
142
} else if ( process . platform === "darwin" && os . release ( ) . startsWith ( "22" ) ) {
130
143
// Workaround for intermittent hangs in CI
131
- console . log ( "Skipping docstrings tests on macOS 13" )
144
+ console . log ( "Skipping docstrings tests on macOS 13" ) ;
132
145
} else {
133
146
console . log ( "Running runtime docstrings tests" ) ;
134
147
148
+ const docstringsTestsDir = path . join ( "tests" , "docstring_tests" ) ;
149
+
135
150
const generated_mocha_test_res = path . join (
136
- "tests" ,
137
- "docstring_tests" ,
151
+ docstringsTestsDir ,
138
152
"generated_mocha_test.res" ,
139
153
) ;
140
154
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
+
141
162
// Remove `generated_mocha_test.res` if file exists
142
163
if ( fs . existsSync ( generated_mocha_test_res ) ) {
143
164
console . log ( `Removing ${ generated_mocha_test_res } ` ) ;
@@ -150,17 +171,14 @@ async function runTests() {
150
171
} ) ;
151
172
152
173
// 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
+ } ) ;
160
178
161
179
// Build again to check if generated_mocha_test.res has syntax or type erros
162
180
cp . execSync ( `${ rescript_exe } build` , {
163
- cwd : path . join ( __dirname , ".." , "tests/docstring_tests" ) ,
181
+ cwd : path . join ( __dirname , ".." , docstringsTestsDir ) ,
164
182
stdio : [ 0 , 1 , 2 ] ,
165
183
} ) ;
166
184
@@ -173,7 +191,7 @@ async function runTests() {
173
191
174
192
console . log ( "Run mocha test" ) ;
175
193
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" ) } ` ,
177
195
{
178
196
cwd : path . join ( __dirname , ".." ) ,
179
197
stdio : [ 0 , 1 , 2 ] ,
0 commit comments