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));
}
}
eventBroadcaster.on('test-step-finished', ({ index, result, testCase }) => {
ensure('test-step-finished :: index', index, isDefined());
ensure('test-step-finished :: result', result, isDefined());
ensure('test-step-finished :: testCase', testCase, isDefined());
const
map = cache.get(new Path(testCase.sourceLocation.uri)),
scenario = map.get(Scenario).onLine(testCase.sourceLocation.line),
step = scenario.steps[index];
if (step instanceof Step) { // ignore hooks
notifier.stepFinished(step, this.outcomeFrom(result));
}
});
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();
function isInstanceOf(type: Function & (new (...args: any[]) => T)): Predicate { // tslint:disable-line:ban-types
return Predicate.to(`be an instance of ${ type.name }`, (value: T) =>
value instanceof type);
}
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()) ]);
}
}
function looksLikeBase64Encoded(): Predicate {
const regex = /^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)$/;
return Predicate.to(`be an ISO-8601-compliant date`, (value: string) => regex.test(value));
}
describe('equals', () => {
const Astrid = stage().theActorCalled('Astrid');
class Name extends TinyTypeOf() {}
given([
{ description: 'string', expected: 'hello', actual: 'hello' },
{ description: 'number', expected: 42, actual: 42 },
{ description: 'boolean', expected: false, actual: false },
{ description: 'object', expected: { k: 'v' }, actual: { k: 'v' } },
{ description: 'TinyType', expected: new Name('Jan'), actual: new Name('Jan') },
{ description: 'array', expected: [ null, 2, '3' ], actual: [ null, 2, '3' ] },
{ description: 'Date', expected: new Date('Jan 27, 2019'), actual: new Date('Jan 27, 2019') },
]).
it('compares the value of "actual" and "expected" and allows for the actor flow to continue when they match', ({ actual, expected }) => {
return expect(Astrid.attemptsTo(
Ensure.that(actual, equals(expected)),
)).to.be.fulfilled;
});
constructor(public readonly value: string) {
super();
ensure(this.constructor.name, value, isDefined());
}
constructor(
public readonly value: ActivityDetails,
timestamp?: Timestamp,
) {
super(timestamp);
ensure('value', value, isDefined());
}
}