UNPKG

jest-allure2-reporter

Version:
65 lines 1.92 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.StepsModule = void 0; const utils_1 = require("../../utils"); class StepsModule { context; constructor(context) { this.context = context; } static create(context) { return new StepsModule({ get metadata() { return context.getCurrentMetadata(); }, get now() { return context.getNow(); }, }); } step(name, function_) { this.#startStep(name); const end = this.#stopStep; let result; try { result = function_(); if ((0, utils_1.isPromiseLike)(result)) { this.context.metadata.set('stage', 'running'); result.then(() => end(), (error) => end(error)); } else { end(); } return result; } catch (error) { end(error); throw error; } } #startStep = (displayName) => { this.context.metadata.$startStep().assign({ stage: 'scheduled', start: this.context.now, displayName, }); }; #stopStep = (error) => { if (error === undefined) { this.context.metadata .defaults({ status: 'passed' }) .assign({ stage: 'finished', stop: this.context.now }); } else { this.context.metadata.assign({ stage: 'interrupted', status: (0, utils_1.isJestAssertionError)(error) ? 'failed' : 'broken', statusDetails: (0, utils_1.getStatusDetails)(error), stop: this.context.now, }); } this.context.metadata.$stopStep(); }; } exports.StepsModule = StepsModule; //# sourceMappingURL=StepsModule.js.map