UNPKG

jest-allure2-adapter

Version:
36 lines (35 loc) 1.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getContent = exports.dateStr = void 0; const allure_js_commons_1 = require("allure-js-commons"); const dateNow = Date.now; const stripAnsi = require('strip-ansi'); function addZero(num, digits = 2) { return `${('0' + num).slice(-digits)}`; } exports.dateStr = (isFileName = false) => { const date = new Date(dateNow()); return (date.getFullYear() + '-' + addZero(date.getMonth() + 1) + '-' + addZero(date.getDate()) + (isFileName ? 'T' : ' ') + addZero(date.getUTCHours()) + (isFileName ? '-' : ':') + addZero(date.getMinutes()) + (isFileName ? '-' : ':') + addZero(date.getSeconds()) + '.' + addZero(date.getMilliseconds(), 3)); }; function getContent(content, type) { if (typeof content === 'string') { return stripAnsi(content); } if (type === allure_js_commons_1.ContentType.JSON) { return JSON.stringify(content); } return content; } exports.getContent = getContent;