Permalink
Browse files

feat(protractor): JetBrains tools should be able to report scenario d…

…uration

affects: serenity-js
  • Loading branch information...
jan-molak committed Apr 19, 2017
1 parent 2864f2f commit 3afb8fc61438278aed7e819281d9a1b8c7124859
@@ -17,6 +17,8 @@ import {
import { ProtractorReporter } from '../../../../src/serenity-protractor/reporting';
import { ProtractorReportExporter } from '../../../../src/serenity-protractor/reporting/protractor_reporter';
import { RehearsalReport } from '../../../../src/serenity/reporting';
import { Stage } from '../../../../src/serenity/stage/stage';
import { Journal, StageManager } from '../../../../src/serenity/stage/stage_manager';
describe('serenity-protractor', () => {
@@ -54,11 +56,15 @@ describe('serenity-protractor', () => {
examplesOfFailure = [ Result.FAILURE, Result.COMPROMISED, Result.ERROR ];
let protractor: Runner,
reporter: ProtractorReporter;
reporter: ProtractorReporter,
stage: Stage;
beforeEach(() => {
stage = new Stage(new StageManager(new Journal()));
protractor = sinon.createStubInstance(Runner) as any;
reporter = new ProtractorReporter(protractor);
reporter.assignTo(stage);
});
describe('complies with the Protractor Framework specification:', () => {
@@ -69,24 +75,26 @@ describe('serenity-protractor', () => {
describe('notifies Protractor as soon as a test', () => {
given(...examplesOfSuccess).it('passes', result => {
reporter.notifyOf(new SceneStarts(scene_1));
reporter.notifyOf(new SceneFinished(new Outcome(scene_1, result)));
reporter.notifyOf(new SceneStarts(scene_1, now));
reporter.notifyOf(new SceneFinished(new Outcome(scene_1, result), now + scene_1_duration));
expect(protractor.emit, `scenario finished with ${ Result[ result ] }`).
to.have.been.calledWith('testPass', {
category: feature,
name: scenario_1,
durationMillis: scene_1_duration,
});
});
given(...examplesOfFailure).it('fails', result => {
reporter.notifyOf(new SceneStarts(scene_1));
reporter.notifyOf(new SceneFinished(new Outcome(scene_1, result)));
reporter.notifyOf(new SceneStarts(scene_1, now));
reporter.notifyOf(new SceneFinished(new Outcome(scene_1, result), now + scene_1_duration));
expect(protractor.emit, `scenario finished with ${ Result[ result ] }`).
to.have.been.calledWith('testFail', {
category: feature,
name: scenario_1,
durationMillis: scene_1_duration,
});
});
});
@@ -21,8 +21,6 @@ export function run(runner: Runner, specs: string[]): PromiseLike<ProtractorRepo
export class SerenityProtractorFramework {
private config: SerenityFrameworkConfig;
private framework: TestFrameworkAdapter;
private reporter: ProtractorReporter;
private onComplete = noop;
@@ -37,7 +35,7 @@ export class SerenityProtractorFramework {
this.onComplete = protractorConfig.onComplete || noop;
serenity.configure(this.withFallback(protractorConfig).mergedWith({
this.serenity.configure(this.withFallback(protractorConfig).mergedWith({
crew: [
this.reporter,
new StandIns(),
@@ -3,6 +3,7 @@ import {
ActivityFinished,
ActivityStarts,
DomainEvent,
Identifiable,
Outcome,
RecordedScene,
Result,
@@ -24,10 +25,12 @@ import { ProtractorActivityReport, ProtractorReport, ProtractorSceneReport } fro
export class ProtractorReporter implements StageCrewMember {
private static Events_of_Interest = [ SceneStarts, SceneFinished, ActivityStarts, ActivityFinished ];
private stage: Stage;
private static Events_of_Interest = [ SceneStarts, SceneFinished ];
private stage: Stage = null;
private journal: Journal = new Journal();
private timing: {[key: string]: number} = {};
constructor(private runner: Runner) {
}
@@ -38,7 +41,7 @@ export class ProtractorReporter implements StageCrewMember {
notifyOf(event: DomainEvent<any>): void {
switch (event.constructor.name) { // tslint:disable-line:switch-default - ignore other events
case SceneStarts.name: return this.record(event);
case SceneStarts.name: return this.sceneStarts(event);
case ActivityStarts.name: return this.record(event);
case ActivityFinished.name: return this.record(event);
case SceneFinished.name: return this.sceneFinished(event);
@@ -49,21 +52,27 @@ export class ProtractorReporter implements StageCrewMember {
return RehearsalReport.from(this.journal.read()).exportedUsing(new ProtractorReportExporter());
}
private sceneStarts<T extends Identifiable>(event: DomainEvent<T>) {
this.record(event);
this.timing[event.value.id] = event.timestamp;
}
private sceneFinished(event: SceneFinished): void {
this.record(event);
this.notifyProtractor(event.value);
this.notifyProtractor(event.value, event.timestamp - this.timing[event.value.subject.id]);
}
private record = (event: DomainEvent<any>) => this.journal.record(event);
private notifyProtractor(outcome: Outcome<RecordedScene>) {
private notifyProtractor(outcome: Outcome<RecordedScene>, duration: number) {
const result = (outcome.result & Result.Failed)
? 'testFail'
: 'testPass';
this.runner.emit(result, {
name: outcome.subject.name,
category: outcome.subject.category,
durationMillis: duration,
});
}
}

0 comments on commit 3afb8fc

Please sign in to comment.