Skip to content
Permalink
Browse files
fix(protractor): Corrected the test runner detector
So that explicit serenity.runner config takes precedence over guessing
  • Loading branch information
jan-molak committed Nov 27, 2019
1 parent 30e4def commit e5e638bfe3468523a3a7ff34f7dabd458aedda3b
Showing 2 changed files with 48 additions and 6 deletions.
@@ -24,6 +24,18 @@ describe('TestRunnerDetector', () => {
expect(runner).to.be.instanceOf(CucumberTestRunner);
});

it('uses the CucumberTestRunner even when the Jasmine config is present as well', () => {
const runner = detector.runnerFor({
serenity: {
runner: 'cucumber',
},
cucumberOpts: {},
jasmineNodeOpts: {},
});

expect(runner).to.be.instanceOf(CucumberTestRunner);
});

it('uses the JasmineTestRunner', () => {
const runner = detector.runnerFor({
serenity: {
@@ -34,6 +46,18 @@ describe('TestRunnerDetector', () => {
expect(runner).to.be.instanceOf(JasmineTestRunner);
});

it('uses the JasmineTestRunner even when the Cucumber config is present as well', () => {
const runner = detector.runnerFor({
serenity: {
runner: 'jasmine',
},
cucumberOpts: {},
jasmineNodeOpts: {},
});

expect(runner).to.be.instanceOf(JasmineTestRunner);
});

it('uses the MochaTestRunner');
});

@@ -25,14 +25,32 @@ export class TestRunnerDetector {

// todo: simplify and introduce a config object with "as(String)", "as(Object)", etc. to avoid issues with undefined
// todo: and config merge too, using on deepmerge
if (
(config.serenity && config.serenity.runner && config.serenity.runner === 'cucumber') ||
(config.cucumberOpts)
) {
const { CucumberTestRunner } = require('./runners/CucumberTestRunner');
return new CucumberTestRunner(config.cucumberOpts || {}, this.loader);

const
specifiesRunnerFor = (type: string) =>
!!config.serenity &&
!!config.serenity.runner &&
config.serenity.runner === type;

switch (true) {
case specifiesRunnerFor('cucumber'):
return this.useCucumber(config);
case specifiesRunnerFor('jasmine'):
return this.useJasmine(config);
case !! config.cucumberOpts:
return this.useCucumber(config);
case !! config.jasmineNodeOpts:
default:
return this.useJasmine(config);
}
}

private useCucumber(config: Config): TestRunner {
const { CucumberTestRunner } = require('./runners/CucumberTestRunner');
return new CucumberTestRunner(config.cucumberOpts || {}, this.loader);
}

private useJasmine(config: Config): TestRunner {
const { JasmineTestRunner } = require('./runners/JasmineTestRunner');
return new JasmineTestRunner(config.jasmineNodeOpts, this.loader);
}

0 comments on commit e5e638b

Please sign in to comment.