Skip to content
Permalink
Browse files
fix(core): AssertionErrors are correctly reported
  • Loading branch information
jan-molak committed Feb 5, 2019
1 parent be0ca07 commit fc2a88168526a4b53b23eb4a16e734b7420e52b8
Showing with 209 additions and 37 deletions.
  1. +1 −1 examples/cucumber-rest-api-level-testing/features/api/calculations.feature
  2. +3 −3 examples/cucumber-rest-api-level-testing/features/support/screenplay/tasks/VerifyResultAt.ts
  3. +6 −1 integration/cucumber-1-runner/src/step_definitions/callback.steps.ts
  4. +6 −1 integration/cucumber-1-runner/src/step_definitions/promise.steps.ts
  5. +6 −1 integration/cucumber-1-runner/src/step_definitions/synchronous.steps.ts
  6. +6 −1 integration/cucumber-2-runner/src/step_definitions/callback.steps.ts
  7. +6 −1 integration/cucumber-2-runner/src/step_definitions/promise.steps.ts
  8. +6 −1 integration/cucumber-2-runner/src/step_definitions/synchronous.steps.ts
  9. +6 −1 integration/cucumber-3-runner/src/step_definitions/callback.steps.ts
  10. +6 −1 integration/cucumber-3-runner/src/step_definitions/promise.steps.ts
  11. +6 −1 integration/cucumber-3-runner/src/step_definitions/synchronous.steps.ts
  12. +6 −1 integration/cucumber-4-runner/src/step_definitions/callback.steps.ts
  13. +6 −1 integration/cucumber-4-runner/src/step_definitions/promise.steps.ts
  14. +6 −1 integration/cucumber-4-runner/src/step_definitions/synchronous.steps.ts
  15. +6 −1 integration/cucumber-5-runner/src/step_definitions/callback.steps.ts
  16. +6 −1 integration/cucumber-5-runner/src/step_definitions/promise.steps.ts
  17. +6 −1 integration/cucumber-5-runner/src/step_definitions/synchronous.steps.ts
  18. +6 −0 integration/cucumber/features/assertion_failure_scenario.feature
  19. +1 −1 integration/cucumber/features/failing_scenario.feature
  20. +1 −1 integration/cucumber/features/pending_scenarios.feature
  21. +4 −4 integration/cucumber/features/scenario_outlines.feature
  22. +58 −0 integration/cucumber/spec/assertion_failure_scenario.spec.ts
  23. +1 −1 integration/cucumber/spec/failing_scenario.spec.ts
  24. +2 −2 integration/cucumber/spec/pending_scenarios.spec.ts
  25. +1 −1 integration/cucumber/spec/scenario_outlines.spec.ts
  26. +31 −0 packages/core/spec/io/ErrorSerialiser.spec.ts
  27. +1 −1 packages/core/spec/model/outcomes.spec.ts
  28. +1 −1 packages/core/spec/stage/crew/serenity-bdd-reporter/SerenityBDDReporter.spec.ts
  29. +1 −1 packages/core/src/io/ErrorSerialiser.ts
  30. +2 −1 packages/core/src/stage/crew/serenity-bdd-reporter/reports/ErrorParser.ts
  31. +5 −2 packages/cucumber/src/adapters/cucumber-0.ts
  32. +0 −2 packages/cucumber/src/register.ts
@@ -9,7 +9,7 @@ Feature: Calculations API

| expression | expected_result | description |
| 2 | 2 | Literal |
| 2 + 2 | 4 | Addition |
| 2 + 2 | 5 | Addition |
| 2 - 3 | -1 | Subtraction |
| 2 * 5 | 10 | Multiplication |
| 5 / 2 | 2.5 | Division |
@@ -1,10 +1,10 @@
import { Assertion, Ensure, equals } from '@serenity-js/assertions';
import { Ensure, equals, Expectation } from '@serenity-js/assertions';
import { KnowableUnknown, Task } from '@serenity-js/core';
import { GetRequest, LastResponse, Send } from '@serenity-js/rest';

