@badeball/cypress-cucumber-preprocessor
Version:
[](https://github.com/badeball/cypress-cucumber-preprocessor/actions/workflows/build.yml) [ • 2.58 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.runStepWithLogGroup = void 0;
const data_table_1 = __importDefault(require("../data_table"));
const error_1 = require("./error");
const ensureChain = (value) => Cypress.isCy(value) ? value : cy.wrap(value, { log: false });
// eslint-disable-next-line @typescript-eslint/no-empty-function
const nativePromiseConstructor = (async () => { })().constructor;
function getMaxColumnWidths(tableArray) {
const maxColumnWidths = [];
for (const row of tableArray) {
for (let i = 0; i < row.length; i++) {
const cell = row[i];
const cellWidth = cell.length;
maxColumnWidths[i] = Math.max(maxColumnWidths[i] || 0, cellWidth);
}
}
return maxColumnWidths;
}
function padElements(tableArray, maxColumnWidths) {
return tableArray.map((row) => row.map((cell, index) => (cell = cell + " ".repeat(maxColumnWidths[index] - cell.length))));
}
function convertArrayToTableString(tableArray) {
const maxColumnWidths = getMaxColumnWidths(tableArray);
const paddedTableArray = padElements(tableArray, maxColumnWidths);
const lines = paddedTableArray.map((row) => row.join(" | "));
const tableString = lines.join(" |\n| ");
return tableString;
}
function runStepWithLogGroup(options) {
Cypress.log({
name: options.keyword,
message: options.text == null ? "" : `**${options.text}**`,
groupStart: true,
type: "parent",
});
if (options.argument instanceof data_table_1.default) {
Cypress.log({
name: "DataTable",
message: " \n| " +
convertArrayToTableString(options.argument.raw()) +
" |",
});
}
else if (typeof options.argument === "string") {
// TODO: Log docstring here.
}
const ret = options.fn();
if (ret instanceof nativePromiseConstructor) {
throw new error_1.CypressCucumberError("Cucumber preprocessor detected that you returned a native promise from a function handler, this is not supported. Using async / await is generally speaking not supported when using Cypress, period, preprocessor or not.");
}
return ensureChain(ret).then((result) => {
Cypress.log({ groupEnd: true, emitOnly: true });
return result;
});
}
exports.runStepWithLogGroup = runStepWithLogGroup;