UNPKG

@serenity-js/protractor

Version:

Adapter that integrates @serenity-js/web with Protractor, enabling Serenity/JS reporting and using the Screenplay Pattern to write end-to-end test scenarios

68 lines 2.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TestRunnerDetector = void 0; /** * Detects the [`TestRunnerAdapter`](https://serenity-js.org/api/core-adapter/interface/TestRunnerAdapter/) to use, * based on Protractor configuration. * * @group Integration */ class TestRunnerDetector { testRunnerLoader; static cucumberOpts = 'cucumberOpts'; static jasmineNodeOpts = 'jasmineNodeOpts'; static mochaOpts = 'mochaOpts'; static protractorCliOptions() { return [ TestRunnerDetector.cucumberOpts, TestRunnerDetector.jasmineNodeOpts, TestRunnerDetector.mochaOpts, ]; } constructor(testRunnerLoader) { this.testRunnerLoader = testRunnerLoader; } runnerFor(config) { const specifiesRunnerFor = (type) => !!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 specifiesRunnerFor('mocha'): return this.useMocha(config); case !!config.cucumberOpts: return this.useCucumber(config); case !!config.mochaOpts: return this.useMocha(config); case !!config.jasmineNodeOpts: // eslint-disable-line unicorn/no-useless-switch-case default: return this.useJasmine(config); } } useJasmine(config) { return this.testRunnerLoader.forJasmine(this.mergedConfigFor(config, TestRunnerDetector.jasmineNodeOpts)); } useMocha(config) { return this.testRunnerLoader.forMocha(this.mergedConfigFor(config, TestRunnerDetector.mochaOpts)); } useCucumber(config) { const serenityReportingServicesConfigured = config?.serenity?.crew?.length > 0; return this.testRunnerLoader.forCucumber(this.mergedConfigFor(config, TestRunnerDetector.cucumberOpts), { useStandardOutput: serenityReportingServicesConfigured, uniqueFormatterOutputs: this.multiCapabilitiesOrTestShardingEnabled(config), }); } mergedConfigFor(config = {}, key) { return Object.assign({}, config[key], (config.capabilities || {})[key]); } multiCapabilitiesOrTestShardingEnabled(config) { return !!((Array.isArray(config.multiCapabilities) && config.multiCapabilities.length > 0) || typeof config.getMultiCapabilities === 'function' || config.capabilities?.shardTestFiles); } } exports.TestRunnerDetector = TestRunnerDetector; //# sourceMappingURL=TestRunnerDetector.js.map