33// ```
44// npm install browser-ui-test
55// ```
6- const path = require ( 'path' ) ;
6+ const fs = require ( "fs" ) ;
7+ const path = require ( "path" ) ;
78const { Options, runTest} = require ( 'browser-ui-test' ) ;
89
910function showHelp ( ) {
1011 console . log ( "rustdoc-js options:" ) ;
1112 console . log ( " --doc-folder [PATH] : location of the generated doc folder" ) ;
1213 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 " ) ;
1415}
1516
1617function parseOptions ( args ) {
1718 var opts = {
1819 "doc_folder" : "" ,
19- "test_file " : "" ,
20+ "tests_folder " : "" ,
2021 } ;
2122 var correspondances = {
2223 "--doc-folder" : "doc_folder" ,
23- "--test-file " : "test_file " ,
24+ "--tests-folder " : "tests_folder " ,
2425 } ;
2526
2627 for ( var i = 0 ; i < args . length ; ++ i ) {
2728 if ( args [ i ] === "--doc-folder"
28- || args [ i ] === "--test-file " ) {
29+ || args [ i ] === "--tests-folder " ) {
2930 i += 1 ;
3031 if ( i >= args . length ) {
3132 console . log ( "Missing argument after `" + args [ i - 1 ] + "` option." ) ;
@@ -41,8 +42,8 @@ function parseOptions(args) {
4142 return null ;
4243 }
4344 }
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." ) ;
4647 } else if ( opts [ "doc_folder" ] . length < 1 ) {
4748 console . log ( "Missing `--doc-folder` option." ) ;
4849 } else {
@@ -51,15 +52,8 @@ function parseOptions(args) {
5152 return null ;
5253}
5354
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 ) ) ;
6357 if ( opts === null ) {
6458 process . exit ( 1 ) ;
6559 }
@@ -68,22 +62,34 @@ function main(argv) {
6862 try {
6963 // This is more convenient that setting fields one by one.
7064 options . parseArguments ( [
71- ' --no-screenshot' ,
65+ " --no-screenshot" ,
7266 "--variable" , "DOC_PATH" , opts [ "doc_folder" ] ,
7367 ] ) ;
7468 } catch ( error ) {
7569 console . error ( `invalid argument: ${ error } ` ) ;
7670 process . exit ( 1 ) ;
7771 }
7872
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 ) {
8591 process . exit ( 1 ) ;
86- } ) ;
92+ }
8793}
8894
8995main ( process . argv ) ;
0 commit comments