UNPKG

k6-cucumber-steps

Version:

Cucumber step definitions for running k6 performance tests.

83 lines (67 loc) 2.48 kB
const fs = require("fs"); const path = require("path"); const { minify } = require("html-minifier-terser"); const reportsDir = path.resolve("reports"); async function linkReports() { if (!fs.existsSync(reportsDir)) { console.warn("⚠️ No reports directory found."); return; } // Get all HTML files in the reports directory, excluding any with "combined-" in the name const htmlFiles = fs .readdirSync(reportsDir) .filter((f) => f.endsWith(".html") && !f.includes("combined-")) .map((f) => ({ name: f, path: path.join(reportsDir, f), mtime: fs.statSync(path.join(reportsDir, f)).mtime.getTime(), })); if (htmlFiles.length === 0) { console.warn("⚠️ No HTML reports found."); return; } // Find k6 report: file starting with "k6-" or fallback to most recent let k6Report = htmlFiles.find((f) => f.name.startsWith("k6-")); if (!k6Report) { k6Report = htmlFiles.reduce((a, b) => (a.mtime > b.mtime ? a : b)); } // Find all other HTML reports (excluding k6 report) const otherReports = htmlFiles.filter((f) => f.name !== k6Report.name); if (!k6Report || otherReports.length === 0) { console.warn("⚠️ K6 or any other HTML report not found."); return; } // Read k6 report content let content = fs.readFileSync(k6Report.path, "utf8"); // Build tabs for each other report const tabs = otherReports .map( (report, idx) => ` <input type="radio" name="tabs" id="tab${idx + 2}"> <label for="tab${idx + 2}"><i class="fas fa-file-alt"></i> &nbsp; ${report.name}</label> <div class="tab"> <iframe src="${report.name}" style="width:100%; height:600px; border:none;"></iframe> </div> ` ) .join("\n"); // Insert tabs after the first tab (assumes k6 report has a tab structure) content = content.replace( /<input type="radio" name="tabs" id="tabone"/, `${tabs}\n<input type="radio" name="tabs" id="tabone"` ); // Remove any existing footer content = content.replace( /<div style="padding:10px;margin-top:20px;text-align:center">[\s\S]*?<\/div>/, "" ); const minified = await minify(content, { collapseWhitespace: true, removeComments: true, minifyCSS: true, }); const combinedPath = path.join(reportsDir, "combined-report.html"); fs.writeFileSync(combinedPath, minified, "utf8"); console.log(`📄 Combined report generated at: ${combinedPath}`); } module.exports = { linkReports };