3
3
// ```
4
4
// npm install browser-ui-test
5
5
// ```
6
- const path = require ( 'path' ) ;
6
+ const fs = require ( "fs" ) ;
7
+ const path = require ( "path" ) ;
7
8
const { Options, runTest} = require ( 'browser-ui-test' ) ;
8
9
9
10
function showHelp ( ) {
10
11
console . log ( "rustdoc-js options:" ) ;
11
12
console . log ( " --doc-folder [PATH] : location of the generated doc folder" ) ;
12
13
console . log ( " --help : show this message then quit" ) ;
13
- console . log ( " --test-file [PATH] : location of the JS test file " ) ;
14
+ console . log ( " --tests-folder [PATH] : location of the .GOML tests folder " ) ;
14
15
}
15
16
16
17
function parseOptions ( args ) {
17
18
var opts = {
18
19
"doc_folder" : "" ,
19
- "test_file " : "" ,
20
+ "tests_folder " : "" ,
20
21
} ;
21
22
var correspondances = {
22
23
"--doc-folder" : "doc_folder" ,
23
- "--test-file " : "test_file " ,
24
+ "--tests-folder " : "tests_folder " ,
24
25
} ;
25
26
26
27
for ( var i = 0 ; i < args . length ; ++ i ) {
27
28
if ( args [ i ] === "--doc-folder"
28
- || args [ i ] === "--test-file " ) {
29
+ || args [ i ] === "--tests-folder " ) {
29
30
i += 1 ;
30
31
if ( i >= args . length ) {
31
32
console . log ( "Missing argument after `" + args [ i - 1 ] + "` option." ) ;
@@ -41,8 +42,8 @@ function parseOptions(args) {
41
42
return null ;
42
43
}
43
44
}
44
- if ( opts [ "test_file " ] . length < 1 ) {
45
- console . log ( "Missing `--test-file ` option." ) ;
45
+ if ( opts [ "tests_folder " ] . length < 1 ) {
46
+ console . log ( "Missing `--tests-folder ` option." ) ;
46
47
} else if ( opts [ "doc_folder" ] . length < 1 ) {
47
48
console . log ( "Missing `--doc-folder` option." ) ;
48
49
} else {
@@ -51,15 +52,8 @@ function parseOptions(args) {
51
52
return null ;
52
53
}
53
54
54
- function checkFile ( test_file , opts , loaded , index ) {
55
- const test_name = path . basename ( test_file , ".js" ) ;
56
-
57
- process . stdout . write ( 'Checking "' + test_name + '" ... ' ) ;
58
- return runChecks ( test_file , loaded , index ) ;
59
- }
60
-
61
- function main ( argv ) {
62
- var opts = parseOptions ( argv . slice ( 2 ) ) ;
55
+ async function main ( argv ) {
56
+ let opts = parseOptions ( argv . slice ( 2 ) ) ;
63
57
if ( opts === null ) {
64
58
process . exit ( 1 ) ;
65
59
}
@@ -68,22 +62,34 @@ function main(argv) {
68
62
try {
69
63
// This is more convenient that setting fields one by one.
70
64
options . parseArguments ( [
71
- ' --no-screenshot' ,
65
+ " --no-screenshot" ,
72
66
"--variable" , "DOC_PATH" , opts [ "doc_folder" ] ,
73
67
] ) ;
74
68
} catch ( error ) {
75
69
console . error ( `invalid argument: ${ error } ` ) ;
76
70
process . exit ( 1 ) ;
77
71
}
78
72
79
- runTest ( opts [ "test_file" ] , options ) . then ( out => {
80
- const [ output , nb_failures ] = out ;
81
- console . log ( output ) ;
82
- process . exit ( nb_failures ) ;
83
- } ) . catch ( err => {
84
- console . error ( err ) ;
73
+ let failed = false ;
74
+ let files = fs . readdirSync ( opts [ "tests_folder" ] ) . filter ( file => path . extname ( file ) == ".goml" ) ;
75
+
76
+ files . sort ( ) ;
77
+ for ( var i = 0 ; i < files . length ; ++ i ) {
78
+ const testPath = path . join ( opts [ "tests_folder" ] , files [ i ] ) ;
79
+ await runTest ( testPath , options ) . then ( out => {
80
+ const [ output , nb_failures ] = out ;
81
+ console . log ( output ) ;
82
+ if ( nb_failures > 0 ) {
83
+ failed = true ;
84
+ }
85
+ } ) . catch ( err => {
86
+ console . error ( err ) ;
87
+ failed = true ;
88
+ } ) ;
89
+ }
90
+ if ( failed ) {
85
91
process . exit ( 1 ) ;
86
- } ) ;
92
+ }
87
93
}
88
94
89
95
main ( process . argv ) ;
0 commit comments