Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat(protractor): protractor adapter merges capability-level test r…
  • Loading branch information
jan-molak committed Feb 26, 2021
1 parent 08425ce commit f8a830c
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 6 deletions.
50 changes: 50 additions & 0 deletions packages/protractor/spec/adapter/runner/TestRunnerDetector.spec.ts
Expand Up @@ -56,6 +56,23 @@ describe('TestRunnerDetector', () => {
expect(testRunnerLoader.forCucumber).to.have.been.calledWith(emptyRunnerConfig, defaultAdapterConfig);
});

it('merges cucumberOpts present in capabilities with root config', () => {
const runner = detector.runnerFor({
cucumberOpts: {
tags: ['@wip'],
name: 'example scenario',
},
capabilities: {
cucumberOpts: {
name: 'different scenario',
},
}
});

expect(testRunnerLoader.forCucumber)
.to.have.been.calledWith({ tags: ['@wip'], name: 'different scenario' }, defaultAdapterConfig);
});

describe('instructs TestRunnerLoader', () => {

describe('to take over standard output when the config', () => {
Expand Down Expand Up @@ -187,6 +204,22 @@ describe('TestRunnerDetector', () => {

expect(testRunnerLoader.forJasmine).to.have.been.calledWith({});
});

it('merges jasmineNodeOpts present in capabilities with root config', () => {
const runner = detector.runnerFor({
jasmineNodeOpts: {
defaultTimeoutInterval: 5,
},
capabilities: {
jasmineNodeOpts: {
defaultTimeoutInterval: 10,
},
}
});

expect(testRunnerLoader.forJasmine)
.to.have.been.calledWith({ defaultTimeoutInterval: 10 });
});
});

describe('Mocha', () => {
Expand Down Expand Up @@ -221,6 +254,23 @@ describe('TestRunnerDetector', () => {

expect(testRunnerLoader.forMocha).to.have.been.calledWith({});
});

it('merges mochaOpts present in capabilities with root config', () => {
const runner = detector.runnerFor({
mochaOpts: {
timeout: 5,
},
capabilities: {
mochaOpts: {
timeout: 10,
},
}
});

expect(testRunnerLoader.forMocha)
.to.have.been.calledWith({ timeout: 10 });
});

});
});
});
25 changes: 19 additions & 6 deletions packages/protractor/src/adapter/runner/TestRunnerDetector.ts
Expand Up @@ -11,11 +11,15 @@ import { TestRunnerLoader } from './TestRunnerLoader';
*/
export class TestRunnerDetector {

static cucumberOpts = 'cucumberOpts';
static jasmineNodeOpts = 'jasmineNodeOpts';
static mochaOpts = 'mochaOpts';

static protractorCliOptions() {
return [
'cucumberOpts',
'jasmineNodeOpts',
'mochaOpts',
TestRunnerDetector.cucumberOpts,
TestRunnerDetector.jasmineNodeOpts,
TestRunnerDetector.mochaOpts,
];
}

Expand Down Expand Up @@ -55,23 +59,32 @@ export class TestRunnerDetector {
}

private useJasmine(config: ProtractorConfig): TestRunnerAdapter {
return this.testRunnerLoader.forJasmine(config.jasmineNodeOpts || {});
return this.testRunnerLoader.forJasmine(this.mergedConfigFor(config, TestRunnerDetector.jasmineNodeOpts));
}

private useMocha(config: ProtractorConfig): TestRunnerAdapter {
return this.testRunnerLoader.forMocha(config.mochaOpts || {});
return this.testRunnerLoader.forMocha(this.mergedConfigFor(config, TestRunnerDetector.mochaOpts));
}

private useCucumber(config: ProtractorConfig): TestRunnerAdapter {

const serenityReportingServicesConfigured = config?.serenity?.crew?.length > 0;

return this.testRunnerLoader.forCucumber(config.cucumberOpts || {}, {
return this.testRunnerLoader.forCucumber(this.mergedConfigFor(config, TestRunnerDetector.cucumberOpts), {
useStandardOutput: serenityReportingServicesConfigured,
uniqueFormatterOutputs: this.multiCapabilitiesOrTestShardingEnabled(config),
})
}

private mergedConfigFor<K extends keyof ProtractorConfig>(config: ProtractorConfig = {}, key: K): ProtractorConfig[K] {
// tslint:disable-next-line:prefer-object-spread
return Object.assign(
{},
config[key],
(config.capabilities || {})[key],
);
}

private multiCapabilitiesOrTestShardingEnabled(config: ProtractorConfig): boolean {
return !! (
(Array.isArray(config.multiCapabilities) && config.multiCapabilities.length > 0)
Expand Down

0 comments on commit f8a830c

Please sign in to comment.