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,94 @@ 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+ /* 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...` )
3478 }
79+ try {
80+ const result = await etest . runTests ( {
81+ extensionDevelopmentPath,
82+ extensionTestsPath,
83+ launchArgs : [
84+ tests === 'integration' ? integrationWorkspacePath : unitTestWorkspacePath ,
85+ '--disable-workspace-trust' ,
86+ '--verbose'
87+ ] ,
88+ } ) ;
89+
90+ // eslint-disable-next-line no-console
91+ console . error ( `Run tests spawn result: ${ result } ` ) ;
92+ process . exit ( result ) ;
93+ } catch ( err ) {
94+ // eslint-disable-next-line no-console
95+ console . error ( `Failed to run tests: ${ err } ` ) ;
96+ process . exit ( 1 ) ;
97+ }
98+ // }
3599}
36100
37- void main ( ) ;
101+ // void main();
102+
103+ main ( ) . catch ( ( err ) => {
104+ // eslint-disable-next-line no-console
105+ console . error ( 'Failed to run tests:' , err ) ;
106+ process . exit ( 1 ) ;
107+ } ) ;
0 commit comments