UNPKG

suitest-js-api

Version:

Suitest is a test automation and device manipulation tool for living room devices and web browsers.

50 lines (41 loc) 1.39 kB
const { translateProgress, translateNotStartedReason, translateTestLine, translateTestLineResult, } = require('@suitest/translate'); const {compose} = require('ramda'); const text = require('@suitest/smst-to-text'); /** * Transforms markdown string * @param {string} md * @returns {string} */ const transformMarkdown = md => md .replace(/\*\*(.*?)\*\*/g, '$1') // bold text -> regular text .replace(/\(mailto:(.*?)\)/g, '($1)') // mailto links -> regular link .replace(/!?\[(.*?)\]\((.*?)\)({.*})?/g, (_, text, url) => { return text === url ? `(${url})` : `${text} (${url})`; }); // links, previews -> text + url /** * Composes output text from result object with title and description. * @param {{title: [{type: string, value: string}], description: [{type: string, value: string}]}} result * @returns {string} - composed text */ const titleDescToText = (result) => { const titleResult = text.toText(result.title, {}); if (result.description) { const descriptionResult = text.toText(result.description, {}); return `${titleResult}\n${descriptionResult}`; } return `${titleResult}`; }; module.exports = { translateNotStartedReason: compose(titleDescToText, translateNotStartedReason), translateProgress: compose(titleDescToText, translateProgress), // for testing transformMarkdown, titleDescToText, translateTestLine, translateTestLineResult, };