import * as vscode from 'vscode' ; import { GetPesterInvokeScript } from './powershellScripts' ; import { PowerShellExtensionClient } from './powershellExtension' ; export class PesterTaskInvoker { private currentTaskExecution : vscode . TaskExecution | undefined ; constructor ( private readonly powershellExtensionClient , private readonly outputPath ) { outputPath = outputPath . replace ( /'/g , "''" ) ; } public async runTests ( filePath , lineNumber ? ) { const pwshExePath = ( await this . powershellExtensionClient . GetVersionDetails ( ) ) . exePath ; this . currentTaskExecution ?. terminate ( ) ; const task = this . createTask ( pwshExePath , filePath , this . outputPath , lineNumber ) ; task . presentationOptions . echo = false ; this . currentTaskExecution = await vscode . tasks . executeTask ( task ) ; } public async stopTests ( ) { this . currentTaskExecution ?. terminate ( ) ; } private createTask ( pwshExePath , filePath , outputPath , lineNumber ? ) { const scriptPath = filePath . replace ( /'/g , "''" ) ; const shellExec = new vscode . ShellExecution ( GetPesterInvokeScript ( scriptPath , outputPath , lineNumber ) , { executable : pwshExePath , shellArgs : [ "-NoLogo" , "-NoProfile" , "-NonInteractive" , "-Command" ] } ) ; return new vscode . Task ( { type : "pester" } , vscode . TaskScope . Workspace , "Pester" , "Pester Test Explorer" , shellExec , "$pester" ) ; } }