import { SerializableResponse } from 'common' ; import { Task , TaskSet } from 'durable-functions/lib/src/classes' ; import { TestContextData , TestGroupName } from 'functional-tests' ; import _ from 'lodash' ; import { OrchestrationSteps } from '../orchestration/orchestration-steps' ; import { E2EScanScenarioDefinition } from './e2e-scan-scenario-definitions' ; export class ScanScenarioDriver { protected readonly testContextData : TestContextData ; protected encounteredError : boolean = false ; constructor ( private readonly orchestrationSteps , public readonly testDefinition ) { this . testContextData = testDefinition . initialTestContextData ; } public * submitScanPhase ( ) { yield * this . skipIfError ( this . submitScanForTests ( ) , this . testDefinition . testGroups . postScanSubmissionTests ) ; } public * waitForScanCompletionPhase ( ) { let testsToRun = [ ] . concat ( this . testDefinition . testGroups . postScanCompletionTests , this . testDefinition . testGroups . scanReportTests ) ; testsToRun = _ . uniq ( _ . compact ( testsToRun ) ) ; yield * this . skipIfError ( this . orchestrationSteps . waitForBaseScanCompletion ( this . testContextData . scanId ) , testsToRun ) ; } public * afterScanCompletedPhase ( ) { const scanRequestOptions = this . testDefinition . scanOptions ; if ( scanRequestOptions . deepScan ) { yield * this . skipIfError ( this . orchestrationSteps . waitForDeepScanCompletion ( this . testContextData . scanId ) , this . testDefinition . testGroups . postDeepScanCompletionTests ) ; } if ( scanRequestOptions . scanNotificationUrl ) { yield * this . skipIfError ( this . orchestrationSteps . waitForScanCompletionNotification ( this . testContextData . scanId ) , this . testDefinition . testGroups . postScanCompletionNotificationTests ) ; } yield * this . skipIfError ( this . orchestrationSteps . trackScanRequestCompleted ( ) ) ; } private * submitScanForTests ( ) { this . testContextData . scanId = yield * this . orchestrationSteps . invokeSubmitScanRequestRestApi ( this . testContextData . scanUrl , this . testDefinition . scanOptions ) ; } private * skipIfError ( generator , testGroupNames ? ) { if ( this . encounteredError !== true ) { try { yield * generator ; } catch { this . encounteredError = true ; } } yield * this . orchestrationSteps . runFunctionalTestGroups ( this . testDefinition . readableName , this . testContextData , testGroupNames ) ; } }