"use strict" ; import * as path from "path" ; import * as Mocha from "mocha" ; const NYC = require ( "nyc" ) ; import * as glob from "glob" ; import "ts-node/register" ; import "source-map-support/register" ; if ( process . platform === "linux" ) { const tty = require ( "tty" ) ; if ( ! tty . getWindowSize ) { tty . getWindowSize = ( ) : number [ ] => { return [ 80 , 75 ] ; } ; } } export async function run ( ) { const testsRoot = path . resolve ( __dirname , ".." ) ; const nyc = new NYC ( { extends : "@istanbuljs/nyc-config-typescript" , cwd : path . join ( __dirname , ".." , ".." ) , reporter : [ "text-summary" , "html" , "lcov" , "cobertura" ] , all : true , silent : false , instrument : true , hookRequire : true , hookRunInContext : true , hookRunInThisContext : true , include : [ "dist/**/*.js" ] , exclude : [ "dist/test/**" ] , } ) ; await nyc . wrap ( ) ; const myFilesRegex = /vscode-taskexplorer\/dist/ ; const filterFn = myFilesRegex . test . bind ( myFilesRegex ) ; if ( Object . keys ( require . cache ) . filter ( filterFn ) . length > 1 ) { console . warn ( "NYC initialized after modules were loaded" , Object . keys ( require . cache ) . filter ( filterFn ) ) ; } await nyc . createTempDirectory ( ) ; const mocha = new Mocha ( { ui : "tdd" , useColors : true , timeout : 30000 , retries : 1 , reporter : "mocha-multi-reporters" , reporterOptions : { reporterEnabled : "spec, mocha-junit-reporter" , mochaJunitReporterReporterOptions : { mochaFile : __dirname + "/../../coverage/junit/extension_tests.xml" , suiteTitleSeparatedBy : ": " } } } ) ; mocha . useColors ( true ) ; const files = glob . sync ( "**/*.test.js" , { cwd : testsRoot } ) ; files . forEach ( f => mocha . addFile ( path . resolve ( testsRoot , f ) ) ) ; const failures = await new Promise ( resolve => mocha . run ( resolve ) ) ; await nyc . writeCoverageFile ( ) ; console . log ( await captureStdout ( nyc . report . bind ( nyc ) ) ) ; if ( failures > 0 ) { throw new Error ( `${ failures } tests failed.` ) ; } } async function captureStdout ( fn ) { let w = process . stdout . write , buffer = "" ; process . stdout . write = ( s ) => { buffer = buffer + s ; return true ; } ; await fn ( ) ; process . stdout . write = w ; return buffer ; }