Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private failureOutcomeFrom(failure: Expectation): ProblemIndication {
const error = this.errorFrom(failure);
if (error instanceof AssertionError) {
// sadly, Jasmine error propagation mechanism is rather basic
// and unable to serialise the expected/actual properties of the AssertionError object
return new ExecutionFailedWithAssertionError(error);
}
if (!! failure.matcherName) { // the presence of a non-empty matcherName property indicates a Jasmine-specific assertion error
return new ExecutionFailedWithAssertionError(
new AssertionError(failure.message, failure.expected, failure.actual, error),
);
}
return new ExecutionFailedWithError(error);
}
case status === 'undefined':
return new ImplementationPending(new ImplementationPendingError('Step not implemented'));
case status === 'ambiguous':
if (! error) {
// Only the step result contains the "ambiguous step def error", the scenario itself doesn't
return new ExecutionFailedWithError(new AmbiguousStepDefinitionError('Multiple step definitions match'));
}
return new ExecutionFailedWithError(error);
case status === 'failed':
switch (true) {
case error instanceof AssertionError: return new ExecutionFailedWithAssertionError(error as AssertionError);
case error instanceof TestCompromisedError: return new ExecutionCompromised(error as TestCompromisedError);
default: return new ExecutionFailedWithError(error);
}
case status === 'pending':
return new ImplementationPending(new ImplementationPendingError('Step not implemented'));
case status === 'passed':
return new ExecutionSuccessful();
case status === 'skipped':
return new ExecutionSkipped();
}
// tslint:enable:switch-default
}
outcomeFrom(result: { duration: number, exception: string | Error, status: string }): Outcome {
const error = !! result.exception && this.errorFrom(result.exception);
// tslint:disable:switch-default
switch (result.status) {
case 'undefined':
return new ImplementationPending(new ImplementationPendingError('Step not implemented'));
case 'ambiguous':
case 'failed':
switch (true) {
case error instanceof AssertionError: return new ExecutionFailedWithAssertionError(error as AssertionError);
case error instanceof TestCompromisedError: return new ExecutionCompromised(error as TestCompromisedError);
default: return new ExecutionFailedWithError(error);
}
case 'pending':
return new ImplementationPending(new ImplementationPendingError('Step not implemented'));
case 'passed':
return new ExecutionSuccessful();
case 'skipped':
return new ExecutionSkipped();
}
// tslint:enable:switch-default
}
it('determines the result of the sequence based on the worst result of the contributing scenarios', () => {
given(reporter).isNotifiedOfFollowingEvents(
new SceneSequenceDetected(sequence),
new SceneTemplateDetected(template),
new SceneParametersDetected(
scenario1,
new ScenarioParameters(
new Name('Serenity/JS contributors'),
new Description(`Some of the people who have contributed their time and talent to the Serenity/JS project`),
{ Developer: 'jan-molak', Twitter_Handle: '@JanMolak' },
),
),
new SceneStarts(scenario1),
new SceneFinished(scenario1, new ExecutionFailedWithError(new Error('Something happened'))),
new SceneSequenceDetected(sequence),
new SceneTemplateDetected(template),
new SceneParametersDetected(
scenario2,
new ScenarioParameters(
new Name('Serenity/JS contributors'),
new Description(`Some of the people who have contributed their time and talent to the Serenity/JS project`),
{ Developer: 'wakaleo', Twitter_Handle: '@wakaleo' },
),
),
new SceneStarts(scenario2),
new SceneFinished(scenario2, new ExecutionSuccessful()),
new TestRunFinished(),
);
function sample(type: 'passing.spec.ts' | 'failing.spec.ts' | string) {
return type === 'passing.spec.ts'
? { path: 'passing.spec.ts', name: 'passing test', category: 'samples', description: 'samples passing test', outcome: new ExecutionSuccessful() }
: { path: 'failing.spec.ts', name: 'failing test', category: 'samples', description: 'samples failing test', outcome: new ExecutionFailedWithError(expectedError) };
}