import { After , Before } from "cucumber" ; import { endChildProcesses } from "end-child-processes" ; import { promises as fs } from "fs" ; import * as path from "path" ; import * as rimraf from "rimraf" ; import * as textRunner from "text-runner-core" ; import * as tmp from "tmp-promise" ; import * as util from "util" ; import { TRWorld } from "./world" ; const rimrafp = util . promisify ( rimraf ) ; Before ( async function ( ) { const world = this as TRWorld ; if ( process . env . CUCUMBER_PARALLEL ) { const tempDir = await tmp . dir ( ) ; world . workspace = new textRunner . files . AbsoluteDirPath ( tempDir . path ) ; } else { world . workspace = new textRunner . files . AbsoluteDirPath ( path . join ( process . cwd ( ) , "tmp" ) ) ; } let workspaceExists = false ; try { await fs . stat ( world . workspace . platformified ( ) ) ; workspaceExists = true ; } catch ( e ) { } if ( workspaceExists ) { await fs . rmdir ( world . workspace . platformified ( ) , { recursive : true } ) ; } await fs . mkdir ( world . workspace . platformified ( ) , { recursive : true } ) ; } ) ; After ( { timeout : 20000 } , async function ( scenario ) { const world = this as TRWorld ; await endChildProcesses ( ) ; if ( scenario . result . status === "failed" ) { console . log ( "\ntest artifacts are located in" , world . workspace . platformified ( ) ) ; } else { await rimrafp ( world . workspace . platformified ( ) ) ; } } ) ; Before ( { tags : "@debug" } , function ( ) { const world = this as TRWorld ; world . debug = true ; } ) ; After ( { tags : "@debug" } , function ( ) { const world = this as TRWorld ; world . debug = false ; } ) ;