import { When } from "cucumber" ; import * as textRunner from "text-runner-core" ; import * as helpers from "./helpers" ; import { TRWorld } from "./world" ; When ( /^calling:$/ , { timeout : 20000 } , async function ( jsText ) { const world = this as TRWorld ; const config = { sourceDir : world . workspace . platformified ( ) } ; let command = new textRunner . commands . Run ( config ) ; let observer = new textRunner . ActivityCollector ( command ) ; let asyncFunc = async function ( tr , ac ) { } ; const funcText = `
  asyncFunc = async function runner(textRunner, MyObserverClass) {
    ${ jsText }
  }` ; eval ( funcText ) ; try { await asyncFunc ( textRunner , textRunner . ActivityCollector ) ; world . apiResults = observer . results ( ) ; } catch ( e ) { world . apiException = e ; } } ) ; When ( /^calling Text-Runner$/ , { timeout : 20000 } , async function ( ) { const world = this as TRWorld ; const command = new textRunner . commands . Run ( { sourceDir : world . workspace . platformified ( ) } ) ; const activityCollector = new textRunner . ActivityCollector ( command ) ; try { await command . execute ( ) ; } catch ( e ) { world . apiException = e ; } world . apiResults = activityCollector . results ( ) ; } ) ; When ( /^(trying to run|running) "([^"]*)"$/ , { timeout : 30000 } , async function ( tryingText , command ) { const world = this as TRWorld ; world . finishedProcess = await helpers . executeCLI ( command , determineExpectError ( tryingText ) , world ) ; } ) ; When ( /^(trying to run|running) Text-Runner$/ , { timeout : 30000 } , async function ( tryingText ) { const world = this as TRWorld ; world . finishedProcess = await helpers . executeCLI ( "run" , determineExpectError ( tryingText ) , world ) ; } ) ; When ( /^(trying to run|running) Text-Runner in the source directory$/ , { timeout : 30000 } , async function ( tryingText ) { const world = this as TRWorld ; world . finishedProcess = await helpers . executeCLI ( "run" , determineExpectError ( tryingText ) , world , { cwd : world . workspace . platformified ( ) , } ) ; } ) ; function determineExpectError ( tryingText ) { if ( tryingText === "running" ) { return false ; } else if ( tryingText === "executing" ) { return false ; } else if ( tryingText === "calling" ) { return false ; } else { return true ; } }