5
5
6
6
import * as etest from '@vscode/test-electron' ;
7
7
import * as path from 'path' ;
8
+ import * as configData from '../package.json' ;
8
9
9
10
/**
10
11
* Run mocha tests from project's tests folder.
@@ -13,25 +14,93 @@ import * as path from 'path';
13
14
*/
14
15
async function main ( ) : Promise < void > {
15
16
const [ , , tests , extension = '' ] = process . argv ;
16
- const extensionRootPath = path . resolve ( __dirname , ' ../../') ;
17
+ const extensionRootPath = path . resolve ( __dirname , __dirname . endsWith ( 'out/build' ) ? ' ../../' : ' ../') ;
17
18
const extensionDevelopmentPath = path . resolve ( extensionRootPath , extension ) ;
18
19
const extensionTestsPath = path . resolve ( extensionRootPath , 'out' , 'test' , tests ) ;
19
20
const integrationWorkspacePath = path . resolve ( extensionRootPath , 'test' , 'fixtures' , 'components' , 'components.code-workspace' ) ;
20
21
const unitTestWorkspacePath = path . resolve ( extensionRootPath , 'test' , 'fixtures' , 'components' , 'empty.code-workspace' ) ;
21
- try {
22
- await etest . runTests ( {
23
- extensionDevelopmentPath,
24
- extensionTestsPath,
25
- launchArgs : [
26
- tests === 'integration' ? integrationWorkspacePath : unitTestWorkspacePath ,
27
- '--disable-workspace-trust' ,
28
- ] ,
29
- } ) ;
30
- } catch ( err ) {
31
- // eslint-disable-next-line no-console
32
- console . error ( `Failed to run tests: ${ err } ` ) ;
33
- process . exit ( 1 ) ;
22
+
23
+ /* eslint-disable no-console */
24
+ console . info ( `${ __filename } : Started` ) ;
25
+
26
+ console . info ( `${ path . basename ( __filename ) } : __dirname: ${ __dirname } ` ) ;
27
+ console . info ( `${ path . basename ( __filename ) } : extensionRootPath: ${ extensionRootPath } ` ) ;
28
+ console . info ( `${ path . basename ( __filename ) } : extensionDevelopmentPath: ${ extensionDevelopmentPath } ` ) ;
29
+ console . info ( `${ path . basename ( __filename ) } : extensionTestsPath: ${ extensionTestsPath } ` ) ;
30
+ console . info ( `${ path . basename ( __filename ) } : integrationWorkspacePath: ${ integrationWorkspacePath } ` ) ;
31
+ console . info ( `${ path . basename ( __filename ) } : unitTestWorkspacePath: ${ unitTestWorkspacePath } ` ) ;
32
+
33
+ console . info ( `${ path . basename ( __filename ) } : NYC config vales:` ) ;
34
+ console . log ( 'NYC include paths:' , path . resolve ( '../src/**/*' ) ) ;
35
+ console . log ( 'NYC report-dir:' , process . env . NYC_REPORT_DIR || 'coverage (default)' ) ;
36
+ console . log ( 'NYC temp-dir:' , process . env . NYC_TEMP_DIR || '.nyc_output (default)' ) ;
37
+
38
+
39
+ /* eslint-disable no-console */
40
+ if ( process . env . COVERAGE ) {
41
+ console . log ( `Running nyc as part of the ${ tests } tests execution...` )
42
+ // const { instrument } = require('istanbul-lib-instrument');
43
+ // const __instrumenter = new Instrumenter();
44
+
45
+ const nyc = require ( 'nyc' ) ;
46
+ // const nycConfig = {
47
+ // cwd: path.resolve(__dirname),
48
+ // require: ['ts-node/register'],
49
+ // extension: ['.ts'],
50
+ // reporter: ['lcov', 'text-summary'],
51
+ // };
52
+ const nycConfig = configData . nyc ;
53
+ const nycInstance = new nyc ( nycConfig ) ;
54
+
55
+ nycInstance . wrap ( ) ;
56
+
57
+ // // // Now run your tests with the Electron runner
58
+ // // void (async () => {
59
+ // // try {
60
+ // // const result = await etest.runTests({
61
+ // // extensionDevelopmentPath,
62
+ // // extensionTestsPath,
63
+ // // launchArgs: [
64
+ // // tests === 'integration' ? integrationWorkspacePath : unitTestWorkspacePath,
65
+ // // '--disable-workspace-trust',
66
+ // // ],
67
+ // // });
68
+
69
+ // // console.error(`Run tests spawn result: ${result}`);
70
+ // // process.exit(result);
71
+ // // } catch (err) {
72
+ // // console.error(`Failed to run tests: ${err}`);
73
+ // // process.exit(1);
74
+ // // }
75
+ // // })();
76
+ } else {
77
+ console . log ( `Running the ${ tests } tests...` )
34
78
}
79
+ try {
80
+ const result = await etest . runTests ( {
81
+ extensionDevelopmentPath,
82
+ extensionTestsPath,
83
+ launchArgs : [
84
+ tests === 'integration' ? integrationWorkspacePath : unitTestWorkspacePath ,
85
+ '--disable-workspace-trust' ,
86
+ ] ,
87
+ } ) ;
88
+
89
+ // eslint-disable-next-line no-console
90
+ console . error ( `Run tests spawn result: ${ result } ` ) ;
91
+ process . exit ( result ) ;
92
+ } catch ( err ) {
93
+ // eslint-disable-next-line no-console
94
+ console . error ( `Failed to run tests: ${ err } ` ) ;
95
+ process . exit ( 1 ) ;
96
+ }
97
+ // }
35
98
}
36
99
37
- void main ( ) ;
100
+ // void main();
101
+
102
+ main ( ) . catch ( ( err ) => {
103
+ // eslint-disable-next-line no-console
104
+ console . error ( 'Failed to run tests:' , err ) ;
105
+ process . exit ( 1 ) ;
106
+ } ) ;
0 commit comments