Skip to content

Commit

Permalink
fix(reporting): execution context of a scenario is considered when ge…
Browse files Browse the repository at this point in the history
…nerating the scenario ID and na

affects: @serenity-js/core

This solves the problem where, if there are several scenario with identical names, only one of them
would be clickable in the reports.

ISSUES CLOSED: Closes #75
  • Loading branch information
jan-molak committed Sep 29, 2017
1 parent 244e903 commit cd71d71
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
10 changes: 7 additions & 3 deletions packages/core/spec/reporting/serenity_bdd_reporter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,9 @@ describe('When reporting on what happened during the rehearsal', () => {
);

return stageManager.waitForNextCue().then(_ =>
expect(producedReport('4ec27293d39642f72c52b21e57675a49.json')).to.deep.equal(expectedReportWith({
expect(producedReport('4062be5f843076e45e7704049f4b8cf1.json')).to.deep.equal(expectedReportWith({
id: 'checkout;paying-with-a-default-card;browser:chrome',
name: 'checkout;paying-with-a-default-card;browser:chrome',
duration: 2,
result: 'SUCCESS',
tags: [{
Expand All @@ -583,7 +585,9 @@ describe('When reporting on what happened during the rehearsal', () => {
);

return stageManager.waitForNextCue().then(_ =>
expect(producedReport('898a20ecc17b8d1dc3bf94b26147db3a.json')).to.deep.equal(expectedReportWith({
expect(producedReport('7f0e8e67887c2de55c2ca087e1ca14cb.json')).to.deep.equal(expectedReportWith({
id: 'checkout;paying-with-a-default-card;context:chrome',
name: 'checkout;paying-with-a-default-card;context:chrome',
duration: 2,
result: 'SUCCESS',
tags: [{
Expand Down Expand Up @@ -701,7 +705,7 @@ describe('When reporting on what happened during the rehearsal', () => {
function expectedReportWith(overrides: any) {
const report = {
id: 'checkout;paying-with-a-default-card',
name: 'Paying with a default card',
name: 'checkout;paying-with-a-default-card',
testSteps: [],
issues: [],
userStory: {
Expand Down
14 changes: 12 additions & 2 deletions packages/core/src/reporting/serenity_bdd_reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ export class SerenityBDDReportExporter implements ReportExporter<JSONObject> {
return Promise.all(node.children.map(child => child.exportedUsing(this)))
.then((children: ActivityReport[]) => this.errorExporter.tryToExport(node.outcome.error).then(error => {
return node.promisedTags().then(tags => ({
id: `${this.dashified(node.value.category)};${this.dashified(node.value.name)}`,
id: this.idOf(node, tags),
title: node.value.name,
name: node.value.name,
name: this.idOf(node, tags),
context: tags.filter(tag => tag.type === 'context').map(tag => tag.value).pop(),
description: '',
startTime: node.startedAt,
Expand Down Expand Up @@ -121,6 +121,16 @@ export class SerenityBDDReportExporter implements ReportExporter<JSONObject> {
})));
}

private idOf(node: ScenePeriod, tags: Tag[]) {
const combined = (ts: Tag[]) => (tags || []).map(tag => `${ tag.type }:${tag.value}`).join(';');

return [
this.dashified(node.value.category),
this.dashified(node.value.name),
combined(tags),
].join(';').replace(/;$/, '');
}

private dashified = (name: string) => name
.replace(/([a-z])([A-Z])/g, '$1-$2')
.replace(/[ \t\W]/g, '-')
Expand Down

0 comments on commit cd71d71

Please sign in to comment.