UNPKG

jest-bdd-generator

Version:

Jest code generator empowered with Gherkin and BDD

148 lines (147 loc) 5 kB
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } function _async_to_generator(fn) { return function() { var self = this, args = arguments; return new Promise(function(resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(void 0); }); }; } function _define_property(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _object_spread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys2 = Object.keys(source); if (typeof Object.getOwnPropertySymbols === "function") { ownKeys2 = ownKeys2.concat(Object.getOwnPropertySymbols(source).filter(function(sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys2.forEach(function(key) { _define_property(target, key, source[key]); }); } return target; } function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function(sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; } function _object_spread_props(target, source) { source = source != null ? source : {}; if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function(key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } import { loadConfiguration, loadSupport, runCucumber } from "@cucumber/cucumber/api"; import * as path from "path"; import * as fs from "fs"; function runTests(options) { return _runTests.apply(this, arguments); } function _runTests() { _runTests = _async_to_generator(function* (options) { const { runConfiguration } = yield loadConfiguration(); runConfiguration.support.requireModules = [ path.join(__dirname, `./jest-execute/jest-ts-register${path.extname(__filename)}`) ]; if (options.pathTestsInput) { if (fs.lstatSync(options.pathTestsInput).isDirectory()) { const foldername = options.pathTestsInput; runConfiguration.support.requirePaths = fs.readdirSync(options.pathTestsInput).filter((subPath) => path.extname(subPath) === ".ts").map((fname) => path.join(foldername, fname)); } else { runConfiguration.support.requirePaths = [ options.pathTestsInput ]; } runConfiguration.formats.files = { [`${path.basename(options.pathTestsInput)}-report.html`]: "html" }; } if (options.pathFeatureInput) { runConfiguration.sources.paths = [ options.pathFeatureInput ]; if (fs.lstatSync(options.pathFeatureInput).isFile()) { const featureBookName = path.basename(options.pathFeatureInput).replace(/\.feature$/, ""); runConfiguration.formats.files = { [`${featureBookName}-report.html`]: "html" }; runConfiguration.support.requirePaths = runConfiguration.support.requirePaths.filter((filename) => path.basename(filename).indexOf(featureBookName) !== -1); } } if (options.scenario) { runConfiguration.sources.names = options.scenario; const reportNameWithScenario = {}; Object.keys(runConfiguration.formats.files).forEach((key) => { reportNameWithScenario[`${path.basename(key)}-${options.scenario}.html`] = "html"; }); runConfiguration.formats.files = reportNameWithScenario; } if (options.pathOutput) { const pathOutput = options.pathOutput; const filesFormats = runConfiguration.formats.files; runConfiguration.formats.files = {}; Object.keys(filesFormats).forEach((key) => { const k = path.join(pathOutput, key); runConfiguration.formats.files[k] = filesFormats[key]; }); } const support = yield loadSupport(runConfiguration); const { success } = yield runCucumber(_object_spread_props(_object_spread({}, runConfiguration), { support })); return success; }); return _runTests.apply(this, arguments); } export { runTests }; //# sourceMappingURL=index.js.map