Skip to content
Permalink
Browse files
fix(core): WithStage moved to @serenity-js/core
WithStage can be used in both Cucumber and Jasmine tests so it makes sense to have it in core
  • Loading branch information
jan-molak committed May 21, 2019
1 parent 90630b4 commit 30184f801b840f6fa1c7308da84e8207735dc061
Showing with 80 additions and 81 deletions.
  1. +5 −5 examples/cucumber-domain-level-testing/features/step_definitions/domain-level.steps.ts
  2. +2 −4 examples/cucumber-domain-level-testing/features/support/configure_serenity.ts
  3. +5 −5 examples/cucumber-rest-api-level-testing/features/step_definitions/api-level.steps.ts
  4. +2 −4 examples/cucumber-rest-api-level-testing/features/support/configure_serenity.ts
  5. +1 −1 examples/protractor-cucumber/features/step_definitions/ui.steps.ts
  6. +2 −4 examples/protractor-cucumber/features/support/configure_serenity.ts
  7. +1 −2 integration/cucumber-1-runner/src/step_definitions/screenplay.steps.ts
  8. +1 −3 integration/cucumber-1-runner/src/support/configure_serenity.ts
  9. +1 −2 integration/cucumber-2-runner/src/step_definitions/screenplay.steps.ts
  10. +1 −3 integration/cucumber-2-runner/src/support/configure_serenity.ts
  11. +1 −2 integration/cucumber-3-runner/src/step_definitions/screenplay.steps.ts
  12. +1 −3 integration/cucumber-3-runner/src/support/configure_serenity.ts
  13. +1 −2 integration/cucumber-4-runner/src/step_definitions/screenplay.steps.ts
  14. +1 −3 integration/cucumber-4-runner/src/support/configure_serenity.ts
  15. +1 −2 integration/cucumber-5-runner/src/step_definitions/screenplay.steps.ts
  16. +1 −3 integration/cucumber-5-runner/src/support/configure_serenity.ts
  17. +52 −0 packages/core/src/stage/WithStage.ts
  18. +1 −0 packages/core/src/stage/index.ts
  19. +0 −32 packages/cucumber/src/WithStage.ts
  20. +0 −1 packages/cucumber/src/index.ts
@@ -1,30 +1,30 @@
import { Operand, Operator } from '@serenity-js-examples/calculator-app';
import { Ensure, equals } from '@serenity-js/assertions';
import { WithStage } from '@serenity-js/cucumber';
import { WithStage } from '@serenity-js/core';
import { Given, Then, When } from 'cucumber';
import { EnterOperand, RequestANewCalculation, ResultOfCalculation, UseOperator } from '../support/screenplay';

