1
1
// Copyright (c) Microsoft Corporation.
2
2
// Licensed under the MIT License.
3
3
4
- import * as glob from "glob" ;
5
- import * as Mocha from "mocha" ;
4
+ // NOTE: This code is borrowed under permission from:
5
+ // https://github.com/microsoft/vscode-extension-samples/tree/main/helloworld-test-sample/src/test
6
+
6
7
import * as path from "path" ;
8
+ import * as Mocha from "mocha" ;
9
+ import * as glob from "glob" ;
7
10
8
11
export function run ( ) : Promise < void > {
9
12
// Create the mocha test
10
13
const mocha = new Mocha ( {
11
- ui : "tdd" , // the TDD UI is being used in extension.test.ts (suite, test, etc.)
14
+ ui : "tdd" ,
12
15
color : ! process . env . TF_BUILD , // colored output from test results
13
16
reporter : "mocha-multi-reporters" ,
14
17
timeout : 5000 ,
@@ -23,24 +26,26 @@ export function run(): Promise<void> {
23
26
const testsRoot = path . resolve ( __dirname , ".." ) ;
24
27
25
28
return new Promise ( ( c , e ) => {
26
- glob ( "**/**.test.js" , { cwd : testsRoot } , ( err : any , files : any [ ] ) => {
29
+ glob ( "**/**.test.js" , { cwd : testsRoot } , ( err , files ) => {
27
30
if ( err ) {
28
31
return e ( err ) ;
29
32
}
30
33
31
34
// Add files to the test suite
32
- files . forEach ( ( f ) => mocha . addFile ( path . resolve ( testsRoot , f ) ) ) ;
35
+ files . forEach ( f => mocha . addFile ( path . resolve ( testsRoot , f ) ) ) ;
33
36
34
37
try {
35
38
// Run the mocha test
36
- mocha . run ( ( failures ) => {
39
+ mocha . run ( failures => {
37
40
if ( failures > 0 ) {
38
41
e ( new Error ( `${ failures } tests failed.` ) ) ;
39
42
} else {
40
43
c ( ) ;
41
44
}
42
45
} ) ;
43
46
} catch ( err ) {
47
+ // tslint:disable-next-line:no-console
48
+ console . error ( err ) ;
44
49
e ( err ) ;
45
50
}
46
51
} ) ;
0 commit comments