Skip to content
Permalink
Browse files
feat(core): support for Capability and Theme scenario tags
affects: @serenity-js/core, @serenity-js/cucumber
  • Loading branch information
jan-molak committed Aug 7, 2018
1 parent a1fef6c commit 76c165a728d67b2ee61ab511e94bc80cab304b34
@@ -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()),
);

@@ -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()),
);

@@ -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', () => {
@@ -3,6 +3,7 @@ import { JSONObject, match } from 'tiny-types';
import {
ActivityDetails,
BrowserTag,
CapabilityTag,
ContextTag,
Description,
ExecutionCompromised,
@@ -18,6 +19,7 @@ import {
Outcome,
ScenarioDetails,
Tag,
ThemeTag,
Timestamp,
} from '../../../model';
import { ErrorParser } from './ErrorParser';
@@ -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);
});
}

@@ -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 = '/',
@@ -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),
]);
}

0 comments on commit 76c165a

Please sign in to comment.