Skip to content
Permalink
Browse files
fix(cucumber): AssertionErrors are reported as such
  • Loading branch information
jan-molak committed Feb 5, 2019
1 parent 74ed99a commit 7bd837da1ee2cf11e2d9658a0458bc3d39bcb658
Showing with 8 additions and 4 deletions.
  1. +1 −1 packages/core/src/io/ErrorSerialiser.ts
  2. +2 −1 packages/core/src/model/outcomes.ts
  3. +5 −2 packages/cucumber/src/adapters/CucumberEventProtocolAdapter.ts
@@ -27,7 +27,7 @@ export class ErrorSerialiser {
}, { name: error.name || error.constructor.name }) as SerialisedError;
}

static deserialise(serialisedError: SerialisedError): Error {
static deserialise<E extends Error>(serialisedError: SerialisedError): E {
// todo: de-serialise the cause map well
const constructor = ErrorSerialiser.recognisedErrors.find(errorType => errorType.name === serialisedError.name) || Error;
const deserialised = Object.create(constructor.prototype);
@@ -1,4 +1,5 @@
import { JSONObject, match, TinyType } from 'tiny-types';
import { AssertionError } from '../errors';
import { ErrorSerialiser, SerialisedError } from '../io';

export interface SerialisedOutcome extends JSONObject {
@@ -80,7 +81,7 @@ export class ExecutionFailedWithAssertionError extends ProblemIndication {

static fromJSON = (o: SerialisedOutcome) => new ExecutionFailedWithAssertionError(ErrorSerialiser.deserialise(o.error));

constructor(error: Error) {
constructor(error: AssertionError) {
super(error, ExecutionFailedWithAssertionError.Code);
}
}
@@ -1,6 +1,7 @@
import { UnknownError } from '@serenity-js/core/lib/errors';
import { AssertionError, UnknownError } from '@serenity-js/core/lib/errors';
import { ErrorSerialiser, Path } from '@serenity-js/core/lib/io';
import {
ExecutionFailedWithAssertionError,
ExecutionFailedWithError,
ExecutionSkipped,
ExecutionSuccessful,
@@ -102,7 +103,9 @@ export function cucumberEventProtocolAdapter({ notifier, mapper, cache }: Depend

case 'ambiguous':
case 'failed':
return new ExecutionFailedWithError(error);
return error instanceof AssertionError
? new ExecutionFailedWithAssertionError(error)
: new ExecutionFailedWithError(error);

case 'pending':
return new ImplementationPending();

0 comments on commit 7bd837d

Please sign in to comment.