UNPKG

@testomatio/reporter

Version:
152 lines (151 loc) 5.26 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const playwright_js_1 = require("./adapter/utils/playwright.js"); const helpers_js_1 = require("./helpers.js"); const index_js_1 = require("./services/index.js"); const picocolors_1 = __importDefault(require("picocolors")); /** * Stores path to file as artifact and uploads it to the S3 storage * @param {string | {path: string, type: string, name: string}} data - path to file or object with path, type and name * @param {any} [context=null] - optional context parameter * @returns {void} */ function saveArtifact(data, context = null) { if (helpers_js_1.isPlaywright) console.warn(`[TESTOMATIO] 'artifact' function is not supported for Playwright Playwright supports artifacts out of the box.`); if (!data) return; index_js_1.services.artifacts.put(data, context); } /** * Attach log message(s) to the test report * @param {...any} args - log messages to attach * @returns {void} */ function logMessage(...args) { index_js_1.services.logger._templateLiteralLog(...args); } /** * Similar to "log" function but marks message in report as a step * @param {string} message - step message * @param {{[key: string]: any}} [logs] optional key-value object with additional info, e.g. logs * @returns {void} * * Example: * step('Get response', { logs: {status: 'success'} }); */ function addStep(message, logs) { // this is done because Playwright reporter intercepts console logs and then we gather them and show on Testomat // if not console.log, the step message will be lost from reporter if (helpers_js_1.isPlaywright) index_js_1.services.logger._templateLiteralLog(message, logs); // all other frameworks else index_js_1.services.logger.step(message, logs); } /** * Add key-value pair(s) to the test report * @param {{[key: string]: string} | string} keyValue - object { key: value } (multiple props allowed) OR key (string) * @param {string|undefined} [value=undefined] - optional value when keyValue is a string * @returns {void} * * @example * meta('key', 'value'); * meta({ key: 'value' }); * meta({ key1: 'value1', key2: 'value2' }); */ function setKeyValue(keyValue, value = undefined) { // in this case keyValue acts as key (value passed as second argument) if (typeof keyValue === 'string') { const key = keyValue; keyValue = { [key]: value }; } if (helpers_js_1.isPlaywright) { console.log(`${playwright_js_1.playwrightLogsMarkers.meta} ${JSON.stringify(keyValue)}`); return; } // in this case keyValue is expected to be an object index_js_1.services.keyValues.put(keyValue); } /** * Adds label(s) to the test * @param {string | { * [key: string]: string} * } key - just label OR custom field name OR object with custom field name and value * @param {string | null} [value=null] - optional label value (of custom field value) * (used when key is a string) * @returns {void} * * @example * label('high'); * label('priority', 'high'); * label({priority: 'high'}); */ function setLabel(key, value = null) { let labelsArr = []; // process label('priority', 'high') and label('high' if (typeof key === 'string') { labelsArr = [value ? `${key}:${value}` : key]; // process label({priority: 'high'}), label({priority: 'high', scope: 'smoke'}) } else if (key !== null && typeof key === 'object') { labelsArr = Object.entries(key).map(([key, value]) => `${key}:${value}`); } const labels = labelsArr.map(l => ({ label: l })); if (helpers_js_1.isPlaywright) { console.log(`${playwright_js_1.playwrightLogsMarkers.label} ${JSON.stringify(labels)}`); return; } index_js_1.services.links.put(labels); } /** * Add link(s) to the test report * @param {...string | string[]} testIds - test IDs to link * @returns {void} * * @example * linkTest('T11111111', 'T22222222') * or * linkTest(['T11111111', 'T22222222']) */ function linkTest(...testIds) { const testIdsArr = testIds.flat(); const links = testIdsArr.map(testId => ({ test: testId })); if (helpers_js_1.isPlaywright) { console.log(`${playwright_js_1.playwrightLogsMarkers.linkTest} ${JSON.stringify(links)}`); return; } index_js_1.services.links.put(links); } /** * Add JIRA issue link(s) to the test report * @param {...(string | string[])} jiraIds - JIRA issue IDs to link * @returns {void} * * @example * linkJira('TICKET-1', 'TICKET-2') * or * linkJira(['TICKET-1', 'TICKET-2']) */ function linkJira(...jiraIds) { const jiraIdsArr = jiraIds.flat(); const links = jiraIdsArr.map(jiraId => ({ jira: jiraId })); if (helpers_js_1.isPlaywright) { console.log(`${playwright_js_1.playwrightLogsMarkers.linkJira} ${JSON.stringify(links)}`); return; } index_js_1.services.links.put(links); } module.exports = { artifact: saveArtifact, log: logMessage, step: addStep, keyValue: setKeyValue, label: setLabel, linkTest, linkJira, };