i have this k6 script but i can't seem to get the errors to show up in my html file although if i console.log i see them
import http from "k6/http";
import { sleep, check } from "k6";
import { htmlReport } from "https://raw.githubusercontent.com/benc-uk/k6- reporter/main/dist/bundle.js";
export const options = {
stages: [
{ duration: "1s", target: 100 }, // Ramp-up to 100 users in 1 minute
{ duration: "3s", target: 200 }, // Ramp-up to 200 users over 3 minutes
{ duration: "5s", target: 500 }, // Sustain 500 users for 5 minutes
{ duration: "2s", target: 100 }, // Ramp-down to 100 users over 2 minutes
{ duration: "1s", target: 0 }, // Gradual cooldown to 0 users in 1 minute
],
thresholds: {
http_req_duration: ["p(95)<200"], // 95% of requests must complete within 200ms
http_req_failed: ["rate<0.01"], // Less than 1% of requests should fail
},
};
// Initialize shared state for failed requests
let globalFailedRequests = \[\];
export default () =\> {
const url =
"https://test-url/limit=50&langcode=en";
const res = http.get(url);
const success = check(res, {
"status is 200": (r) =\> r.status === 200,
"response time \< 200ms": (r) =\> r.timings.duration \< 200,
});
if (!success) {
globalFailedRequests.push({
url: url,
status: res.status,
error: res.body || "No error message",
responseTime: res.timings.duration,
});
console.log(
`Request success: ${success}, Status code: ${res.status}, timing: ${res.timings.duration}`
);
}
sleep(6); // Simulate delay between requests
};
export function handleSummary(data) {
const failedRequestsHtml = globalFailedRequests
.map(
(req) =\>
`<li><strong>URL:</strong> ${req.url} | <strong>Status:</strong> ${req.status} | <strong>Error:</strong> ${req.error}</li>`
)
.join("");
// Add failed request information to the HTML summary
const additionalHtml = ` <h3>Failed Requests</h3> <ul>${failedRequestsHtml || "<li>No failed requests</li>"}</ul> `;
// Modify the final HTML report by appending the additional HTML
const reportWithFailures = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Load Test Summary Report</title>
<style>
body { font-family: Arial, sans-serif; }
h1 { color: #333; }
</style>
</head>
<body>
<h1>Load Test Summary Report</h1>
${htmlReport(data)}
${additionalHtml}
</body>
</html>
`;
// Return the modified HTML report
return {
"getLoad.html": reportWithFailures, // Generate HTML report with failed requests
};}
the console.log shows the errors but it seems they don't get added to the array in handleSummary() this is an example of an error i seen to be able to view in my terminal Request success: false, Status code: 200, timing: 28824.404
i am also able to output the errors in a json file but i need them to be within the html file in this usecase