import * as jest from 'jest' ; import * as fs from 'fs-extra' ; import * as path from 'path' ; import { AggregatedResult } from '@jest/test-result' ; import { tempRepoFolder } from '../common' ; const extensionRoot = path . join ( __dirname , '..' , '..' , '..' ) ; type Output = { results : AggregatedResult ; } ; export function run ( ) { ( process as any ) . __VSCODE = require ( 'vscode' ) ; const jestConfigFile = path . join ( extensionRoot , 'jest.extension.config.js' ) ; const jestConfig = require ( jestConfigFile ) ; return new Promise ( ( resolve , reject ) => { jest . runCLI ( jestConfig , [ extensionRoot ] ) . catch ( error => { delete ( process as any ) . __VSCODE ; console . error ( 'Calling jest.runCLI failed' , error ) ; reject ( error ) ; } ) . then ( output => { delete ( process as any ) . __VSCODE ; if ( ! output ) { return resolve ( ) ; } const results = output as Output ; if ( results . results . numFailedTestSuites || results . results . numFailedTests ) { fs . appendFileSync ( path . join ( tempRepoFolder , 'tests.failed' ) , 'failed' ) ; } resolve ( ) ; } ) ; } ) ; }