1
1
import * as path from "path" ;
2
2
import * as Mocha from "mocha" ;
3
- import * as glob from "glob" ;
3
+ import { glob } from "glob" ;
4
4
5
5
import { TIMEOUT_MS } from "./setup" ;
6
6
7
- export function run ( ) : Promise < void > {
7
+ export async function run ( ) : Promise < void > {
8
8
const mocha = new Mocha ( {
9
9
asyncOnly : true ,
10
10
color : true ,
@@ -16,33 +16,32 @@ export function run(): Promise<void> {
16
16
17
17
const testsRoot = path . resolve ( __dirname , ".." ) ;
18
18
19
- return new Promise ( ( c , e ) => {
20
- glob ( "**/**.test.js" , { cwd : testsRoot } , ( err , files ) => {
21
- if ( err ) {
22
- return e ( err ) ;
23
- }
19
+ try {
20
+ // Find all test files
21
+ const files = await glob ( "**/**.test.js" , { cwd : testsRoot } ) ;
24
22
25
- // Add files to the test suite
26
- files . forEach ( f => mocha . addFile ( path . resolve ( testsRoot , f ) ) ) ;
23
+ // Add files to the test suite
24
+ files . forEach ( f => mocha . addFile ( path . resolve ( testsRoot , f ) ) ) ;
27
25
28
- try {
29
- // Run the mocha test
30
- mocha . run ( failures => {
31
- if ( failures > 0 ) {
32
- // Let the cameras roll for a bit & make sure we capture the error
33
- if ( process . env . CI ) {
34
- setTimeout ( ( ) => e ( new Error ( `${ failures } tests failed; pausing for dramatic effect.` ) ) , 3000 ) ;
35
- } else {
36
- e ( new Error ( `${ failures } tests failed.` ) ) ;
37
- }
26
+ // Run the mocha test and wrap in a promise since mocha.run uses callbacks
27
+ await new Promise < void > ( ( resolve , reject ) => {
28
+ mocha . run ( failures => {
29
+ if ( failures > 0 ) {
30
+ const error = new Error ( `${ failures } tests failed${ process . env . CI ? '; pausing for dramatic effect.' : '.' } ` ) ;
31
+
32
+ // Let the cameras roll for a bit & make sure we capture the error
33
+ if ( process . env . CI ) {
34
+ setTimeout ( ( ) => reject ( error ) , 3000 ) ;
38
35
} else {
39
- c ( ) ;
36
+ reject ( error ) ;
40
37
}
41
- } ) ;
42
- } catch ( err ) {
43
- console . error ( err ) ;
44
- e ( err ) ;
45
- }
38
+ } else {
39
+ resolve ( ) ;
40
+ }
41
+ } ) ;
46
42
} ) ;
47
- } ) ;
43
+ } catch ( err ) {
44
+ console . error ( err ) ;
45
+ throw err ;
46
+ }
48
47
}
0 commit comments