import * as fs from 'fs' ; import * as path from 'path' ; import * as vscode from 'vscode' ; import * as which from 'which' ; import { nls } from '../../messages' ; import { telemetryService } from '../../telemetry' ; import { workspaceService } from './workspaceService' ; param cwd returns export function getLwcTestRunnerExecutable ( cwd ) { const workspaceType = workspaceService . getCurrentWorkspaceType ( ) ; if ( workspaceService . isSFDXWorkspace ( workspaceType ) ) { const lwcTestRunnerExecutable = path . join ( cwd , 'node_modules' , '.bin' , 'lwc-jest' ) ; if ( fs . existsSync ( lwcTestRunnerExecutable ) ) { return lwcTestRunnerExecutable ; } else { const errorMessage = nls . localize ( 'no_lwc_jest_found_text' ) ; console . error ( errorMessage ) ; vscode . window . showErrorMessage ( errorMessage ) ; telemetryService . sendException ( 'lwc_test_no_lwc_jest_found' , errorMessage ) ; } } else if ( workspaceService . isCoreWorkspace ( workspaceType ) ) { const lwcTestRunnerExecutable = which . sync ( 'lwc-test' , { nothrow : true } ) ; if ( lwcTestRunnerExecutable && fs . existsSync ( lwcTestRunnerExecutable ) ) { return lwcTestRunnerExecutable ; } else { const errorMessage = nls . localize ( 'no_lwc_testrunner_found_text' ) ; console . error ( errorMessage ) ; vscode . window . showErrorMessage ( errorMessage ) ; telemetryService . sendException ( 'lwc_test_no_lwc_testrunner_found' , errorMessage ) ; } } else { telemetryService . sendException ( 'lwc_test_no_lwc_testrunner_found' , 'Unsupported workspace' ) ; } }