Skip to content
Permalink
Browse files
fix(core): Ensure the reportData entries in the report are compatib…
…le with Serenity BDD CLI
  • Loading branch information
jan-molak committed Mar 5, 2019
1 parent fdf7c1c commit 95afc5a0fbdc2e300039364a14c64b380252bb2e
@@ -191,16 +191,12 @@ describe('SerenityBDDReporter', () => {

expect(report.testSteps).to.have.lengthOf(2);
expect(report.testSteps[0].number).to.equal(1);
expect(report.testSteps[0].reportData).to.deep.equal({
title: 'pick a card message',
contents: '{\n \"card\": \"default\"\n}',
});
expect(report.testSteps[0].reportData.title).to.equal('pick a card message');
expect(report.testSteps[0].reportData.contents).to.equal('{\n "card": "default"\n}');

expect(report.testSteps[1].number).to.equal(2);
expect(report.testSteps[1].reportData).to.deep.equal({
title: 'make a payment message',
contents: '{\n \"amount\": \"£42\"\n}',
});
expect(report.testSteps[1].reportData.title).to.equal('make a payment message');
expect(report.testSteps[1].reportData.contents).to.deep.equal('{\n \"amount\": \"£42\"\n}');
});
});

@@ -49,6 +49,9 @@ export interface TestStep extends JSONObject {

// https://github.com/serenity-bdd/serenity-core/blob/master/serenity-model/src/main/java/net/thucydides/core/model/ReportData.java
export interface ReportData extends JSONObject {
id: string;
isEvidence: boolean;
path: string;
title: string;
contents: string;
}
@@ -1,3 +1,4 @@
import cuid = require('cuid');
import { JSONObject, match } from 'tiny-types';
import { equal } from 'tiny-types/lib/objects'; // tslint:disable-line:no-submodule-imports
import { inspect } from 'util';
@@ -228,7 +229,13 @@ export class SceneReport {

arbitraryDataCaptured(name: Name, contents: string) {
return this.withMutated(report => {
this.activities.mostRecentlyAccessedItem().reportData = { title: name.value, contents };
this.activities.mostRecentlyAccessedItem().reportData = {
id: `report-data-${ cuid() }`,
isEvidence: false,
path: '',
title: name.value,
contents,
};
});
}

@@ -9,7 +9,15 @@ import {
SceneTagged,
TestRunnerDetected,
} from '../../../../events';
import { Artifact, ArtifactType, HTTPRequestResponse, JSONData, Photo, ScenarioDetails } from '../../../../model';
import {
Artifact,
ArtifactType,
HTTPRequestResponse,
JSONData,
Photo,
ScenarioDetails,
TextData,
} from '../../../../model';
import { SceneReport } from '../reports';

/**
@@ -31,7 +39,8 @@ export abstract class SceneReportingStrategy {
.when(TestRunnerDetected, (e: TestRunnerDetected) => report.executedBy(e.value))
.when(ArtifactGenerated, (e: ArtifactGenerated) => match<Artifact, SceneReport>(e.artifact)
.when(HTTPRequestResponse, _ => report.httpRequestCaptured(e.artifact.map(data => data)))
.when(JSONData, _ => report.arbitraryDataCaptured(e.name, e.artifact.map(data => JSON.stringify(data, null, 4))))
.when(TextData, _ => report.arbitraryDataCaptured(e.name, e.artifact.map(artifactContents => artifactContents.data)))
.when(JSONData, _ => report.arbitraryDataCaptured(e.name, e.artifact.map(artifactContents => JSON.stringify(artifactContents, null, 4))))
.else(_ => report))
.when(ArtifactArchived, (e: ArtifactArchived) => match<ArtifactType, SceneReport>(e.type)
.when(Photo, _ => report.photoTaken(e.path))

0 comments on commit 95afc5a

Please sign in to comment.