export const VerifyResultAt = (url: KnowableUnknown<string>, assertion: Assertion<KnowableUnknown<any>>) =>
export const VerifyResultAt = (url: KnowableUnknown<string>, expectation: Expectation<KnowableUnknown<any>>) =>
Task.where(`#actor verifies result at ${ url }`,
Send.a(GetRequest.to(url)),
Ensure.that(LastResponse.status(), equals(200)),
Ensure.that(LastResponse.body(), assertion),
Ensure.that(LastResponse.body(), expectation),
);
@@ -1,3 +1,4 @@
import { AssertionError } from '@serenity-js/core';
import { TableDefinition } from 'cucumber';

type Callback = (error?: Error, pending?: string) => void;
@@ -7,10 +8,14 @@ export = function() {
done();
});

this.Given(/^.*step (?:.*) fails$/, function(done: Callback) {
this.Given(/^.*step (?:.*) fails with generic error$/, function(done: Callback) {
done(new Error(`Something's wrong`));
});

this.Given(/^.*step (?:.*) fails with assertion error$/, function(done: Callback) {
done(new AssertionError(`Expected false to equal true`, false, true));
});

this.Given(/^.*step (?:.*) marked as pending/, function(done: Callback) {
done(void 0, 'pending');
});
@@ -1,14 +1,19 @@
import { AssertionError } from '@serenity-js/core';
import { TableDefinition } from 'cucumber';

export = function() {
this.Given(/^.*step (?:.*) passes$/, function() {
return Promise.resolve();
});

this.Given(/^.*step (?:.*) fails$/, function() {
this.Given(/^.*step (?:.*) fails with generic error$/, function() {
return Promise.reject(new Error(`Something's wrong`));
});

this.Given(/^.*step (?:.*) fails with assertion error$/, function() {
return Promise.reject(new AssertionError(`Expected false to equal true`, false, true));
});

this.Given(/^.*step (?:.*) marked as pending/, function() {
return Promise.resolve('pending');
});
@@ -1,14 +1,19 @@
import { AssertionError } from '@serenity-js/core';
import { TableDefinition } from 'cucumber';

export = function() {
this.Given(/^.*step (?:.*) passes$/, function() {
return void 0;
});

this.Given(/^.*step (?:.*) fails$/, function() {
this.Given(/^.*step (?:.*) fails with generic error$/, function() {
throw new Error(`Something's wrong`);
});

this.Given(/^.*step (?:.*) fails with assertion error$/, function() {
throw new AssertionError(`Expected false to equal true`, false, true);
});

this.Given(/^.*step (?:.*) marked as pending/, function() {
return 'pending';
});
@@ -1,3 +1,4 @@
import { AssertionError } from '@serenity-js/core';
import { defineSupportCode, TableDefinition } from 'cucumber';

type Callback = (error?: Error, pending?: string) => void;
@@ -8,10 +9,14 @@ defineSupportCode(({ Given }) => {
done();
});

Given(/^.*step (?:.*) fails$/, function(done: Callback) {
Given(/^.*step (?:.*) fails with generic error$/, function(done: Callback) {
done(new Error(`Something's wrong`));
});

Given(/^.*step (?:.*) fails with assertion error$/, function(done: Callback) {
done(new AssertionError(`Expected false to equal true`, false, true));
});

Given(/^.*step (?:.*) marked as pending/, function(done: Callback) {
done(void 0, 'pending');
});
@@ -1,14 +1,19 @@
import { AssertionError } from '@serenity-js/core';
import { defineSupportCode, TableDefinition } from 'cucumber';

defineSupportCode(({ Given }) => {
Given(/^.*step (?:.*) passes$/, function() {
return Promise.resolve();
});

Given(/^.*step (?:.*) fails$/, function() {
Given(/^.*step (?:.*) fails with generic error$/, function() {
return Promise.reject(new Error(`Something's wrong`));
});

Given(/^.*step (?:.*) fails with assertion error$/, function() {
return Promise.reject(new AssertionError(`Expected false to equal true`, false, true));
});

Given(/^.*step (?:.*) marked as pending/, function() {
return Promise.resolve('pending');
});
@@ -1,14 +1,19 @@
import { AssertionError } from '@serenity-js/core';
import { defineSupportCode, TableDefinition } from 'cucumber';

defineSupportCode(({ Given }) => {
Given(/^.*step (?:.*) passes$/, function() {
return void 0;
});

Given(/^.*step (?:.*) fails$/, function() {
Given(/^.*step (?:.*) fails with generic error$/, function() {
throw new Error(`Something's wrong`);
});

Given(/^.*step (?:.*) fails with assertion error$/, function() {
throw new AssertionError(`Expected false to equal true`, false, true);
});

Given(/^.*step (?:.*) marked as pending/, function() {
return 'pending';
});
@@ -1,3 +1,4 @@
import { AssertionError } from '@serenity-js/core';
import { defineSupportCode, TableDefinition } from 'cucumber';

type Callback = (error?: Error, pending?: string) => void;
@@ -8,10 +9,14 @@ defineSupportCode(({ Given }) => {
done();
});

Given(/^.*step (?:.*) fails$/, function(done: Callback) {
Given(/^.*step (?:.*) fails with generic error$/, function(done: Callback) {
done(new Error(`Something's wrong`));
});

Given(/^.*step (?:.*) fails with assertion error$/, function(done: Callback) {
done(new AssertionError(`Expected false to equal true`, false, true));
});

Given(/^.*step (?:.*) marked as pending/, function(done: Callback) {
done(void 0, 'pending');
});
@@ -1,14 +1,19 @@
import { AssertionError } from '@serenity-js/core';
import { defineSupportCode, TableDefinition } from 'cucumber';

defineSupportCode(({ Given }) => {
Given(/^.*step (?:.*) passes$/, function() {
return Promise.resolve();
});

Given(/^.*step (?:.*) fails$/, function() {
Given(/^.*step (?:.*) fails with generic error$/, function() {
return Promise.reject(new Error(`Something's wrong`));
});

Given(/^.*step (?:.*) fails with assertion error$/, function() {
return Promise.reject(new AssertionError(`Expected false to equal true`, false, true));
});

Given(/^.*step (?:.*) marked as pending/, function() {
return Promise.resolve('pending');
});
@@ -1,14 +1,19 @@
import { AssertionError } from '@serenity-js/core';
import { defineSupportCode, TableDefinition } from 'cucumber';

defineSupportCode(({ Given }) => {
Given(/^.*step (?:.*) passes$/, function() {
return void 0;
});

Given(/^.*step (?:.*) fails$/, function() {
Given(/^.*step (?:.*) fails with generic error$/, function() {
throw new Error(`Something's wrong`);
});

Given(/^.*step (?:.*) fails with assertion error$/, function() {
throw new AssertionError(`Expected false to equal true`, false, true);
});

Given(/^.*step (?:.*) marked as pending/, function() {
return 'pending';
});
@@ -1,3 +1,4 @@
import { AssertionError } from '@serenity-js/core';
import { Given, TableDefinition } from 'cucumber';

type Callback = (error?: Error, pending?: string) => void;
@@ -6,10 +7,14 @@ Given(/^.*step (?:.*) passes$/, function(done: Callback) {
done();
});

Given(/^.*step (?:.*) fails$/, function(done: Callback) {
Given(/^.*step (?:.*) fails with generic error$/, function(done: Callback) {
done(new Error(`Something's wrong`));
});

Given(/^.*step (?:.*) fails with assertion error$/, function(done: Callback) {
done(new AssertionError(`Expected false to equal true`, false, true));
});

Given(/^.*step (?:.*) marked as pending/, function(done: Callback) {
done(void 0, 'pending');
});
@@ -1,13 +1,18 @@
import { AssertionError } from '@serenity-js/core';
import { Given, TableDefinition } from 'cucumber';

Given(/^.*step (?:.*) passes$/, function() {
return Promise.resolve();
});

Given(/^.*step (?:.*) fails$/, function() {
Given(/^.*step (?:.*) fails with generic error$/, function() {
return Promise.reject(new Error(`Something's wrong`));
});

Given(/^.*step (?:.*) fails with assertion error$/, function() {
return Promise.reject(new AssertionError(`Expected false to equal true`, false, true));
});

Given(/^.*step (?:.*) marked as pending/, function() {
return Promise.resolve('pending');
});
@@ -1,13 +1,18 @@
import { AssertionError } from '@serenity-js/core';
import { Given, TableDefinition } from 'cucumber';

Given(/^.*step (?:.*) passes$/, function() {
return void 0;
});

Given(/^.*step (?:.*) fails$/, function() {
Given(/^.*step (?:.*) fails with generic error$/, function() {
throw new Error(`Something's wrong`);
});

Given(/^.*step (?:.*) fails with assertion error$/, function() {
throw new AssertionError(`Expected false to equal true`, false, true);
});

Given(/^.*step (?:.*) marked as pending/, function() {
return 'pending';
});
@@ -1,3 +1,4 @@
import { AssertionError } from '@serenity-js/core';
import { Given, TableDefinition } from 'cucumber';

type Callback = (error?: Error, pending?: string) => void;
@@ -6,10 +7,14 @@ Given(/^.*step (?:.*) passes$/, function(done: Callback) {
done();
});

Given(/^.*step (?:.*) fails$/, function(done: Callback) {
Given(/^.*step (?:.*) fails with generic error$/, function(done: Callback) {
done(new Error(`Something's wrong`));
});

Given(/^.*step (?:.*) fails with assertion error$/, function(done: Callback) {
done(new AssertionError(`Expected false to equal true`, false, true));
});

Given(/^.*step (?:.*) marked as pending/, function(done: Callback) {
done(void 0, 'pending');
});
@@ -1,13 +1,18 @@
import { AssertionError } from '@serenity-js/core';
import { Given, TableDefinition } from 'cucumber';

Given(/^.*step (?:.*) passes$/, function() {
return Promise.resolve();
});

Given(/^.*step (?:.*) fails$/, function() {
Given(/^.*step (?:.*) fails with generic error$/, function() {
return Promise.reject(new Error(`Something's wrong`));
});

Given(/^.*step (?:.*) fails with assertion error$/, function() {
return Promise.reject(new AssertionError(`Expected false to equal true`, false, true));
});

Given(/^.*step (?:.*) marked as pending/, function() {
return Promise.resolve('pending');
});
@@ -1,13 +1,18 @@
import { AssertionError } from '@serenity-js/core';
import { Given, TableDefinition } from 'cucumber';

Given(/^.*step (?:.*) passes$/, function() {
return void 0;
});

Given(/^.*step (?:.*) fails$/, function() {
Given(/^.*step (?:.*) fails with generic error$/, function() {
throw new Error(`Something's wrong`);
});

Given(/^.*step (?:.*) fails with assertion error$/, function() {
throw new AssertionError(`Expected false to equal true`, false, true);
});

Given(/^.*step (?:.*) marked as pending/, function() {
return 'pending';
});
@@ -0,0 +1,6 @@
Feature: Serenity/JS recognises a scenario failing due to an assertion error

Scenario: An assertion failure scenario

Given a step that fails with assertion error

@@ -2,5 +2,5 @@ Feature: Serenity/JS recognises a failing scenario

Scenario: A failing scenario

Given a step that fails
Given a step that fails with generic error

@@ -17,4 +17,4 @@ Feature: Serenity/JS recognises pending scenarios

Given step number one that passes
And step number two that is marked as pending
And step number three that fails
And step number three that fails with generic error
@@ -6,8 +6,8 @@ Feature: Serenity/JS recognises scenario outlines

Examples: Example results

Description of the examples
Description of the examples

| result |
| passes |
| fails |
| result |
| passes |
| fails with generic error |

0 comments on commit fc2a881

Please sign in to comment.