11// This file is a verbatim copy of gleeunit 0.10.0's <https://github.com/lpil/gleeunit/blob/main/src/gleeunit_ffi.mjs>
22
33async function * gleamFiles ( directory ) {
4- for ( let entry of await read_dir ( directory ) ) {
5- let path = join_path ( directory , entry ) ;
4+ for ( const entry of await read_dir ( directory ) ) {
5+ const path = join_path ( directory , entry ) ;
66 if ( path . endsWith ( ".gleam" ) ) {
77 yield path ;
88 } else {
@@ -16,9 +16,9 @@ async function* gleamFiles(directory) {
1616}
1717
1818async function readRootPackageName ( ) {
19- let toml = await read_file ( "gleam.toml" , "utf-8" ) ;
20- for ( let line of toml . split ( "\n" ) ) {
21- let matches = line . match ( / \s * n a m e \s * = \s * " ( [ a - z ] [ a - z 0 - 9 _ ] * ) " / ) ; // Match regexp in compiler-cli/src/new.rs in validate_name()
19+ const toml = await read_file ( "gleam.toml" , "utf-8" ) ;
20+ for ( const line of toml . split ( "\n" ) ) {
21+ const matches = line . match ( / \s * n a m e \s * = \s * " ( [ a - z ] [ a - z 0 - 9 _ ] * ) " / ) ; // Match regexp in compiler-cli/src/new.rs in validate_name()
2222 if ( matches ) return matches [ 1 ] ;
2323 }
2424 throw new Error ( "Could not determine package name from gleam.toml" ) ;
@@ -28,21 +28,21 @@ export async function main() {
2828 let passes = 0 ;
2929 let failures = 0 ;
3030
31- let packageName = await readRootPackageName ( ) ;
32- let dist = `../${ packageName } /` ;
31+ const packageName = await readRootPackageName ( ) ;
32+ const dist = `../${ packageName } /` ;
3333
34- for await ( let path of await gleamFiles ( "test" ) ) {
35- let js_path = path . slice ( "test/" . length ) . replace ( ".gleam" , ".mjs" ) ;
36- let module = await import ( join_path ( dist , js_path ) ) ;
37- for ( let fnName of Object . keys ( module ) ) {
34+ for await ( const path of await gleamFiles ( "test" ) ) {
35+ const js_path = path . slice ( "test/" . length ) . replace ( ".gleam" , ".mjs" ) ;
36+ const module = await import ( join_path ( dist , js_path ) ) ;
37+ for ( const fnName of Object . keys ( module ) ) {
3838 if ( ! fnName . endsWith ( "_test" ) ) continue ;
3939 try {
4040 await module [ fnName ] ( ) ;
4141 write ( `\u001b[32m.\u001b[0m` ) ;
4242 passes ++ ;
4343 } catch ( error ) {
44- let moduleName = "\n" + js_path . slice ( 0 , - 4 ) ;
45- let line = error . line ? `:${ error . line } ` : "" ;
44+ const moduleName = "\n" + js_path . slice ( 0 , - 4 ) ;
45+ const line = error . line ? `:${ error . line } ` : "" ;
4646 write ( `\n❌ ${ moduleName } .${ fnName } ${ line } : ${ error } \n` ) ;
4747 failures ++ ;
4848 }
@@ -76,8 +76,8 @@ function exit(code) {
7676
7777async function read_dir ( path ) {
7878 if ( globalThis . Deno ) {
79- let items = [ ] ;
80- for await ( let item of Deno . readDir ( path , { withFileTypes : true } ) ) {
79+ const items = [ ] ;
80+ for await ( const item of Deno . readDir ( path , { withFileTypes : true } ) ) {
8181 items . push ( item . name ) ;
8282 }
8383 return items ;
@@ -96,8 +96,8 @@ async function read_file(path) {
9696 if ( globalThis . Deno ) {
9797 return Deno . readTextFile ( path ) ;
9898 } else {
99- let { readFile } = await import ( "fs/promises" ) ;
100- let contents = await readFile ( path ) ;
99+ const { readFile } = await import ( "fs/promises" ) ;
100+ const contents = await readFile ( path ) ;
101101 return contents . toString ( ) ;
102102 }
103103}
0 commit comments