55
66import * as etest from '@vscode/test-electron' ;
77import * as path from 'path' ;
8+ import * as configData from '../package.json' ;
89
910/**
1011 * Run mocha tests from project's tests folder.
@@ -13,25 +14,97 @@ import * as path from 'path';
1314 */
1415async function main ( ) : Promise < void > {
1516 const [ , , tests , extension = '' ] = process . argv ;
16- const extensionRootPath = path . resolve ( __dirname , ' ../../') ;
17+ const extensionRootPath = path . resolve ( __dirname , __dirname . endsWith ( 'out/build' ) ? ' ../../' : ' ../') ;
1718 const extensionDevelopmentPath = path . resolve ( extensionRootPath , extension ) ;
1819 const extensionTestsPath = path . resolve ( extensionRootPath , 'out' , 'test' , tests ) ;
1920 const integrationWorkspacePath = path . resolve ( extensionRootPath , 'test' , 'fixtures' , 'components' , 'components.code-workspace' ) ;
2021 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+ const boolPattern = / ^ ( t r u e | 1 | y e s ) $ / i;
40+ const verbose = boolPattern . test ( process . env . VERBOSE ) ;
41+
42+ /* eslint-disable no-console */
43+ if ( process . env . COVERAGE ) {
44+ console . log ( `Running nyc as part of the ${ tests } tests execution...` )
45+ // const { instrument } = require('istanbul-lib-instrument');
46+ // const __instrumenter = new Instrumenter();
47+
48+ const nyc = require ( 'nyc' ) ;
49+ // const nycConfig = {
50+ // cwd: path.resolve(__dirname),
51+ // require: ['ts-node/register'],
52+ // extension: ['.ts'],
53+ // reporter: ['lcov', 'text-summary'],
54+ // };
55+ const nycConfig = configData . nyc ;
56+ const nycInstance = new nyc ( nycConfig ) ;
57+
58+ nycInstance . wrap ( ) ;
59+
60+ // // // Now run your tests with the Electron runner
61+ // // void (async () => {
62+ // // try {
63+ // // const result = await etest.runTests({
64+ // // extensionDevelopmentPath,
65+ // // extensionTestsPath,
66+ // // launchArgs: [
67+ // // tests === 'integration' ? integrationWorkspacePath : unitTestWorkspacePath,
68+ // // '--disable-workspace-trust',
69+ // // ],
70+ // // });
71+
72+ // // console.error(`Run tests spawn result: ${result}`);
73+ // // process.exit(result);
74+ // // } catch (err) {
75+ // // console.error(`Failed to run tests: ${err}`);
76+ // // process.exit(1);
77+ // // }
78+ // // })();
79+ } else {
80+ console . log ( `Running the ${ tests } tests...` )
3481 }
82+ try {
83+ const result = await etest . runTests ( {
84+ extensionDevelopmentPath,
85+ extensionTestsPath,
86+ launchArgs : [
87+ tests === 'integration' ? integrationWorkspacePath : unitTestWorkspacePath ,
88+ '--disable-workspace-trust' ,
89+ verbose ? '--verbose' : ''
90+ ] ,
91+ } ) ;
92+
93+ // eslint-disable-next-line no-console
94+ console . error ( `Run tests spawn result: ${ result } ` ) ;
95+ process . exit ( result ) ;
96+ } catch ( err ) {
97+ // eslint-disable-next-line no-console
98+ console . error ( `Failed to run tests: ${ err } ` ) ;
99+ process . exit ( 1 ) ;
100+ }
101+ // }
35102}
36103
37- void main ( ) ;
104+ // void main();
105+
106+ main ( ) . catch ( ( err ) => {
107+ // eslint-disable-next-line no-console
108+ console . error ( 'Failed to run tests:' , err ) ;
109+ process . exit ( 1 ) ;
110+ } ) ;
0 commit comments