Skip to content

Commit

Permalink
feat(core): support for Capability and Theme scenario tags
Browse files Browse the repository at this point in the history
affects: @serenity-js/core, @serenity-js/cucumber
  • Loading branch information
jan-molak committed Aug 7, 2018
1 parent a1fef6c commit 76c165a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ describe('SerenityBDDReporter', () => {
it('belongs to a capability', () => {
given(reporter).isNotifiedOfFollowingEvents(
new SceneTagged(defaultCardScenario, new CapabilityTag('E-Commerce')),
new SceneTagged(defaultCardScenario, new FeatureTag('Checkout')),
new SceneFinished(defaultCardScenario, new ExecutionSuccessful()),
);

Expand All @@ -135,12 +136,22 @@ describe('SerenityBDDReporter', () => {
expect(report.tags).to.deep.include.members([{
name: 'E-Commerce',
type: 'capability',
}, {
name: 'E-Commerce/Checkout',
type: 'feature',
}]);

expect(report.featureTag).to.deep.equal({
name: 'Checkout',
type: 'feature',
});
});

it('belongs to a theme', () => {
given(reporter).isNotifiedOfFollowingEvents(
new SceneTagged(defaultCardScenario, new ThemeTag('Digital')),
new SceneTagged(defaultCardScenario, new CapabilityTag('E-Commerce')),
new SceneTagged(defaultCardScenario, new FeatureTag('Checkout')),
new SceneFinished(defaultCardScenario, new ExecutionSuccessful()),
);

Expand All @@ -149,7 +160,18 @@ describe('SerenityBDDReporter', () => {
expect(report.tags).to.deep.include.members([{
name: 'Digital',
type: 'theme',
},{
name: 'Digital/E-Commerce',
type: 'capability',
}, {
name: 'Digital/E-Commerce/Checkout',
type: 'feature',
}]);

expect(report.featureTag).to.deep.equal({
name: 'Checkout',
type: 'feature',
});
});

describe('is executed in the context and', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { JSONObject, match } from 'tiny-types';
import {
ActivityDetails,
BrowserTag,
CapabilityTag,
ContextTag,
Description,
ExecutionCompromised,
Expand All @@ -18,6 +19,7 @@ import {
Outcome,
ScenarioDetails,
Tag,
ThemeTag,
Timestamp,
} from '../../../model';
import { ErrorParser } from './ErrorParser';
Expand Down Expand Up @@ -69,19 +71,28 @@ export class ScenarioReport {

sceneTaggedWith(tag: Tag) {
return this.withMutated(report => {
const nameOfRecorded = (typeOfTag: { Type: string }) => (report.tags.find(t => t.type === typeOfTag.Type) || { name: void 0 }).name;
const concatenated = (...names: string[]): string => names.filter(name => !! name).join('/');

const serialisedTag = tag.toJSON();

if (! report.tags) {
report.tags = [];
}

report.tags.push(tag.toJSON());

match(tag)
.when(ManualTag, _ => report.manual = true)
.when(FeatureTag, _ => report.featureTag = tag.toJSON())
.when(IssueTag, _ => (report.issues = report.issues || []).push(tag.name))
.when(BrowserTag, _ => (report.context = report.context || tag.name))
.when(ContextTag, _ => (report.context = tag.name))
match<Tag, void>(tag)
.when(ManualTag, _ => report.manual = true)
.when(CapabilityTag, _ => serialisedTag.name = concatenated(nameOfRecorded(ThemeTag), tag.name))
.when(FeatureTag, _ => {
serialisedTag.name = concatenated(nameOfRecorded(CapabilityTag), tag.name);
report.featureTag = tag.toJSON();
})
.when(IssueTag, _ => (report.issues = report.issues || []).push(tag.name))
.when(BrowserTag, _ => (report.context = report.context || tag.name))
.when(ContextTag, _ => (report.context = tag.name))
.else(_ => void 0);

report.tags.push(serialisedTag);
});
}

Expand Down
8 changes: 4 additions & 4 deletions packages/cucumber/src/listener/Notifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class Notifier {

private scenarioHierarchyTagsFor(scenario: cucumber.events.ScenarioPayload): Tag[] {

const humanReadable = (text: string) => text.replace(/_/g, ' ');
const humanReadable = (text: string) => text.replace(/[_-]+/g, ' ');

const
separator = '/',
Expand All @@ -106,9 +106,9 @@ export class Notifier {
const [ feature, capability, theme ] = hierarchy.reverse();

return notEmpty([
theme && new ThemeTag(humanReadable(theme)),
capability && new CapabilityTag(humanReadable(capability)),
feature && new FeatureTag(feature),
theme && new ThemeTag(humanReadable(theme)),
capability && new CapabilityTag(humanReadable(capability)),
feature && new FeatureTag(feature),
]);
}

Expand Down

0 comments on commit 76c165a

Please sign in to comment.