jest-bdd-generator
Version:
Jest code generator empowered with Gherkin and BDD
182 lines (181 loc) • 6.63 kB
JavaScript
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var src_exports = {};
__export(src_exports, {
runTests: () => runTests
});
module.exports = __toCommonJS(src_exports);
var import_api = require("@cucumber/cucumber/api");
var path = __toESM(require("path"));
var fs = __toESM(require("fs"));
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;
}
function runTests(options) {
return _runTests.apply(this, arguments);
}
function _runTests() {
_runTests = _async_to_generator(function* (options) {
const { runConfiguration } = yield (0, import_api.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 (0, import_api.loadSupport)(runConfiguration);
const { success } = yield (0, import_api.runCucumber)(_object_spread_props(_object_spread({}, runConfiguration), {
support
}));
return success;
});
return _runTests.apply(this, arguments);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
runTests
});
//# sourceMappingURL=index.js.map