import * as uuid from 'uuid' ; import * as vscode from 'vscode' ; import { TestRunner , TestRunType } from '../testRunner' ; import { TestCaseInfo , TestExecutionInfo , TestFileInfo , TestInfoKind , TestType } from '../types' ; import { FORCE_LWC_TEST_DEBUG_LOG_NAME } from '../types/constants' ; import { isLwcJestTest } from '../utils' ; import { telemetryService } from '../../telemetry' ; import { workspaceService } from '../workspace/workspaceService' ; const debugSessionStartTimes = new Map < string , [ number , number ] > ( ) ; param command param args param cwd export function getDebugConfiguration ( command , args , cwd ) { const sfdxDebugSessionId = uuid . v4 ( ) ; const debugConfiguration = { sfdxDebugSessionId , type : 'node' , request : 'launch' , name : 'Debug LWC test(s)' , cwd , runtimeExecutable : command , args , resolveSourceMapLocations : [ '**' , '!**/node_modules/**' ] , console : 'integratedTerminal' , internalConsoleOptions : 'openOnSessionStart' , port : 9229 , disableOptimisticBPs : true } ; return debugConfiguration ; } param testExecutionInfo export async function forceLwcTestDebug ( testExecutionInfo ) { const testRunner = new TestRunner ( testExecutionInfo , TestRunType . DEBUG ) ; const shellExecutionInfo = testRunner . getShellExecutionInfo ( ) ; if ( shellExecutionInfo ) { const { command , args , workspaceFolder , testResultFsPath } = shellExecutionInfo ; testRunner . startWatchingTestResults ( testResultFsPath ) ; const debugConfiguration = getDebugConfiguration ( command , args , workspaceFolder . uri . fsPath ) ; await vscode . debug . startDebugging ( workspaceFolder , debugConfiguration ) ; } } param data export async function forceLwcTestCaseDebug ( data ) { const { testExecutionInfo } = data ; await forceLwcTestDebug ( testExecutionInfo ) ; } param data export async function forceLwcTestFileDebug ( data ) { const { testExecutionInfo } = data ; await forceLwcTestDebug ( testExecutionInfo ) ; } /**
 * Debug the test of currently focused editor
 */ export async function forceLwcTestDebugActiveTextEditorTest ( ) { const { activeTextEditor } = vscode . window ; if ( activeTextEditor && isLwcJestTest ( activeTextEditor . document ) ) { const testExecutionInfo = { kind : TestInfoKind . TEST_FILE , testType : TestType . LWC , testUri : activeTextEditor . document . uri } ; await forceLwcTestFileDebug ( { testExecutionInfo } ) ; } } param session export function handleDidStartDebugSession ( session ) { const { configuration } = session ; const { sfdxDebugSessionId } = configuration ; const startTime = process . hrtime ( ) ; debugSessionStartTimes . set ( sfdxDebugSessionId , startTime ) ; } param session export function handleDidTerminateDebugSession ( session ) { const { configuration } = session ; const startTime = debugSessionStartTimes . get ( configuration . sfdxDebugSessionId ) ; if ( Array . isArray ( startTime ) ) { telemetryService . sendCommandEvent ( FORCE_LWC_TEST_DEBUG_LOG_NAME , startTime , { workspaceType : workspaceService . getCurrentWorkspaceTypeForTelemetry ( ) } ) ; } }