UNPKG

jest-allure2-reporter

Version:
51 lines 2.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.StepsDecorator = void 0; const utils_1 = require("../../utils"); class StepsDecorator { context; constructor(context) { this.context = context; } createStep(nameFormat, function_, userParameters) { const runtime = this.context.runtime; const formatName = this.context.handlebars.compile(nameFormat); function resolveParameters(arguments_) { const parameters = userParameters ?? Array.from(arguments_, noop); return parameters.map(resolveParameter, arguments_); } function createHandlebarsContext(parameters) { const context = {}; for (const [name, index, value] of parameters) { context[name] = value; context[index] = value; } return context; } const handleArguments = (parameters) => { for (const [name, , value, options, raw] of parameters) { if (raw != null || userParameters == null) { runtime.parameter(name, value, options); } } }; return (0, utils_1.wrapFunction)(function_, function () { const arguments_ = arguments; const parameters = resolveParameters(arguments_); const handlebarsContext = createHandlebarsContext(parameters); return runtime.step(formatName(handlebarsContext), (0, utils_1.wrapFunction)(function_, function step() { handleArguments(parameters); return Reflect.apply(function_, this, arguments_); }.bind(this))); }); } } exports.StepsDecorator = StepsDecorator; function resolveParameter(parameter, index) { const { name = `${index}`, ...options } = typeof parameter === 'string' ? { name: parameter } : (parameter ?? {}); return [name, index, this[index], options, parameter]; } function noop() { /* no-op */ } //# sourceMappingURL=StepsDecorator.js.map