Skip to content

Commit

Permalink
docs(examples): updated examples to use the new Serenity/JS 3.0 APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-molak committed Jun 20, 2022
1 parent f78721b commit 396b950
Show file tree
Hide file tree
Showing 22 changed files with 28 additions and 83 deletions.
2 changes: 1 addition & 1 deletion examples/calculator-app/spec/Calculator.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'mocha';
import { describe, it } from 'mocha';
import { given } from 'mocha-testdata';

import { Calculator } from '../src';
Expand Down
11 changes: 2 additions & 9 deletions examples/calculator-app/spec/domain/model/Operator.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import 'mocha';
import { describe } from 'mocha';
import { given } from 'mocha-testdata';

import {
AdditionOperator,
DivisionOperator,
LeftParenthesisOperator,
Operator,
RightParenthesisOperator,
SubtractionOperator,
} from '../../../src';
import { AdditionOperator, DivisionOperator, LeftParenthesisOperator, Operator, RightParenthesisOperator, SubtractionOperator } from '../../../src';

import { expect } from '../../expect';

Expand Down
12 changes: 2 additions & 10 deletions examples/calculator-app/spec/rest-api/model/Expression.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import 'mocha';
import { describe, it } from 'mocha';
import { given } from 'mocha-testdata';

import {
AdditionOperator,
DivisionOperator,
LeftParenthesisOperator,
MultiplicationOperator,
Operand,
RightParenthesisOperator,
SubtractionOperator,
} from '../../../src/domain/model';
import { AdditionOperator, DivisionOperator, LeftParenthesisOperator, MultiplicationOperator, Operand, RightParenthesisOperator, SubtractionOperator } from '../../../src/domain/model';
import { Expression } from '../../../src/rest-api/model';

import { expect } from '../../expect';
Expand Down
12 changes: 1 addition & 11 deletions examples/calculator-app/src/Calculator.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
import { match } from 'tiny-types';
import {
CalculatorCommand,
CalculatorEvent,
CalculatorQuery,
EnterOperandCommand,
GetCalculationResult,
OperandEntered,
OperatorUsed,
ResultCalculator,
UseOperatorCommand,
} from './domain';
import { CalculatorCommand, CalculatorEvent, CalculatorQuery, EnterOperandCommand, GetCalculationResult, OperandEntered, OperatorUsed, ResultCalculator, UseOperatorCommand } from './domain';

export class Calculator {
constructor(private readonly events: Array<CalculatorEvent<any>> = []) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ensure, isDefined, TinyType } from 'tiny-types';
import { CalculatorEvent } from '../events';
import { CalculationId } from '../model';

