import { Application } from "../../automation" ; import * as assert from "assert" ; import * as cp from "child_process" ; import { sleep , waitUntil } from "./helpers/utilities" ; import { SmokeTestsConstants } from "./helpers/smokeTestsConstants" ; import { vscodeManager } from "./main" ; import { SmokeTestLogger } from "./helpers/smokeTestLogger" ; import { TestRunArguments } from "./helpers/testConfigProcessor" ; import TestProject from "./helpers/testProject" ; import AutomationHelper from "./helpers/AutomationHelper" ; const RNWDebugConfigName = "Debug RN Wind" ; const RNWHermesDebugConfigName = "Debug RN Wind Hermes - Experimental" ; const RNwindowsSetBreakpointOnLine = 1 ; const RNwindowsHermesSetBreakpointOnLine = 15 ; const debugWindowsTestTime = SmokeTestsConstants . windowsTestTimeout ; export function startDebugRNWTests ( windowsProject , windowsHermesProject , testParameters ) { describe ( "Debugging Windows" , ( ) => { let app ; let currentWindowsAppName = "" ; let automationHelper ; async function initApp ( workspaceOrFolder , sessionName ? , locale ? ) { app = await vscodeManager . runVSCode ( workspaceOrFolder , sessionName , locale ) ; automationHelper = new AutomationHelper ( app ) ; return app ; } async function disposeAll ( ) { SmokeTestLogger . info ( "Dispose all ..." ) ; if ( app ) { SmokeTestLogger . info ( "Stopping React Native packager ..." ) ; await stopPackager ( ) ; SmokeTestLogger . info ( "Stopping application ..." ) ; await app . stop ( ) ; } terminateWindowsApp ( currentWindowsAppName ) ; } afterEach ( disposeAll ) ; function terminateWindowsApp ( appName ) { SmokeTestLogger . info ( `*** Terminating ${ appName } Windows application` ) ; const terminateWindowsAppCommand = `taskkill/im ${ appName }.exe /t /f` ; cp . execSync ( terminateWindowsAppCommand ) ; } async function stopPackager ( ) { if ( app ) { await automationHelper . runCommandWithRetry ( SmokeTestsConstants . stopPackagerCommand ) ; await sleep ( 3000 ) ; } } async function checkIfAppIsInstalledOnWindows ( appName , timeout ) { SmokeTestLogger . info ( `Searching for app ${ appName } patterns...` ) ; const condition = ( ) => { return ( cp . execSync ( "tasklist" ) . toString ( ) . toLowerCase ( ) . indexOf ( appName . toLowerCase ( ) ) > 0 ) ; } ; const result = await waitUntil ( condition , timeout , 5000 ) ; if ( result ) { SmokeTestLogger . success ( `Found launched ${ appName }` ) ; } else { SmokeTestLogger . error ( `App ${ appName } not found` ) ; } return result ; } async function windowsApplicationTest ( testname , project , isHermesProject = false ) { try { app = await initApp ( project . workspaceDirectory , testname ) ; await automationHelper . openFileWithRetry ( project . projectEntryPointFile ) ; await app . workbench . editors . scrollTop ( ) ; SmokeTestLogger . info ( `${ testname }: App.js file is opened` ) ; let debugConfigName ; let setBreakpointOnLine ; if ( isHermesProject ) { debugConfigName = RNWHermesDebugConfigName ; setBreakpointOnLine = RNwindowsHermesSetBreakpointOnLine ; } else { debugConfigName = RNWDebugConfigName ; setBreakpointOnLine = RNwindowsSetBreakpointOnLine ; } await app . workbench . debug . setBreakpointOnLine ( setBreakpointOnLine ) ; SmokeTestLogger . info ( `${ testname }: Breakpoint is set on line ${ setBreakpointOnLine }` ) ; SmokeTestLogger . info ( `${ testname }: Chosen debug configuration: ${ debugConfigName }` ) ; SmokeTestLogger . info ( `${ testname }: Starting debugging` ) ; await automationHelper . runDebugScenarioWithRetry ( debugConfigName ) ; await checkIfAppIsInstalledOnWindows ( currentWindowsAppName , SmokeTestsConstants . windowsAppBuildAndInstallTimeout ) ; await app . workbench . debug . waitForDebuggingToStart ( ) ; SmokeTestLogger . info ( `${ testname }: Debugging started` ) ; await automationHelper . waitForStackFrameWithRetry ( sf => sf . name === project . projectEntryPointFile && sf . lineNumber === setBreakpointOnLine , `looking for App.js and line ${ setBreakpointOnLine }` ) ; SmokeTestLogger . info ( `${ testname }: Stack frame found` ) ; await app . workbench . debug . stepOver ( ) ; await sleep ( SmokeTestsConstants . debugConsoleSearchTimeout ) ; SmokeTestLogger . info ( `${ testname }: Searching for "Test output from debuggee" string in console` ) ; await automationHelper . runCommandWithRetry ( "Debug: Focus on Debug Console View" ) ; let found = await automationHelper . waitForOutputWithRetry ( "Test output from debuggee" ) ; assert . notStrictEqual ( found , false , '"Test output from debuggee" string is missing in debug console' ) ; SmokeTestLogger . success ( `${ testname }: "Test output from debuggee" string is found` ) ; await automationHelper . disconnectFromDebuggerWithRetry ( ) ; SmokeTestLogger . info ( `${ testname }: Debugging is stopped` ) ; } catch ( e ) { SmokeTestLogger . error ( `${ testname } failed: ${ e . toString ( ) }` ) ; await stopPackager ( ) ; return this . skip ( ) ; } } if ( process . platform === "win32" && testParameters . RunWindowsTests && ! testParameters . SkipUnstableTests ) { it ( "RN Windows app Debug test" , async function ( ) { this . timeout ( debugWindowsTestTime ) ; currentWindowsAppName = SmokeTestsConstants . RNWAppName ; await windowsApplicationTest ( "RN Windows app Debug test" , windowsProject ) ; } ) ; it ( "RN Windows Hermes app Debug test" , async function ( ) { this . timeout ( debugWindowsTestTime ) ; currentWindowsAppName = SmokeTestsConstants . RNWHermesAppName ; await windowsApplicationTest ( "RN Windows Hermes app Debug test" , windowsHermesProject , true ) ; } ) ; } } ) ; }