1
1
// This file is a verbatim copy of gleeunit 0.10.0's <https://github.com/lpil/gleeunit/blob/main/src/gleeunit_ffi.mjs>
2
2
3
3
async 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 ) ;
6
6
if ( path . endsWith ( ".gleam" ) ) {
7
7
yield path ;
8
8
} else {
@@ -16,9 +16,9 @@ async function* gleamFiles(directory) {
16
16
}
17
17
18
18
async 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()
22
22
if ( matches ) return matches [ 1 ] ;
23
23
}
24
24
throw new Error ( "Could not determine package name from gleam.toml" ) ;
@@ -28,21 +28,21 @@ export async function main() {
28
28
let passes = 0 ;
29
29
let failures = 0 ;
30
30
31
- let packageName = await readRootPackageName ( ) ;
32
- let dist = `../${ packageName } /` ;
31
+ const packageName = await readRootPackageName ( ) ;
32
+ const dist = `../${ packageName } /` ;
33
33
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 ) ) {
38
38
if ( ! fnName . endsWith ( "_test" ) ) continue ;
39
39
try {
40
40
await module [ fnName ] ( ) ;
41
41
write ( `\u001b[32m.\u001b[0m` ) ;
42
42
passes ++ ;
43
43
} 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 } ` : "" ;
46
46
write ( `\n❌ ${ moduleName } .${ fnName } ${ line } : ${ error } \n` ) ;
47
47
failures ++ ;
48
48
}
@@ -76,8 +76,8 @@ function exit(code) {
76
76
77
77
async function read_dir ( path ) {
78
78
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 } ) ) {
81
81
items . push ( item . name ) ;
82
82
}
83
83
return items ;
@@ -96,8 +96,8 @@ async function read_file(path) {
96
96
if ( globalThis . Deno ) {
97
97
return Deno . readTextFile ( path ) ;
98
98
} 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 ) ;
101
101
return contents . toString ( ) ;
102
102
}
103
103
}
0 commit comments