Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
feat(core): support for ES6-style task definitions
affects: @serenity-js/cucumber-2, serenity-js - Instead of using the @step annotation it's enough for a task to define a toString() method, which will be used to determine its description #22 - RecordedTask and RecordedActivity are now replaced by RecordedActivity, which can also define the location where it was invoked to support #18 - A more functional-style DSL provided to make prototyping faster, for example, to create a task it's enough to write: task_where('{0} proceeds to checkout') #21 ISSUES CLOSED: #21, #22
- Loading branch information
Showing
21 changed files
with
396 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -42,7 +42,7 @@ | ||
}, | ||
"peerDependencies": { | ||
"cucumber": "2.0.0-rc.9", | ||
"serenity-js": ">= 1.2.5" | ||
"serenity-js": ">= 1.4" | ||
}, | ||
"devDependencies": { | ||
"@types/cucumber": "2.0.0", | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,111 @@ | ||
import sinon = require('sinon'); | ||
import expect = require('../../expect'); | ||
import { Actor, PerformsTasks, Task, task_where } from '../../../src/serenity/screenplay'; | ||
|
||
import { step } from '../../../src/serenity/recording'; | ||
import { Journal, StageManager } from '../../../src/serenity/stage/stage_manager'; | ||
|
||
describe ('When recording', () => { | ||
|
||
let alice: Actor, | ||
stage_manager: StageManager; | ||
|
||
beforeEach(() => { | ||
stage_manager = new StageManager(new Journal()); | ||
alice = new Actor('Alice', stage_manager); | ||
}); | ||
|
||
describe ('Actor', () => { | ||
describe('performing activities that follow', () => { | ||
|
||
describe('Serenity BDD-style implementation', () => { | ||
|
||
class Follow implements Task { | ||
|
||
static the = (personOfInterest: string) => new Follow(personOfInterest); | ||
|
||
@step('{0} follows the #personOfInterest') | ||
performAs(actor: PerformsTasks): PromiseLike<void> { | ||
return Promise.resolve(); | ||
} | ||
|
||
constructor(private personOfInterest: string) { | ||
} | ||
} | ||
|
||
it('notifies the Stage Manager when the activity starts and finishes', () => alice.attemptsTo(Follow.the('white rabbit')).then(() => { | ||
const entries = stage_manager.readTheJournal(); | ||
|
||
expect(entries).to.have.lengthOf(2); | ||
expect(entries[ 0 ].value).to.deep.equal(entries[ 1 ].value.subject); | ||
})); | ||
|
||
it('notifies the Stage Manager of Activity\'s invocation location', () => alice.attemptsTo(Follow.the('white rabbit')).then(() => { | ||
const entries = stage_manager.readTheJournal(); | ||
|
||
expect(entries[ 0 ].value).to.be.recorded.as('Alice follows the white rabbit').calledAt({ | ||
line: 43, | ||
column: 97, | ||
path: '/recording.spec.ts', | ||
}); | ||
})); | ||
}); | ||
|
||
describe('ES6-style implementation', () => { | ||
|
||
class Follow implements Task { | ||
|
||
static the = (personOfInterest: string) => new Follow(personOfInterest); | ||
|
||
performAs(actor: PerformsTasks): PromiseLike<void> { | ||
return Promise.resolve(); | ||
} | ||
|
||
toString = () => `{0} follows the ${ this.personOfInterest }`; | ||
|
||
constructor(private personOfInterest: string) { | ||
} | ||
} | ||
|
||
it('notifies the Stage Manager when the activity starts and finishes', () => alice.attemptsTo(Follow.the('white rabbit')).then(() => { | ||
const entries = stage_manager.readTheJournal(); | ||
|
||
expect(entries).to.have.lengthOf(2); | ||
expect(entries[ 0 ].value).to.deep.equal(entries[ 1 ].value.subject); | ||
})); | ||
|
||
it('notifies the Stage Manager of Activity\'s invocation location', () => alice.attemptsTo(Follow.the('white rabbit')).then(() => { | ||
const entries = stage_manager.readTheJournal(); | ||
|
||
expect(entries[ 0 ].value).to.be.recorded.as('Alice follows the white rabbit').calledAt({ | ||
line: 77, | ||
column: 97, | ||
path: '/recording.spec.ts', | ||
}); | ||
})); | ||
}); | ||
|
||
describe('minimalist implementation', () => { | ||
|
||
const follow_the = (person_of_interest: string) => task_where(`{0} follows the ${person_of_interest}`); | ||
|
||
it('notifies the Stage Manager when the activity starts and finishes', () => alice.attemptsTo(follow_the('white rabbit')).then(() => { | ||
const entries = stage_manager.readTheJournal(); | ||
|
||
expect(entries).to.have.lengthOf(2); | ||
expect(entries[ 0 ].value).to.deep.equal(entries[ 1 ].value.subject); | ||
})); | ||
|
||
it('notifies the Stage Manager of Activity\'s invocation location', () => alice.attemptsTo(follow_the('white rabbit')).then(() => { | ||
const entries = stage_manager.readTheJournal(); | ||
|
||
expect(entries[ 0 ].value).to.be.recorded.as('Alice follows the white rabbit').calledAt({ | ||
line: 99, | ||
column: 97, | ||
path: '/recording.spec.ts', | ||
}); | ||
})); | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.