Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
feat(cucumber): cucumber adapter reports scenario descriptions
affects: @serenity-js/core, @serenity-js/cucumber, @integration/cucumber
- Loading branch information
Showing
25 changed files
with
353 additions
and
88 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Feature: Serenity/JS recognises all the important elements of a scenario | ||
|
||
In order to accurately report the scenario | ||
Serenity/JS should recognise all of its important parts | ||
|
||
Scenario: First scenario | ||
|
||
A scenario where all the steps pass | ||
Is reported as passing | ||
|
||
Given a step that passes |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Feature: Serenity/JS recognises a failing scenario | ||
|
||
Scenario: A failing scenario | ||
|
||
Given a step that fails | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,6 @@ | ||
Feature: Serenity/JS recognises a passing scenario | ||
|
||
In order to correctly report the outcome of a scenario | ||
Serenity/JS should recognise when a scenario passes | ||
|
||
Scenario: A passing scenario | ||
|
||
A scenario where all the steps pass | ||
|
||
Given a step that passes | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { expect, ifExitCodeIsOtherThan, logOutput } from '@integration/testing-tools'; | ||
import { SceneBackgroundDetected, SceneDescriptionDetected, SceneStarts } from '@serenity-js/core/lib/events'; | ||
import { Description, Name } from '@serenity-js/core/lib/model'; | ||
|
||
import 'mocha'; | ||
import { given } from 'mocha-testdata'; | ||
|
||
import { cucumber, Pick } from '../src'; | ||
|
||
describe('@serenity-js/cucumber', function() { | ||
|
||
this.timeout(5000); | ||
|
||
given([ | ||
'synchronous', | ||
'promise', | ||
'callback', | ||
]). | ||
it('recognises scenario descriptions', (stepInterface: string) => | ||
cucumber( | ||
'--require', 'features/support/configure_serenity.ts', | ||
'--require', `features/step_definitions/${ stepInterface }.steps.ts`, | ||
'--require', 'node_modules/@serenity-js/cucumber/register.js', | ||
'features/descriptions.feature', | ||
). | ||
then(ifExitCodeIsOtherThan(0, logOutput)). | ||
then(res => { | ||
expect(res.exitCode).to.equal(0); | ||
|
||
expect(res.events).to.have.lengthOf(7); | ||
|
||
Pick.from(res.events) | ||
.next(SceneStarts, event => expect(event.value.name).to.equal(new Name('First scenario'))) | ||
.next(SceneDescriptionDetected, event => { | ||
expect(event.description).to.equal(new Description( | ||
'A scenario where all the steps pass\nIs reported as passing', | ||
)); | ||
}) | ||
; | ||
})); | ||
}); |
48 changes: 48 additions & 0 deletions
48
integration/cucumber/spec/recognises_failing_scenario.spec.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { expect, ifExitCodeIsOtherThan, logOutput } from '@integration/testing-tools'; | ||
import { | ||
ActivityFinished, | ||
ActivityStarts, | ||
SceneFinished, | ||
SceneStarts, | ||
SceneTagged, | ||
TestRunnerDetected, | ||
} from '@serenity-js/core/lib/events'; | ||
import { ExecutionFailedWithError, FeatureTag, Name } from '@serenity-js/core/lib/model'; | ||
|
||
import 'mocha'; | ||
import { given } from 'mocha-testdata'; | ||
|
||
import { cucumber, Pick } from '../src'; | ||
|
||
describe('@serenity-js/cucumber', function() { | ||
|
||
this.timeout(5000); | ||
|
||
given([ | ||
'synchronous', | ||
'promise', | ||
'callback', | ||
]). | ||
it('recognises a failing scenario', (stepInterface: string) => | ||
cucumber( | ||
'--require', 'features/support/configure_serenity.ts', | ||
'--require', `features/step_definitions/${ stepInterface }.steps.ts`, | ||
'--require', 'node_modules/@serenity-js/cucumber/register.js', | ||
'features/failing_scenario.feature', | ||
). | ||
then(ifExitCodeIsOtherThan(1, logOutput)). | ||
then(res => { | ||
expect(res.exitCode).to.equal(1); | ||
|
||
expect(res.events).to.have.lengthOf(6); | ||
|
||
Pick.from(res.events) | ||
.next(SceneStarts, event => expect(event.value.name).to.equal(new Name('A failing scenario'))) | ||
.next(TestRunnerDetected, event => expect(event.value).to.equal(new Name('Cucumber'))) | ||
.next(SceneTagged, event => expect(event.tag).to.equal(new FeatureTag('Serenity/JS recognises a failing scenario'))) | ||
.next(ActivityStarts, event => expect(event.value.name).to.equal(new Name('Given a step that fails'))) | ||
.next(ActivityFinished, event => expect(event.outcome).to.be.instanceOf(ExecutionFailedWithError)) | ||
.next(SceneFinished, event => expect(event.outcome).to.be.instanceOf(ExecutionFailedWithError)) | ||
; | ||
})); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { DomainEvent } from '@serenity-js/core/lib/events'; | ||
|
||
export class Pick { | ||
static from = (events: DomainEvent[]) => new Pick(events); | ||
|
||
constructor(private events: DomainEvent[]) { | ||
} | ||
|
||
next<T extends DomainEvent>(type: { new(...args: any[]): T }, assertion: (event: T) => void) { | ||
|
||
const foundIndex = this.events.findIndex(event => event.constructor === type); | ||
|
||
if (foundIndex < 0) { | ||
throw new Error(`${ type.name } event not found within ${ this.events.map(e => e.constructor.name).join(', ') }`); | ||
} | ||
|
||
assertion(this.events[ foundIndex ] as T); | ||
|
||
this.events = this.events.slice(foundIndex + 1); | ||
|
||
return this; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './cucumber'; | ||
export * from './Pick'; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
55 changes: 55 additions & 0 deletions
55
...s/core/spec/stage/crew/serenity-bdd-reporter/SerenityBDDReporter/describing_scene.spec.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import 'mocha'; | ||
|
||
import * as sinon from 'sinon'; | ||
|
||
import { | ||
SceneBackgroundDetected, | ||
SceneDescriptionDetected, | ||
SceneFinished, | ||
SceneStarts, | ||
} from '../../../../../src/events'; | ||
import { Description, ExecutionSuccessful, Name } from '../../../../../src/model'; | ||
import { SerenityBDDReporter, StageManager } from '../../../../../src/stage'; | ||
import { SerenityBDDReport } from '../../../../../src/stage/crew/serenity-bdd-reporter/SerenityBDDJsonSchema'; | ||
import { expect } from '../../../../expect'; | ||
import { given } from '../../given'; | ||
import { defaultCardScenario } from '../../samples'; | ||
|
||
describe('SerenityBDDReporter', () => { | ||
|
||
let stageManager: sinon.SinonStubbedInstance<StageManager>, | ||
reporter: SerenityBDDReporter; | ||
|
||
beforeEach(() => { | ||
stageManager = sinon.createStubInstance(StageManager); | ||
|
||
reporter = new SerenityBDDReporter(); | ||
reporter.assignTo(stageManager as any); | ||
}); | ||
|
||
|
||
it('captures information about scenario background', () => { | ||
given(reporter).isNotifiedOfFollowingEvents( | ||
new SceneStarts(defaultCardScenario), | ||
new SceneBackgroundDetected(new Name('Background title'), new Description('Background description')), | ||
new SceneFinished(defaultCardScenario, new ExecutionSuccessful()), | ||
); | ||
|
||
const report: SerenityBDDReport = stageManager.notifyOf.firstCall.lastArg.artifact.contents; | ||
|
||
expect(report.backgroundTitle).to.equal('Background title'); | ||
expect(report.backgroundDescription).to.equal('Background description'); | ||
}); | ||
|
||
it('captures the description of the scenario', () => { | ||
given(reporter).isNotifiedOfFollowingEvents( | ||
new SceneStarts(defaultCardScenario), | ||
new SceneDescriptionDetected(new Description('Scenario description')), | ||
new SceneFinished(defaultCardScenario, new ExecutionSuccessful()), | ||
); | ||
|
||
const report: SerenityBDDReport = stageManager.notifyOf.firstCall.lastArg.artifact.contents; | ||
|
||
expect(report.description).to.equal('Scenario description'); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { ensure, isDefined, Serialised } from 'tiny-types'; | ||
|
||
import { Description, Name } from '../model'; | ||
import { DomainEvent } from './DomainEvent'; | ||
|
||
export class SceneBackgroundDetected extends DomainEvent { | ||
public static fromJSON(o: Serialised<SceneBackgroundDetected>) { | ||
return new SceneBackgroundDetected( | ||
Name.fromJSON(o.name as string), | ||
Description.fromJSON(o.description as string), | ||
); | ||
} | ||
|
||
constructor( | ||
public readonly name: Name, | ||
public readonly description: Description, | ||
) { | ||
super(); | ||
ensure('name', name, isDefined()); | ||
ensure('description', description, isDefined()); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { ensure, isDefined, Serialised } from 'tiny-types'; | ||
|
||
import { Description } from '../model'; | ||
import { DomainEvent } from './DomainEvent'; | ||
|
||
export class SceneDescriptionDetected extends DomainEvent { | ||
public static fromJSON(o: Serialised<SceneDescriptionDetected>) { | ||
return new SceneDescriptionDetected( | ||
Description.fromJSON(o.description as string), | ||
); | ||
} | ||
|
||
constructor( | ||
public readonly description: Description, | ||
) { | ||
super(); | ||
ensure('description', description, isDefined()); | ||
} | ||
} |
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
Oops, something went wrong.