UNPKG

wdio-azure-devops-test-reporter

Version:

A WebdriverIO reporter to create reports to import into Azure Test Plan

63 lines (62 loc) 3.05 kB
import { colorCodeRegex } from "./constants.js"; import { markdownTable } from "markdown-table"; export class Utils { convertIdToAzureActionPathId(id) { const actionPathIdLength = 8; return id.toString(16).toUpperCase().padStart(actionPathIdLength, "0"); } parseCaseID(tags, idMatchingRegex) { if (tags) { let pattern = /@?AzureID-(\d+)/g; if (idMatchingRegex) { pattern = new RegExp(idMatchingRegex, "g"); } for (const tag of tags) { const matchInfo = pattern.exec(typeof tag === "string" ? tag : tag.name); if (matchInfo != null) { return Number(matchInfo[1]); } } } return 0; } getAzureConfigurationIDByCapability(runnerCapabilities, azureConfigurationCapabilities) { const runnerCapabilityFields = Object.keys(runnerCapabilities); const runnerCapabilityValues = Object.values(runnerCapabilities); const matchedId = azureConfigurationCapabilities.find((azureConfigurationCapability) => { const areCapFieldsMatched = Object.keys(azureConfigurationCapability.capabilities).every((capabilityField) => runnerCapabilityFields.find((runnerCapabilityField) => capabilityField.toLowerCase() === runnerCapabilityField.toLowerCase())); const areCapValuesMatched = Object.values(azureConfigurationCapability.capabilities).every((capabilityValue) => runnerCapabilityValues.find((runnerCapabilityValue) => String(capabilityValue).toLowerCase() === String(runnerCapabilityValue).toLowerCase())); return areCapFieldsMatched && areCapValuesMatched; })?.azureConfigId; return matchedId ?? ""; } removeColorCode(error) { return error.replace(colorCodeRegex, ""); } isScreenshotCommand(command) { const isScrenshotEndpoint = /\/session\/[^/]*(\/element\/[^/]*)?\/screenshot/; return ( // WebDriver protocol (command.endpoint && isScrenshotEndpoint.test(command.endpoint)) || // DevTools protocol command.command === "takeScreenshot"); } formatTestArgument(argument) { if (argument) { if (typeof argument === "string") { return argument; } else { const table = argument.rows?.map((row) => row.cells); const formattedTable = table ? markdownTable(table) : ""; // Remove the seperator line between table header and table body const indexOfFirstLineBreak = formattedTable.indexOf("\n"); const indexOfSecondLineBreak = formattedTable.indexOf("\n", indexOfFirstLineBreak + 1); const header = formattedTable.substring(0, indexOfFirstLineBreak); const body = formattedTable.substring(indexOfSecondLineBreak + 1); return `${header}\n${body}`.replace(/\n/g, "\n\n"); } } return ""; } }