Skip to content

Commit

Permalink
fix(playground): added a REST API and a JSON DB to store todos in
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-molak committed Jul 3, 2020
1 parent 119ffd3 commit e406099
Show file tree
Hide file tree
Showing 24 changed files with 1,247 additions and 310 deletions.
5 changes: 4 additions & 1 deletion angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
"styles": [
"src/webapp/styles.css"
],
"scripts": []
"scripts": [],
"allowedCommonJsDependencies": [
"tiny-types"
]
},
"configurations": {
"production": {
Expand Down
4 changes: 2 additions & 2 deletions e2e/protractor.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ exports.config = {
],

serenity: {
runner: 'jasmine',
runner: 'mocha',
crew: [
ArtifactArchiver.storingArtifactsAt('./target/site/serenity'),
ConsoleReporter.forDarkTerminals(),
Photographer.whoWill(TakePhotosOfInteractions), // or Photographer.whoWill(TakePhotosOfInteractions),
Photographer.whoWill(TakePhotosOfFailures), // or Photographer.whoWill(TakePhotosOfInteractions),
new SerenityBDDReporter(),
]
},
Expand Down
40 changes: 21 additions & 19 deletions e2e/src/playground.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ import {
containAtLeastOneItemThat,
Ensure,
equals,
isGreaterThan,
not,
property,
} from '@serenity-js/assertions';
import { actorCalled, actorInTheSpotlight, engage, Log, Note, TakeNote } from '@serenity-js/core';
import { LocalServer, StartLocalServer, StopLocalServer } from '@serenity-js/local-server';
import { Browser } from '@serenity-js/protractor';
import { logging } from 'protractor';
import { logging, protractor } from 'protractor';

import {
Actors,
Expand All @@ -22,31 +21,34 @@ import {
Start,
ToggleItem,
} from './screenplay';
import { ChangeApiUrl, GetRequest, LastResponse, Send } from '@serenity-js/rest';
import { GetRequest, LastResponse, Send } from '@serenity-js/rest';

describe('Playground Todo App', () => {
describe('Playground Todo App', function() {

beforeAll(() => engage(new Actors()));
this.timeout(30000);

beforeAll(() =>
actorCalled('Adam').attemptsTo(
StartLocalServer.onOneOfThePreferredPorts([3000]),
Log.the(LocalServer.url()),
Send.a(GetRequest.to(LocalServer.url())),
Ensure.that(LastResponse.status(), equals(200)),
TakeNote.of(LocalServer.url()),
));

afterAll(() =>
actorCalled('Adam').attemptsTo(
StopLocalServer.ifRunning(),
));
before(() => engage(new Actors(protractor.browser.baseUrl)));

describe('actor', () => {

before(() =>
actorCalled('Adam').attemptsTo(
StartLocalServer.onOneOfThePreferredPorts([3000]),
Log.the(LocalServer.url()),
Ensure.that(LocalServer.url(), equals('http://127.0.0.1:3000')),

Send.a(GetRequest.to('/api/health')),
Ensure.that(LastResponse.status(), equals(200)),
TakeNote.of(LocalServer.url()),
));

after(() =>
actorCalled('Adam').attemptsTo(
StopLocalServer.ifRunning(),
));

it('can record new items', () =>
actorCalled('Jasmine').attemptsTo(
ChangeApiUrl.to(Note.of(LocalServer.url())),
Start.withAnEmptyList(),
RecordItem.called('Walk a dog'),
Ensure.that(RecordedItems(), contain('Walk a dog')),
Expand Down
12 changes: 9 additions & 3 deletions e2e/src/screenplay/Actors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,32 @@ import { Actor, Cast, TakeNotes } from '@serenity-js/core';
import { ManageALocalServer } from '@serenity-js/local-server';
import { BrowseTheWeb } from '@serenity-js/protractor';

import path = require('path');
import { protractor } from 'protractor';

import { server } from '../../../src';
import { CallAnApi } from '@serenity-js/rest';

export class Actors implements Cast {
constructor(private readonly baseUrl: string) {
}

prepare(actor: Actor): Actor {
switch (actor.name) {
case 'Adam':
return actor.whoCan(
TakeNotes.usingASharedNotepad(),
BrowseTheWeb.using(protractor.browser), // todo: fixme, remove
ManageALocalServer.runningAHttpListener(server), // todo: `server` should be parametrised
CallAnApi.at('http://localhost'),
ManageALocalServer.runningAHttpListener(server(
path.join(__dirname, '../../../target/todos.json')
)),
CallAnApi.at(this.baseUrl),
);
case 'Jasmine':
default:
return actor.whoCan(
TakeNotes.usingASharedNotepad(),
CallAnApi.at(protractor.browser.baseUrl),
CallAnApi.at(this.baseUrl),
BrowseTheWeb.using(protractor.browser),
);
}
Expand Down
11 changes: 9 additions & 2 deletions e2e/src/screenplay/playground/Start.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { Ensure, equals } from '@serenity-js/assertions';
import { Task } from '@serenity-js/core';
import { Note, Task } from '@serenity-js/core';
import { Navigate, Website } from '@serenity-js/protractor';
import { RecordItem } from './RecordItem';
import { GetRequest, LastResponse, Send } from '@serenity-js/rest';
import { ChangeApiUrl, DeleteRequest, GetRequest, LastResponse, Send } from '@serenity-js/rest';
import { LocalServer } from '@serenity-js/local-server';

export class Start {
static withAnEmptyList = () =>
Task.where(`#actor starts with an empty list`,
CheckIfTheServerIsUp(),
ClearTheDatabase(),
Navigate.to('/'),
Ensure.that(Website.title(), equals('Serenity/JS Playground')),
);
Expand All @@ -24,3 +26,8 @@ const CheckIfTheServerIsUp = () =>
Send.a(GetRequest.to('/api/health/')),
Ensure.that(LastResponse.status(), equals(200)),
);

const ClearTheDatabase = () =>
Task.where(`#actor clears the database`,
Send.a(DeleteRequest.to('/api/todos')),
);
3 changes: 1 addition & 2 deletions e2e/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
"module": "commonjs",
"target": "es5",
"types": [
"jasmine",
"jasminewd2",
"mocha",
"node"
]
}
Expand Down
56 changes: 29 additions & 27 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,33 @@
// https://karma-runner.github.io/1.0/config/configuration-file.html

module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
],
client: {
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, './coverage/playground'),
reports: ['html', 'lcovonly', 'text-summary'],
fixWebpackSourcePaths: true
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
restartOnFileChange: true
});
config.set({
basePath: '',
frameworks: ['mocha', '@angular-devkit/build-angular'],
plugins: [
require('karma-mocha'),
require('karma-chrome-launcher'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
],
client: {
mocha: {
reporter: 'html',
ui: 'bdd',
}
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, './coverage/playground'),
reports: ['html', 'lcovonly', 'text-summary'],
fixWebpackSourcePaths: true
},
reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
restartOnFileChange: true
});
};
Loading

0 comments on commit e406099

Please sign in to comment.