我在k6 -性能测试中进行了测试。
我需要将今天的日期添加到html报告中:
import http from 'k6/http';
import { sleep } from 'k6';
import { htmlReport } from "https://raw.githubusercontent.com/benc-uk/k6-reporter/main/dist/bundle.js";
import { textSummary } from "https://jslib.k6.io/k6-summary/0.0.1/index.js";
export function handleSummary(data) {
return {
"./report/xxxxx.html": htmlReport(data),
stdout: textSummary(data, { indent: " ", enableColors: true }),
};
}
export const options = {
ext: {
loadimpact: {
distribution: {
"amazon:us:ashburn": { loadZone: "amazon:us:ashburn", percent: 100 },
},
},
},
stages: [
{ target: 5, duration: "5s" },
{ target: 10, duration: "10s" },
{ target: 5, duration: "5s" },
],
thresholds: {
"http_req_duration": ["p(95)<5000"],
"http_req_failed": ["rate<0.01"],
}
};
export default function () {
const res = http.get('https://xxxx/');
sleep(1);
}我不知道,我怎样才能把今天的日期加到报告的标题上呢?
我今天试着用加法。
谢谢!
发布于 2022-10-05 08:15:44
您所遇到的问题可能来自JavaScript使用动态键创建对象的方式。
因此,您可以直接使用当前日期对象:
export function handleSummary(data) {
return {
[`./report/${new Date()}.html`]: htmlReport(data),
stdout: textSummary(data, { indent: " ", enableColors: true }),
};
}这样就会创建一个类似于:Wed Oct 05 2022 10:05:44 GMT+0200 (CEST).html的文件。因为这并不是一种很好的可读性格式,所以我们也可以使用@knittl来实现.toISOString()的建议。
export function handleSummary(data) {
return {
[`./report/${new Date().toISOString()}.html`]: htmlReport(data),
stdout: textSummary(data, { indent: " ", enableColors: true }),
};
}这样就会产生类似于2022-10-05T08:09:54.005Z.html的东西。当然,您也可以以您喜欢的任何方式格式化日期字符串。
https://stackoverflow.com/questions/73306552
复制相似问题