Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
outcomeFor(error: Error | any): ProblemIndication {
return match(error)
.when(ImplementationPendingError, _ => new ImplementationPending(error))
.when(TestCompromisedError, _ => new ExecutionCompromised(error))
.when(AssertionError, _ => new ExecutionFailedWithAssertionError(error))
.when(Error, _ => /AssertionError/.test(error.constructor.name) // mocha
? new ExecutionFailedWithAssertionError(error)
: new ExecutionFailedWithError(error))
.else(_ => new ExecutionFailedWithError(error));
}
}
notifyOf(event: DomainEvent): void {
match(event)
.when(InteractionFinished, ({ value, outcome }: InteractionFinished) => {
// todo: clean up
if (this.stage.theShowHasStarted() && outcome.isWorseThan(ImplementationPending)) {
const id = CorrelationId.create();
this.stage.manager.notifyOf(new AsyncOperationAttempted(
new Description(`[${ this.constructor.name }] Taking screenshot of '${ value.name.value }'...`),
id,
));
BrowseTheWeb.as(this.stage.theActorInTheSpotlight()).takeScreenshot()
.then(screenshot => {
this.stage.manager.notifyOf(new ArtifactGenerated(
value.name,
Photo.fromBase64(screenshot),
notifyOf(event: DomainEvent): void {
match(event)
.when(SceneStarts, (e: SceneStarts) => {
this.firstError = new FirstError();
this.startTimes.recordStartOf(e);
// Print scenario header
this.printer.println(this.theme.separator('-'));
this.printer.println(e.value.location.path.value, e.value.location.line ? `:${ e.value.location.line }` : '');
this.printer.println();
this.printer.println(this.theme.heading(e.value.category.value, ': ', e.value.name.value));
this.printer.println();
})
.when(TaskStarts, (e: TaskStarts) => {
this.printer.indent();
public static from(text: string): Tag[] {
const [ , type, val ] = Tags.Pattern.exec(text);
return match(type.toLowerCase())
.when('manual', _ => [ new ManualTag() ])
.when(/issues?/, _ => val.split(',').map(value => new IssueTag(value.trim())))
.else(value => [ new ArbitraryTag(value.trim()) ]);
}
}
handle(event: DomainEvent, report: SceneReport): SceneReport {
return match(event)
.when(SceneStarts, (e: SceneStarts) => report.executionStartedAt(e.timestamp))
.when(ActivityStarts, (e: ActivityStarts) => report.activityStarted(e.value, e.timestamp))
.when(ActivityFinished, (e: ActivityFinished) => report.activityFinished(e.value, e.outcome, e.timestamp))
.when(SceneFinished, (e: SceneFinished) => {
return report
.executionFinishedAt(e.timestamp)
.executionFinishedWith(e.value, e.outcome);
})
.else(e => super.handle(e, report));
}
}
handle(event: DomainEvent, report: SceneReport): SceneReport {
return match(event)
.when(SceneStarts, (e: SceneStarts) => {
return report
.activityStarted(this.asActivity(e.value), e.timestamp)
.executionStartedAt(e.timestamp);
})
.when(SceneTemplateDetected, (e: SceneTemplateDetected) => {
return report.withScenarioOutline(e.template);
})
.when(SceneParametersDetected, (e: SceneParametersDetected) => {
return report.withScenarioParametersOf(e.scenario, e.value);
})
.when(ActivityStarts, (e: ActivityStarts) => {
return report.activityStarted(e.value, e.timestamp);
})
.when(ActivityFinished, (e: ActivityFinished) => {
return report.activityFinished(e.value, e.outcome, e.timestamp);
.then((outcome: Outcome) =>
match, Outcome>(outcome)
.when(ExpectationMet, o => new ExpectationNotMet(this.flipped(this.expectation.toString()), o.expected, o.actual))
.else(o => new ExpectationMet(this.flipped(this.expectation.toString()), o.expected, o.actual)));
}
static fromJSON = (o: SerialisedOutcome) => match(o.code)
.when(ExecutionCompromised.Code, _ => ExecutionCompromised.fromJSON(o))
.when(ExecutionFailedWithError.Code, _ => ExecutionFailedWithError.fromJSON(o))
.when(ExecutionFailedWithAssertionError.Code, _ => ExecutionFailedWithAssertionError.fromJSON(o))
.when(ImplementationPending.Code, _ => ImplementationPending.fromJSON(o))
.when(ExecutionSkipped.Code, _ => ExecutionSkipped.fromJSON(o))
.when(ExecutionIgnored.Code, _ => ExecutionIgnored.fromJSON(o))
.when(ExecutionSuccessful.Code, _ => ExecutionSuccessful.fromJSON(o))
.else(_ => { throw new Error(`Outcome could not be deserialised: ${ JSON.stringify(o) }`); }) as Outcome
const operatorsAndOperands = events.map(event => match, Operand | Operator>(event)
.when(OperandEntered, ({ value }: OperandEntered) => value)
.when(OperatorUsed, ({ value }: OperatorUsed) => value)
.else(_ => void 0),
).filter(event => !! event);
previous.then(outcome =>
match(outcome)
.when(ExpectationNotMet, o => o)
.else(_ => current.answeredBy(actor)(actual)),
),