1
1
import * as path from "node:path" ;
2
2
import { exec } from "node:child_process" ;
3
3
import { promisify } from "node:util" ;
4
- import { readdirSync , existsSync } from "fs" ;
4
+ import { readdirSync , existsSync , readFileSync } from "fs" ;
5
5
import { micromark } from "micromark" ;
6
6
7
7
const execAsync = promisify ( exec ) ;
@@ -140,4 +140,34 @@ export async function getDoc(absoluteFilePath) {
140
140
values,
141
141
valueHeadings,
142
142
} ;
143
- }
143
+ }
144
+
145
+ function trimRescriptOutput ( output ) {
146
+ return output
147
+ . replace ( "// Generated by ReScript, PLEASE EDIT WITH CARE" , "" )
148
+ . replace ( "/* response Not a pure module */" , "" )
149
+ . trim ( ) ;
150
+ }
151
+
152
+ const testDir = path . resolve ( process . cwd ( ) , "tests" ) ;
153
+ export const testFiles =
154
+ readdirSync ( testDir , { recursive : true } )
155
+ . filter ( f => f . endsWith ( ".res" ) )
156
+ . map ( tf => {
157
+ const sourcePath = path . join ( testDir , tf ) ;
158
+ const source = readFileSync ( sourcePath , "utf-8" ) ;
159
+ const outputPath = sourcePath . replace ( ".res" , ".js" ) ;
160
+ const output = readFileSync ( outputPath , "utf-8" ) ;
161
+
162
+ const parts = tf . split ( path . sep ) ;
163
+ const name = parts [ parts . length - 1 ] . replace ( "__tests.res" , "" ) ;
164
+
165
+ return {
166
+ sourcePath : sourcePath . replace ( testDir , "" ) ,
167
+ source,
168
+ output : trimRescriptOutput ( output ) ,
169
+ outputPath : outputPath . replace ( testDir , "" ) ,
170
+ name,
171
+ } ;
172
+ } )
173
+ . sort ( ( a , b ) => a . name . localeCompare ( b . name ) ) ;
0 commit comments