Permalink
Browse files

fix(serenity-protractor): Custom configuration correctly overrides th…

…e defaults
  • Loading branch information...
jan-molak committed Feb 26, 2017
1 parent ebf5832 commit 031a8ddc5b94c79f43e6f92aa8c1f9858f968044
@@ -0,0 +1,81 @@
import { Config } from 'protractor';
import { Runner } from 'protractor/built/runner';
import { SinonStub } from 'sinon';
import { SerenityProtractorFramework } from '../../../../src/serenity-protractor/framework/serenity_protractor_framework';
import { StandIns } from '../../../../src/serenity-protractor/framework/stand_ins';
import { ProtractorNotifier } from '../../../../src/serenity-protractor/reporting/protractor_notifier';
import { ProtractorReporter } from '../../../../src/serenity-protractor/reporting/protractor_reporter';
import { Photographer } from '../../../../src/serenity-protractor/stage/photographer';
import { SerenityBDDReporter } from '../../../../src/serenity/reporting/serenity_bdd_reporter';
import { Serenity } from '../../../../src/serenity/serenity';
import { ConsoleReporter } from '../../../../src/serenity/stage/console_reporter';
import sinon = require('sinon');
import expect = require('../../../expect');
describe('serenity-protractor', () => {
describe('framework', () => {
describe('SerenityProtractorFramework', () => {
let serenity;
beforeEach(() => {
serenity = sinon.createStubInstance(Serenity);
});
it('can be instantiated with a default crew', () => {
const framework = new SerenityProtractorFramework(serenity, protractorRunner.withConfiguration({
serenity: {
dialect: 'mocha',
},
}));
expect(framework).to.be.instanceOf(SerenityProtractorFramework);
expect(serenity.assignCrewMembers).to.have.been.calledWith(
some(SerenityBDDReporter),
some(Photographer),
// core crew:
some(ProtractorReporter),
some(StandIns),
some(ProtractorNotifier),
);
});
it('can be instantiated with a custom crew, which overrides the default one (except the "protractor core" crew members)', () => {
const framework = new SerenityProtractorFramework(serenity, protractorRunner.withConfiguration({
serenity: {
dialect: 'mocha',
crew: [
new ConsoleReporter(console.log),
],
},
}));
expect(framework).to.be.instanceOf(SerenityProtractorFramework);
expect(serenity.assignCrewMembers).to.have.been.calledWith(
some(ConsoleReporter),
// core crew:
some(ProtractorReporter),
some(StandIns),
some(ProtractorNotifier),
);
});
});
const protractorRunner = {
withConfiguration: (config: Config) => {
const r: Runner = sinon.createStubInstance(Runner);
(r.getConfig as SinonStub).returns(config);
return r;
},
};
const some = sinon.match.instanceOf;
});
});
@@ -1,4 +1,4 @@
import { Runner } from 'protractor';
import { Config, Runner } from 'protractor';
import { serenity, Serenity } from '../..';
import { serenityBDDReporter } from '../../serenity/reporting';
import { ProtractorReport, ProtractorReporter } from '../reporting';
@@ -9,6 +9,8 @@ import { StandIns } from './stand_ins';
import { TestFramework } from './test_framework';
import { TestFrameworkDetector } from './test_framework_detector';
import _ = require('lodash');
// spec: https://github.com/angular/protractor/blob/master/lib/frameworks/README.md
const noop = () => undefined;
@@ -27,7 +29,8 @@ export class SerenityProtractorFramework {
private detect = new TestFrameworkDetector();
constructor(private serenity: Serenity, private runner: Runner) {
this.config = Object.assign({}, this.defaultConfig(), runner.getConfig());
this.config = this.defaultsWith(runner.getConfig());
this.reporter = new ProtractorReporter(runner);
this.framework = this.detect.frameworkFor(this.config);
@@ -55,7 +58,15 @@ export class SerenityProtractorFramework {
private waitForOtherProtractorPlugins = () => Promise.resolve(this.config.onComplete || noop);
private defaultConfig = (): SerenityFrameworkConfig => ({
private defaultsWith = (overrides: Config): SerenityFrameworkConfig => _.mergeWith(this.defaults(), overrides, this.mergeButOverrideLists);
private mergeButOverrideLists = (objValue, srcValue) => {
if (_.isArray(objValue)) {
return srcValue;
}
}
private defaults = () => ({
serenity: {
crew: [
/// [default-stage-crew-members]

0 comments on commit 031a8dd

Please sign in to comment.