UNPKG

rs-qadashboard

Version:

An NPM package for seamless integration of your test pipeline results with our intuitive dashboard!

53 lines (48 loc) 1.53 kB
// Import required modules const fs = require("fs"); const path = require("path"); async function mergeXML(dirname) { let header = '<?xml version="1.0" encoding="UTF-8"?>'; let subheader = '<testsuites>'; let footer = "</testsuites>"; let result = [header]; result.push(subheader); let files = fs.readdirSync(dirname).filter((el) => { return path.extname(el) === ".xml"; }); for await (let file of files) { let fileContent = fs.readFileSync(path.join(dirname, file), "utf-8"); let lines = fileContent .split("\n") .map((line) => line.replace(/^\s*-\s*/, "")); lines = lines.filter((line) => line.trim() !== "" && !line.startsWith("-") && !line.includes('testsuites') && !line.includes('xml version')); result = result.concat(lines); } result.push(footer); return result.join("\n"); } async function sendPostRequest(token, pathFiles, endpoint) { try { const xmlContent = await mergeXML(pathFiles); const response = await fetch(endpoint, { method: "POST", headers: { "Content-Type": "application/xml", token: token, }, body: xmlContent, }); if (response.ok) { console.log("Reporte enviado con éxito"); } else { console.log(response) throw new Error("Error en la solicitud"); } } catch (error) { console.error("Error al enviar la solicitud:", error.message); } } module.exports = { sendPostRequest, default: sendPostRequest, }