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(serenity-bdd): support for reporting business rules
Business rules are a new feature introduced in Cucumber 7
- Loading branch information
Showing
7 changed files
with
174 additions
and
27 deletions.
There are no files selected for viewing
117 changes: 117 additions & 0 deletions
117
...pec/stage/crew/serenity-bdd-reporter/SerenityBDDReporter/reporting_business_rules.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,117 @@ | ||
import { expect } from '@integration/testing-tools'; | ||
import { StageManager } from '@serenity-js/core'; | ||
import { | ||
BusinessRuleDetected, | ||
SceneFinished, | ||
SceneParametersDetected, | ||
SceneSequenceDetected, | ||
SceneStarts, | ||
SceneTemplateDetected, | ||
TestRunFinishes, | ||
} from '@serenity-js/core/lib/events'; | ||
import { FileSystemLocation, Path } from '@serenity-js/core/lib/io'; | ||
import { BusinessRule, Category, CorrelationId, Description, ExecutionSuccessful, Name, ScenarioDetails, ScenarioParameters } from '@serenity-js/core/lib/model'; | ||
import 'mocha'; | ||
import * as sinon from 'sinon'; | ||
|
||
import { SerenityBDDReporter } from '../../../../../src'; | ||
import { SerenityBDDReport } from '../../../../../src/stage/crew/serenity-bdd-reporter/SerenityBDDJsonSchema'; | ||
import { given } from '../../given'; | ||
import { create } from '../create'; | ||
|
||
describe('SerenityBDDReporter', () => { | ||
|
||
let stageManager: sinon.SinonStubbedInstance<StageManager>, | ||
reporter: SerenityBDDReporter; | ||
|
||
beforeEach(() => { | ||
const env = create(); | ||
|
||
stageManager = env.stageManager; | ||
reporter = env.reporter; | ||
}); | ||
|
||
// see examples/cucumber/features/reporting_results/reports_scenario_outlines.feature for more context | ||
const | ||
sceneIds = [ new CorrelationId('scene-0'), new CorrelationId('scene-1') ], | ||
category = new Category('Reporting results'), | ||
name = new Name('Reports scenario outlines'), | ||
path = new Path(`reporting_results/reports_scenario_outlines.feature`), | ||
template = new Description(` | ||
When <Developer> makes a contribution of: | ||
| value | | ||
| time | | ||
| talent | | ||
| great code | | ||
Then they help bring serenity to fellow devs | ||
`), | ||
sequence = new ScenarioDetails(name, category, new FileSystemLocation( | ||
path, | ||
7, | ||
)), | ||
scenarios = [ | ||
new ScenarioDetails(name, category, new FileSystemLocation(path, 25)), | ||
new ScenarioDetails(name, category, new FileSystemLocation(path, 26)), | ||
] | ||
; | ||
|
||
/** | ||
* @test {SerenityBDDReporter} | ||
* @test {SceneStarts} | ||
* @test {SceneBackgroundDetected} | ||
* @test {SceneFinished} | ||
* @test {ExecutionSuccessful} | ||
* @test {TestRunFinishes} | ||
*/ | ||
it('captures information about the business rule for single-scene scenarios', () => { | ||
given(reporter).isNotifiedOfFollowingEvents( | ||
new SceneStarts(sceneIds[0], scenarios[0]), | ||
new BusinessRuleDetected(sceneIds[0], scenarios[0], new BusinessRule(new Name('my rule name'), new Description('my rule description'))), | ||
new SceneFinished(sceneIds[0], scenarios[0], new ExecutionSuccessful()), | ||
new TestRunFinishes(), | ||
); | ||
|
||
const report: SerenityBDDReport = stageManager.notifyOf.firstCall.lastArg.artifact.map(_ => _); | ||
|
||
expect(report.rule).to.equal('my rule name'); | ||
}); | ||
|
||
it('captures information about the business rule for scene sequences', () => { | ||
given(reporter).isNotifiedOfFollowingEvents( | ||
new SceneSequenceDetected(sceneIds[0], sequence), | ||
new SceneTemplateDetected(sceneIds[0], template), | ||
new SceneParametersDetected( | ||
sceneIds[0], | ||
scenarios[0], | ||
new ScenarioParameters( | ||
new Name('Serenity/JS contributors'), | ||
new Description(`Some of the people who have contributed their time and talent to the Serenity/JS project`), | ||
{ Developer: 'jan-molak', Twitter_Handle: '@JanMolak' }, | ||
), | ||
), | ||
new SceneStarts(sceneIds[0], scenarios[0]), | ||
new BusinessRuleDetected(sceneIds[0], scenarios[0], new BusinessRule(new Name('my rule name'), new Description('my rule description'))), | ||
new SceneFinished(sceneIds[0], scenarios[0], new ExecutionSuccessful()), | ||
|
||
new SceneSequenceDetected(sceneIds[1], sequence), | ||
new SceneTemplateDetected(sceneIds[1], template), | ||
new SceneParametersDetected( | ||
sceneIds[1], | ||
scenarios[1], | ||
new ScenarioParameters( | ||
new Name('Serenity/JS contributors'), | ||
new Description(`Some of the people who have contributed their time and talent to the Serenity/JS project`), | ||
{ Developer: 'wakaleo', Twitter_Handle: '@wakaleo' }, | ||
), | ||
), | ||
new SceneStarts(sceneIds[1], scenarios[1]), | ||
new BusinessRuleDetected(sceneIds[1], scenarios[1], new BusinessRule(new Name('my rule name'), new Description('my rule description'))), | ||
new SceneFinished(sceneIds[1], scenarios[1], new ExecutionSuccessful()), | ||
new TestRunFinishes(), | ||
); | ||
|
||
const report: SerenityBDDReport = stageManager.notifyOf.firstCall.lastArg.artifact.map(_ => _); | ||
|
||
expect(report.rule).to.equal('my rule name'); | ||
}); | ||
}); |
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
17 changes: 17 additions & 0 deletions
17
...ity-bdd/src/stage/crew/serenity-bdd-reporter/processors/transformations/businessRuleOf.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,17 @@ | ||
import { BusinessRule, Description, Name } from '@serenity-js/core/lib/model'; | ||
import { SerenityBDDReportContext } from '../SerenityBDDReportContext'; | ||
|
||
/** | ||
* @package | ||
*/ | ||
export function businessRuleOf<Context extends SerenityBDDReportContext>(rule: BusinessRule) { | ||
return (context: Context): Context => { | ||
|
||
context.report.rule = rule.name.value; | ||
|
||
// todo: Serenity BDD v. 2.3.10 doesn't support business rule descriptions yet | ||
// context.report.?? = rule.description.value; | ||
|
||
return context; | ||
} | ||
} |
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