import * as path from 'path' ; import * as fs from 'fs' ; import { instrument } from './coverage' ; import { runTests } from 'vscode-test' ; const XVFB_DISPLAY = ':10' ; function main ( ) { const xDisplay = process . env [ 'DISPLAY' ] ; if ( xDisplay ) { console . log ( `Using DISPLAY=${ xDisplay }` ) ; } else { console . warn ( `No DISPLAY env variable found, exporting DISPLAY=${ XVFB_DISPLAY }` ) ; process . env [ 'DISPLAY' ] = XVFB_DISPLAY ; } const extensionRootPath = path . resolve ( __dirname , '../../' ) ; console . log ( 'Extension root path: ' + extensionRootPath ) ; const launchArgs = [ path . resolve ( extensionRootPath , 'test/samples' ) ] ; const packageJsonPath = path . resolve ( extensionRootPath , 'package.json' ) ; const package_json = fs . readFileSync ( packageJsonPath , 'utf8' ) ; var content = JSON . parse ( package_json ) ; const extensionDevelopmentPath = extensionRootPath ; var outPath ; if ( process . argv . indexOf ( '--coverage' ) >= 0 ) { content . main = 'out-cov/src/extension' ; instrument ( ) ; outPath = path . resolve ( extensionRootPath , 'out-cov' ) ; process . env [ 'GENERATE_COVERAGE' ] = '1' ; } else { content . main = 'out/src/extension' ; outPath = path . resolve ( extensionRootPath , 'out' ) ; } fs . writeFileSync ( packageJsonPath , JSON . stringify ( content , null , 2 ) , 'utf-8' ) ; const extensionTestsPath = path . resolve ( outPath , 'test/suite/index' ) ; runTests ( { extensionDevelopmentPath , extensionTestsPath , launchArgs } ) . catch ( err => { console . error ( 'Failed to run tests' , err ) ; process . exit ( 1 ) ; } ) . then ( ( ) => process . exit ( 0 ) ) ; } main ( ) ;