UNPKG

@serenity-js/webdriverio

Version:

Adapter that integrates @serenity-js/web with the latest stable version of WebdriverIO, enabling Serenity/JS reporting and using the Screenplay Pattern to write web and mobile test scenarios

67 lines 3.13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TestRunnerLoader = void 0; const core_1 = require("@serenity-js/core"); const index_js_1 = require("@serenity-js/core/lib/io/index.js"); class TestRunnerLoader { loader; cwd; cid; fileSystem; finder; constructor(loader, cwd, cid) { this.loader = loader; this.cwd = cwd; this.cid = cid; this.fileSystem = new index_js_1.FileSystem(cwd); this.finder = new index_js_1.FileFinder(cwd); } runnerAdapterFor(config) { switch (config?.serenity?.runner) { case 'cucumber': return this.cucumberAdapter(config?.cucumberOpts); case 'jasmine': return this.jasmineAdapter(config?.jasmineOpts); case 'mocha': case undefined: return this.mochaAdapter(config?.mochaOpts); default: throw new core_1.ConfigurationError(`"${config?.serenity?.runner}" is not a supported test runner. Please use "mocha", "jasmine", or "cucumber"`); } } cucumberAdapter(cucumberOptions) { const { CucumberCLIAdapter, CucumberFormat, StandardOutput, TempFileOutput } = this.loader.require('@serenity-js/cucumber/lib/adapter/index.js'); delete cucumberOptions?.timeout; // todo: support setting a timeout via config? delete cucumberOptions?.parallel; // WebdriverIO handles that already const cleanedCucumberOptions = new index_js_1.Config(cucumberOptions) .where('format', values => [].concat(values).map(value => { const format = new CucumberFormat(value); if (format.output === '') { return format.value; } const basename = index_js_1.Path.from(format.output).basename(); const filenameParts = basename.split('.'); if (filenameParts[0] === basename) { return `${format.formatter}:${format.output}.${this.cid}`; } filenameParts.splice(-1, 0, `${this.cid}`); return `${format.formatter}:${format.output.replace(basename, filenameParts.join('.'))}`; })).object(); // check if we need to free up stdout for any native reporters const output = cleanedCucumberOptions?.format?.some(format => new CucumberFormat(format).output === '') ? new TempFileOutput(this.fileSystem) : new StandardOutput(); return new CucumberCLIAdapter(cleanedCucumberOptions, this.loader, this.fileSystem, output); } jasmineAdapter(jasmineOptions) { const { JasmineAdapter } = this.loader.require('@serenity-js/jasmine/adapter'); return new JasmineAdapter(jasmineOptions, this.loader); } mochaAdapter(mochaOptions) { // todo: update path to mocha adapter too const { MochaAdapter } = this.loader.require('@serenity-js/mocha/lib/adapter/index.js'); return new MochaAdapter(mochaOptions, this.loader); } } exports.TestRunnerLoader = TestRunnerLoader; //# sourceMappingURL=TestRunnerLoader.js.map