export abstract class CalculatorQuery extends TinyType {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
import { match } from 'tiny-types';

import { CalculatorEvent, OperandEntered, OperatorUsed } from '../events';
import {
AdditionOperator,
ArithmeticOperator,
DivisionOperator,
LeftParenthesisOperator,
MultiplicationOperator,
Operand,
Operator,
RightParenthesisOperator,
SubtractionOperator,
} from '../model';
import { AdditionOperator, ArithmeticOperator, DivisionOperator, LeftParenthesisOperator, MultiplicationOperator, Operand, Operator, RightParenthesisOperator, SubtractionOperator } from '../model';

import { QueryHandler } from './QueryHandler';

Expand Down
10 changes: 1 addition & 9 deletions examples/calculator-app/src/rest-api/controllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,7 @@ import * as bodyParser from 'body-parser';
import * as express from 'express';
import { match } from 'tiny-types';

import {
CalculationId,
Calculator,
EnterOperandCommand,
GetCalculationResult,
Operand,
Operator,
UseOperatorCommand,
} from '../';
import { CalculationId, Calculator, EnterOperandCommand, GetCalculationResult, Operand, Operator, UseOperatorCommand } from '../';
import { Expression } from './model';

export function controllers(api: express.Application, calculator: Calculator) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import {
CalculationId,
Calculator,
CalculatorCommand,
CalculatorQuery,
GetCalculationResult,
} from '@serenity-js-examples/calculator-app';
import { CalculationId, Calculator, CalculatorCommand, CalculatorQuery, GetCalculationResult } from '@serenity-js-examples/calculator-app';
import { Ability, Actor } from '@serenity-js/core';

export class InteractDirectly implements Ability {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Actor, actorCalled, actorInTheSpotlight } from '@serenity-js/core';
import { defineParameterType, DataTable, Given, Then } from '@cucumber/cucumber';
import { DataTable, defineParameterType, Given, Then } from '@cucumber/cucumber';

defineParameterType({
regexp: /[A-Z][a-z]+/,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AssertionError, TestCompromisedError } from '@serenity-js/core';
import { Given, DataTable, Then, When } from '@cucumber/cucumber';
import { DataTable, Given, Then, When } from '@cucumber/cucumber';
import { strictEqual } from 'assert';

Given(/^.*step.*passes$/, function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'mocha';
import { after, before, describe, it } from 'mocha';

import { equals } from '@serenity-js/assertions';
import { actorCalled, engage, Note, TakeNote } from '@serenity-js/core';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { After, Before, Then, When } from '@cucumber/cucumber';
import { Ensure, equals } from '@serenity-js/assertions';
import { actorCalled, actorInTheSpotlight, engage, Transform } from '@serenity-js/core';
import { actorCalled, actorInTheSpotlight, engage, q } from '@serenity-js/core';
import { LocalServer, StartLocalServer, StopLocalServer } from '@serenity-js/local-server';
import { UseAngular } from '@serenity-js/protractor';
import { Navigate, Website } from '@serenity-js/web';
import { Navigate, Page } from '@serenity-js/web';
import { Actors } from '../support/screenplay';

Before(() => {
Expand All @@ -21,12 +21,12 @@ When(/^(.*) navigates to the test website number (.*?)$/, (actorName: string, id
actorCalled(actorName).attemptsTo(
StartLocalServer.onRandomPort(),
UseAngular.disableSynchronisation(),
Navigate.to(Transform.the(LocalServer.url(), url => `${ url }/${ id }`)),
Navigate.to(q`${ LocalServer.url() }/${ id }`),
));

Then(/(?:he|she|they) should see the title of "(.*)"/, (expectedTitle: string) =>
actorInTheSpotlight().attemptsTo(
Ensure.that(Website.title(), equals(expectedTitle)),
Ensure.that(Page.current().title(), equals(expectedTitle)),
));

After(() =>
Expand Down
4 changes: 2 additions & 2 deletions examples/protractor-jasmine/spec/interactions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Ensure, equals } from '@serenity-js/assertions';
import { actorCalled, actorInTheSpotlight, engage } from '@serenity-js/core';
import { LocalServer, StartLocalServer, StopLocalServer } from '@serenity-js/local-server';
import { UseAngular } from '@serenity-js/protractor';
import { Navigate, Website } from '@serenity-js/web';
import { Navigate, Page } from '@serenity-js/web';
import { Actors } from './support/Actors';

describe('Interaction flow', () => {
Expand All @@ -14,7 +14,7 @@ describe('Interaction flow', () => {
StartLocalServer.onRandomPort(),
UseAngular.disableSynchronisation(),
Navigate.to(LocalServer.url()),
Ensure.that(Website.title(), equals('Test Website')),
Ensure.that(Page.current().title(), equals('Test Website')),
);
});

Expand Down
6 changes: 3 additions & 3 deletions examples/protractor-mocha/spec/interactions.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'mocha';
import { afterEach, beforeEach, describe, it } from 'mocha';

import { Ensure, equals } from '@serenity-js/assertions';
import { actorCalled, actorInTheSpotlight, Check, engage, Interaction } from '@serenity-js/core';
import { LocalServer, StartLocalServer, StopLocalServer } from '@serenity-js/local-server';
import { UseAngular } from '@serenity-js/protractor';
import { Navigate, Website } from '@serenity-js/web';
import { Navigate, Page } from '@serenity-js/web';
import { Actors } from './support/Actors';

/**
Expand All @@ -28,7 +28,7 @@ describe('Interaction flow', () => {
UseAngular.disableSynchronisation(),
Navigate.to(LocalServer.url()),
Check.whether(counter++, equals(3))
.andIfSo(Ensure.that(Website.title(), equals('Test Website')))
.andIfSo(Ensure.that(Page.current().title(), equals('Test Website')))
.otherwise(FailTheTest()),
);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Actor, actorCalled, actorInTheSpotlight } from '@serenity-js/core';
import { defineParameterType, DataTable, Given, Then } from '@cucumber/cucumber';
import { DataTable, defineParameterType, Given, Then } from '@cucumber/cucumber';

defineParameterType({
regexp: /[A-Z][a-z]+/,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AssertionError, TestCompromisedError } from '@serenity-js/core';
import { Given, DataTable, Then, When } from '@cucumber/cucumber';
import { DataTable, Given, Then, When } from '@cucumber/cucumber';

Given(/^.*step.*passes$/, function () {
return Promise.resolve();
Expand Down
4 changes: 1 addition & 3 deletions examples/webdriverio-cucumber/wdio.conf.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { ConsoleReporter } from '@serenity-js/console-reporter';
import { ArtifactArchiver, StreamReporter } from '@serenity-js/core';
import { ArtifactArchiver } from '@serenity-js/core';
import { SerenityBDDReporter } from '@serenity-js/serenity-bdd';
import { WebdriverIOConfig } from '@serenity-js/webdriverio';
import { createWriteStream } from 'fs';
import { resolve } from 'path';
import Inspector from './src/Inspector';

export const config: WebdriverIOConfig = {

Expand Down
3 changes: 0 additions & 3 deletions examples/webdriverio-jasmine/wdio.conf.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { ConsoleReporter } from '@serenity-js/console-reporter';
import { StreamReporter } from '@serenity-js/core';
import { WebdriverIOConfig } from '@serenity-js/webdriverio';
import { resolve } from 'path';
import { createWriteStream } from 'fs';
import Inspector from './src/Inspector';

export const config: WebdriverIOConfig = {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, it } from 'mocha';
import { contain, Ensure, equals } from '@serenity-js/assertions';
import { actorCalled, actorInTheSpotlight, Question } from '@serenity-js/core';
import { actorCalled, actorInTheSpotlight } from '@serenity-js/core';
import { ClearLocalStorage, RecordedItems, RecordItem, RemoveItem, RenameItem, Start, ToggleItem } from '../src';

describe('Managing a Todo List', () => {
Expand Down
2 changes: 1 addition & 1 deletion examples/webdriverio-mocha-todomvc/src/todo-list/Start.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { endsWith, Ensure } from '@serenity-js/assertions';
import { Answerable, Task } from '@serenity-js/core';
import { Navigate, Page, /* Website */ } from '@serenity-js/web';
import { Navigate, Page } from '@serenity-js/web';
import { RecordItem } from './RecordItem';

export class Start {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// import { by, Target } from '@serenity-js/web'; // Serenity/JS 2.x
import { By, PageElement } from '@serenity-js/web'; // Serenity/JS 3.x
import { By, PageElement } from '@serenity-js/web'; // Serenity/JS 3.x

export class TodoListItem {
static label =
Expand Down
2 changes: 1 addition & 1 deletion examples/webdriverio-mocha-todomvc/wdio.conf.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ConsoleReporter } from '@serenity-js/console-reporter';
import { ArtifactArchiver } from '@serenity-js/core';
import { SerenityBDDReporter } from '@serenity-js/serenity-bdd';
import { Photographer, TakePhotosOfFailures, TakePhotosOfInteractions } from '@serenity-js/web';
import { Photographer, TakePhotosOfFailures } from '@serenity-js/web';
import { WebdriverIOConfig } from '@serenity-js/webdriverio';
import { resolve } from 'path';
import { Actors } from './src';
Expand Down

0 comments on commit 396b950

Please sign in to comment.