33import * as Fs from "fs" ;
44import * as Os from "os" ;
55import * as Exn from "rescript/lib/es6/Exn.js" ;
6+ import * as Int from "rescript/lib/es6/Int.js" ;
67import * as Url from "url" ;
8+ import * as Dict from "rescript/lib/es6/Dict.js" ;
79import * as List from "rescript/lib/es6/List.js" ;
810import * as Path from "path" ;
911import * as $$Array from "rescript/lib/es6/Array.js" ;
1012import * as $$Error from "rescript/lib/es6/Error.js" ;
11- import * as Ordering from "rescript/lib/es6/Ordering .js" ;
13+ import * as Option from "rescript/lib/es6/Option .js" ;
1214import * as Belt_List from "rescript/lib/es6/Belt_List.js" ;
1315import * as ArrayUtils from "./ArrayUtils.res.mjs" ;
1416import * as Belt_Array from "rescript/lib/es6/Belt_Array.js" ;
1517import * as Pervasives from "rescript/lib/es6/Pervasives.js" ;
1618import * as SpawnAsync from "./SpawnAsync.res.mjs" ;
17- import * as Primitive_object from "rescript/lib/es6/Primitive_object .js" ;
19+ import * as Primitive_string from "rescript/lib/es6/Primitive_string .js" ;
1820import * as Promises from "node:fs/promises" ;
1921import * as Primitive_exceptions from "rescript/lib/es6/Primitive_exceptions.js" ;
2022import * as RescriptTools_Docgen from "rescript/lib/es6/RescriptTools_Docgen.js" ;
2123
22- let ignoreRuntimeTests = [
23- "Array.toReversed" ,
24- "Array.toSorted" ,
25- "Promise.withResolvers" ,
26- "Set.union" ,
27- "Set.isSupersetOf" ,
28- "Set.isSubsetOf" ,
29- "Set.isDisjointFrom" ,
30- "Set.intersection" ,
31- "Set.symmetricDifference" ,
32- "Set.difference"
33- ] ;
24+ let nodeVersion = Option . getExn ( Int . fromString ( Option . getExn ( process . version . replace ( "v" , "" ) . split ( "." ) [ 0 ] , "Failed to find major version of Node" ) , undefined ) , "Failed to convert node version to Int" ) ;
25+
26+ let ignoreRuntimeTests = [ [
27+ 18 ,
28+ [
29+ "Array.toReversed" ,
30+ "Array.toSorted" ,
31+ "Promise.withResolvers" ,
32+ "Set.union" ,
33+ "Set.isSupersetOf" ,
34+ "Set.isSubsetOf" ,
35+ "Set.isDisjointFrom" ,
36+ "Set.intersection" ,
37+ "Set.symmetricDifference" ,
38+ "Set.difference"
39+ ]
40+ ] ] ;
3441
3542function getOutput ( buffer ) {
3643 return buffer . map ( e => e . toString ( ) ) . join ( "" ) ;
@@ -53,7 +60,7 @@ async function extractDocFromFile(file) {
5360 RE_EXN_ID : "Assert_failure" ,
5461 _1 : [
5562 "DocTest.res" ,
56- 43 ,
63+ 58 ,
5764 9
5865 ] ,
5966 Error : new Error ( )
@@ -216,28 +223,48 @@ async function extractExamples() {
216223
217224async function main ( ) {
218225 let examples = await extractExamples ( ) ;
219- examples . sort ( ( a , b ) => {
220- if ( Primitive_object . greaterthan ( a . id , b . id ) ) {
221- return Ordering . fromInt ( 1 ) ;
222- } else {
223- return Ordering . fromInt ( - 1 ) ;
224- }
226+ examples . sort ( ( a , b ) => Primitive_string . compare ( a . id , b . id ) ) ;
227+ let dict = { } ;
228+ examples . forEach ( cur => {
229+ let modulePath = cur . id . split ( "." ) ;
230+ let id = modulePath . slice ( 0 , modulePath . length - 1 | 0 ) . join ( "." ) ;
231+ let p = dict [ id ] ;
232+ let previous = p !== undefined ? p : [ ] ;
233+ dict [ id ] = [ cur ] . concat ( previous ) ;
225234 } ) ;
226- let testsContent = $$Array . filterMap ( examples , example => {
227- let codeExamples = getCodeBlocks ( example ) ;
228- let ignore = ignoreRuntimeTests . includes ( example . id ) ;
229- if ( codeExamples . length === 0 || ignore ) {
235+ let output = [ ] ;
236+ Dict . forEachWithKey ( dict , ( examples , key ) => {
237+ let codeExamples = $$Array . filterMap ( examples , example => {
238+ let ignoreExample = Option . isSome ( ignoreRuntimeTests . find ( param => {
239+ if ( nodeVersion === param [ 0 ] ) {
240+ return param [ 1 ] . includes ( example . id ) ;
241+ } else {
242+ return false ;
243+ }
244+ } ) ) ;
245+ if ( ignoreExample ) {
246+ console . warn ( "Ignoring " + example . id + " tests. Not supported by Node " + nodeVersion . toString ( ) ) ;
247+ return ;
248+ }
249+ let code = getCodeBlocks ( example ) ;
250+ if ( code . length === 0 ) {
251+ return ;
252+ } else {
253+ return "test(\"" + Option . getExn ( example . id . split ( "." ) . at ( - 1 ) , undefined ) + "\", () => {\n module Test = {\n " + code + "\n }\n ()\n})" ;
254+ }
255+ } ) ;
256+ if ( codeExamples . length <= 0 ) {
230257 return ;
231- } else {
232- return "describe(\"" + example . id + "\", () => {\n test(\"" + example . id + "\", () => {\n module Test = {\n " + codeExamples + "\n }\n ()\n })\n})" ;
233258 }
234- } ) . join ( "\n\n" ) ;
259+ let content = "describe(\"" + key + "\", () => {\n" + codeExamples . join ( "\n" ) + "\n })" ;
260+ output . push ( content ) ;
261+ } ) ;
235262 let dirname = Path . dirname ( Url . fileURLToPath ( import . meta. url ) ) ;
236263 let filepath = Path . join ( dirname , "generated_mocha_test.res" ) ;
237- let fileContent = "open Mocha\n@@warning(\"-32-34-60-37-109-3-44\")\n\n" + testsContent ;
264+ let fileContent = "open Mocha\n@@warning(\"-32-34-60-37-109-3-44\")\n\n" + output . join ( "\n" ) ;
238265 return await Promises . writeFile ( filepath , fileContent ) ;
239266}
240267
241268await main ( ) ;
242269
243- /* batchSize Not a pure module */
270+ /* nodeVersion Not a pure module */
0 commit comments