Skip to content

Commit 7693c71

Browse files
committed
feat(k6): improve HTML reports using k6-reporter
- Replace hand-rolled HTML summary with htmlReport() from benc-uk/k6-reporter - Add textSummary import for stdout output - Gitignore tests/k6/reports/ directory
1 parent 992ac4c commit 7693c71

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,4 @@ bld/
4747
msbuild.log
4848
msbuild.err
4949
msbuild.wrn
50+
tests/k6/reports/

tests/k6/customers.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import http from 'k6/http';
22
import { check, sleep } from 'k6';
33
import { Trend, Rate } from 'k6/metrics';
4+
import { textSummary } from 'https://jslib.k6.io/k6-summary/0.0.2/index.js';
5+
import { htmlReport } from 'https://raw.githubusercontent.com/benc-uk/k6-reporter/main/dist/bundle.js';
46

57
// ---------------------------------------------------------------------------
68
// Configuration
@@ -196,3 +198,19 @@ export function getCustomers({ token }) {
196198

197199
sleep(1);
198200
}
201+
202+
// ---------------------------------------------------------------------------
203+
// Summary: write results to stdout, JSON and HTML after the run
204+
// ---------------------------------------------------------------------------
205+
export function handleSummary(data) {
206+
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
207+
const reportDir = __ENV.REPORT_DIR || 'tests/k6/reports';
208+
const jsonPath = `${reportDir}/customers-${timestamp}.json`;
209+
const htmlPath = `${reportDir}/customers-${timestamp}.html`;
210+
211+
return {
212+
'stdout': textSummary(data, { indent: ' ', enableColors: true }),
213+
[jsonPath]: JSON.stringify(data, null, 2),
214+
[htmlPath]: htmlReport(data, { title: 'Customer Endpoint Performance Report' }),
215+
};
216+
}

0 commit comments

Comments
 (0)