Given(/^(.*) has requested a new calculation/, function(this: WithStage, actorName: string) {
Given(/^(.*) has requested a new calculation/, function (this: WithStage, actorName: string) {
return this.stage.theActorCalled(actorName).attemptsTo(
RequestANewCalculation(),
);
});

When(/^(.*) enters (\d+)$/, function(this: WithStage, actorName: string, operandValue: string) {
When(/^(.*) enters (\d+)$/, function (this: WithStage, actorName: string, operandValue: string) {
const actor = ! isPronoun(actorName) ? this.stage.actor(actorName) : this.stage.theActorInTheSpotlight();

return actor.attemptsTo(
EnterOperand(new Operand(parseFloat(operandValue))),
);
});

When(/(?:he|she|they) uses? the (.) operator/, function(this: WithStage, operatorSymbol: string) {
When(/(?:he|she|they) uses? the (.) operator/, function (this: WithStage, operatorSymbol: string) {
return this.stage.theActorInTheSpotlight().attemptsTo(
UseOperator(Operator.fromString(operatorSymbol)),
);
});

Then(/(?:he|she|they) should get a result of (\d+)/, function(this: WithStage, expectedResult: string) {
Then(/(?:he|she|they) should get a result of (\d+)/, function (this: WithStage, expectedResult: string) {
return this.stage.theActorInTheSpotlight().attemptsTo(
Ensure.that(ResultOfCalculation(), equals(parseFloat(expectedResult))),
);
@@ -1,7 +1,5 @@
import { serenity } from '@serenity-js/core';
import { ArtifactArchiver, ConsoleReporter, serenity, SerenityBDDReporter, WithStage } from '@serenity-js/core';
import { FileSystem, Path } from '@serenity-js/core/lib/io';
import { ArtifactArchiver, ConsoleReporter, SerenityBDDReporter } from '@serenity-js/core/lib/stage';
import { WithStage } from '@serenity-js/cucumber';

import { setDefaultTimeout, setWorldConstructor } from 'cucumber';
import { Actors } from './screenplay';
@@ -15,6 +13,6 @@ serenity.setTheStage(

setDefaultTimeout(1000);

setWorldConstructor(function(this: WithStage, { parameters }) {
setWorldConstructor(function (this: WithStage, { parameters }) {
this.stage = serenity.callToStageFor(new Actors());
});
@@ -1,31 +1,31 @@
import { equals } from '@serenity-js/assertions';
import { WithStage } from '@serenity-js/cucumber';
import { WithStage } from '@serenity-js/core';
import { LocalServer, StartLocalServer, StopLocalServer } from '@serenity-js/local-server';
import { ChangeApiUrl, LastResponse } from '@serenity-js/rest';
import { After, Before, Then, When } from 'cucumber';
import { RequestCalculationOf, VerifyResultAt } from '../support/screenplay';

Before(function() {
Before(function () {
return this.stage.theActorCalled('Apisitt').attemptsTo( // todo: change to Maggie
StartLocalServer.onRandomPort(),
ChangeApiUrl.to(LocalServer.url()),
// TakeNote.of(LocalServer.url()) // Question or Question<Promise>; Pass between actors
);
});

When(/^(.*) asks for the following calculation: (.*)$/, function(this: WithStage, actorName: string, expression: string) {
When(/^(.*) asks for the following calculation: (.*)$/, function (this: WithStage, actorName: string, expression: string) {
return this.stage.actor(actorName).attemptsTo(
RequestCalculationOf(expression),
);
});

Then(/(?:he|she|they) should get a result of ([\d-.]+)/, function(this: WithStage, expectedResult: string) {
Then(/(?:he|she|they) should get a result of ([\d-.]+)/, function (this: WithStage, expectedResult: string) {
return this.stage.theActorInTheSpotlight().attemptsTo(
VerifyResultAt(LastResponse.header('location'), equals({ result: Number(expectedResult) })),
);
});

After(function() {
After(function () {
return this.stage.theActorCalled('Apisitt').attemptsTo(
StopLocalServer.ifRunning(),
);
@@ -1,7 +1,5 @@
import { serenity } from '@serenity-js/core';
import { ArtifactArchiver, ConsoleReporter, serenity, SerenityBDDReporter, WithStage } from '@serenity-js/core';
import { FileSystem, Path } from '@serenity-js/core/lib/io';
import { ArtifactArchiver, ConsoleReporter, SerenityBDDReporter } from '@serenity-js/core/lib/stage';
import { WithStage } from '@serenity-js/cucumber';

import { setDefaultTimeout, setWorldConstructor } from 'cucumber';
import { Actors } from './screenplay';
@@ -14,6 +12,6 @@ serenity.setTheStage(

setDefaultTimeout(1000);

setWorldConstructor(function(this: WithStage, { parameters }) {
setWorldConstructor(function (this: WithStage, { parameters }) {
this.stage = serenity.callToStageFor(new Actors());
});
@@ -1,5 +1,5 @@
import { Ensure, equals } from '@serenity-js/assertions';
import { WithStage } from '@serenity-js/cucumber';
import { WithStage } from '@serenity-js/core';
import { LocalServer, StartLocalServer, StopLocalServer } from '@serenity-js/local-server';
import { Navigate, UseAngular, Website } from '@serenity-js/protractor';
import { After, Then, When } from 'cucumber';
@@ -1,7 +1,5 @@
import { serenity } from '@serenity-js/core';
import { ArtifactArchiver, ConsoleReporter, serenity, SerenityBDDReporter, WithStage } from '@serenity-js/core';
import { FileSystem, Path } from '@serenity-js/core/lib/io';
import { ArtifactArchiver, ConsoleReporter, DebugReporter, SerenityBDDReporter } from '@serenity-js/core/lib/stage';
import { WithStage } from '@serenity-js/cucumber';

import { setDefaultTimeout, setWorldConstructor } from 'cucumber';
import { Actors } from './screenplay';
@@ -16,6 +14,6 @@ serenity.setTheStage(

setDefaultTimeout(1000);

setWorldConstructor(function(this: WithStage, { parameters }) {
setWorldConstructor(function (this: WithStage, { parameters }) {
this.stage = serenity.callToStageFor(new Actors());
});
@@ -1,5 +1,4 @@
import { Interaction } from '@serenity-js/core';
import { WithStage } from '@serenity-js/cucumber';
import { Interaction, WithStage } from '@serenity-js/core';

const
MakeAnArrow = () => Interaction.where(`#actor makes an arrow`, actor => void 0),
@@ -1,7 +1,5 @@
import { ChildProcessReporter } from '@integration/testing-tools';
import { serenity } from '@serenity-js/core';
import { DebugReporter } from '@serenity-js/core/lib/stage';
import { WithStage } from '@serenity-js/cucumber';
import { DebugReporter, serenity, WithStage } from '@serenity-js/core';
import { Actors } from './Actors';

export = function () {
@@ -1,5 +1,4 @@
import { Interaction } from '@serenity-js/core';
import { WithStage } from '@serenity-js/cucumber';
import { Interaction, WithStage } from '@serenity-js/core';
import { defineSupportCode } from 'cucumber';

const
@@ -1,7 +1,5 @@
import { ChildProcessReporter } from '@integration/testing-tools';
import { serenity } from '@serenity-js/core';
import { DebugReporter } from '@serenity-js/core/lib/stage';
import { WithStage } from '@serenity-js/cucumber';
import { DebugReporter, serenity, WithStage } from '@serenity-js/core';
import { defineSupportCode } from 'cucumber';
import { Actors } from './Actors';

@@ -1,5 +1,4 @@
import { Interaction } from '@serenity-js/core';
import { WithStage } from '@serenity-js/cucumber';
import { Interaction, WithStage } from '@serenity-js/core';
import { defineSupportCode } from 'cucumber';

const
@@ -1,7 +1,5 @@
import { ChildProcessReporter } from '@integration/testing-tools';
import { serenity } from '@serenity-js/core';
import { DebugReporter } from '@serenity-js/core/lib/stage';
import { WithStage } from '@serenity-js/cucumber';
import { DebugReporter, serenity, WithStage } from '@serenity-js/core';
import { defineSupportCode } from 'cucumber';
import { Actors } from './Actors';

@@ -1,5 +1,4 @@
import { Interaction } from '@serenity-js/core';
import { WithStage } from '@serenity-js/cucumber';
import { Interaction, WithStage } from '@serenity-js/core';
import { After, Before, Then, When } from 'cucumber';

const
@@ -1,7 +1,5 @@
import { ChildProcessReporter } from '@integration/testing-tools';
import { serenity } from '@serenity-js/core';
import { DebugReporter } from '@serenity-js/core/lib/stage';
import { WithStage } from '@serenity-js/cucumber';
import { DebugReporter, serenity, WithStage } from '@serenity-js/core';
import { setDefaultTimeout, setWorldConstructor } from 'cucumber';
import { Actors } from './Actors';

@@ -1,5 +1,4 @@
import { Interaction } from '@serenity-js/core';
import { WithStage } from '@serenity-js/cucumber';
import { Interaction, WithStage } from '@serenity-js/core';
import { After, Before, Then, When } from 'cucumber';

const
@@ -1,7 +1,5 @@
import { ChildProcessReporter } from '@integration/testing-tools';
import { serenity } from '@serenity-js/core';
import { DebugReporter } from '@serenity-js/core/lib/stage';
import { WithStage } from '@serenity-js/cucumber';
import { DebugReporter, serenity, WithStage } from '@serenity-js/core';
import { setDefaultTimeout, setWorldConstructor } from 'cucumber';
import { Actors } from './Actors';

@@ -0,0 +1,52 @@
import { Stage } from './Stage';

/**
* @desc Makes the {@link Stage} object setup in your test runner configuration visible
* to test steps or test scenarios.
*
* When using Cucumber, the {@link Stage} is typically set up using the Cucumber World Constructor.
* When using Jasmine, the {@link Stage} is typically set up in the `beforeEach` step.
*
* @see https://github.com/cucumber/cucumber-js/blob/v5.0.1/docs/support_files/api_reference.md
* @see https://github.com/cucumber/cucumber-js/blob/v5.0.1/docs/support_files/step_definitions.md
* @see https://www.typescriptlang.org/docs/handbook/functions.html#this-parameters
*
* @example <caption>Usage with Cucumber.js</caption>
* // features/support/configure_serenity.ts
* import { WithStage } from '@serenity-js/core';
* import { setWorldConstructor } from 'cucumber';
*
* setWorldConstructor(function (this: WithStage, { parameters }) {
* this.stage = serenity.callToStageFor(new SomeImplementationOfTheDressingRoomInterface());
* });
*
* // features/step_definitions/some.steps.ts
* import { WithStage } from '@serenity-js/cucumber';
*
* Given(/(.*?) is a registered customer/, function (this: WithStage, actorName: string) {
* return this.stage.actor(actorName).attemptsTo(
*
* );
* });
*
* @example <caption>Usage with Jasmine</caption>
* // spec/some.spec.ts
* import { serenity, WithStage } from '@serenity-js/core';
*
* describe('Using the Stage', () => {
* beforeEach(function (this: WithStage) {
* this.stage = serenity.callToStageFor(new SomeImplementationOfTheDressingRoomInterface());
* });
*
* it('makes it easy to access the Actors', function(this: WithStage) {
* return this.stage.theActorCalled('Barry').attemptsTo(
* // tasks
* );
* })
* });
*
* @interface
*/
export abstract class WithStage {
stage: Stage;
}
@@ -4,3 +4,4 @@ export * from './crew';
export * from './StageCrewMember';
export * from './StageManager';
export * from './Stage';
export * from './WithStage';

This file was deleted.

This file was deleted.

0 comments on commit 30184f8

Please sign in to comment.