k6-modern-reporter 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitattributes +2 -0
- package/LICENSE +21 -0
- package/README.md +182 -0
- package/assets/checks.jpeg +0 -0
- package/assets/metrics.jpeg +0 -0
- package/assets/overview.jpeg +0 -0
- package/assets/thresholds.jpeg +0 -0
- package/k6-modern-reporter.js +1291 -0
- package/package.json +28 -0
- package/reports/test-reporter-2026-01-31T16-39-41.613Z.html +847 -0
- package/test-reporter.ts +59 -0
package/test-reporter.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import http from 'k6/http';
|
|
2
|
+
import { check } from 'k6';
|
|
3
|
+
import { htmlReport } from './k6-modern-reporter.js';
|
|
4
|
+
|
|
5
|
+
export const options = {
|
|
6
|
+
scenarios: {
|
|
7
|
+
shared_iteration: {
|
|
8
|
+
executor: 'shared-iterations',
|
|
9
|
+
vus: 20,
|
|
10
|
+
iterations: 100,
|
|
11
|
+
maxDuration: '60s',
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
|
|
15
|
+
// Basic Non-Functional Validations
|
|
16
|
+
/* Thresholds are the pass/fail criteria that you define for your test metrics.
|
|
17
|
+
If the performance of the system under test (SUT) does not meet the conditions of your threshold, the test will finish with a failed status. */
|
|
18
|
+
thresholds: {
|
|
19
|
+
'http_req_failed': ['rate==0.00'], // http errors should be 0%
|
|
20
|
+
'http_req_duration': ['p(95)<1000'], // 95% of requests should be below 1000ms or 1s
|
|
21
|
+
'checks': ['rate==1.00'], // the rate of successful checks should be 100%
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// The default exported function is gonna be picked up by k6 as the entry point for the test script. It will be executed repeatedly in "iterations" for the whole duration of the test.
|
|
26
|
+
export default function () {
|
|
27
|
+
// 80% chance of success vs failure for randomization
|
|
28
|
+
const isSuccess = Math.random() < 0.8;
|
|
29
|
+
|
|
30
|
+
let response: http.Response;
|
|
31
|
+
if (isSuccess) {
|
|
32
|
+
// Successful request
|
|
33
|
+
response = http.get("https://httpbin.org/get");
|
|
34
|
+
} else {
|
|
35
|
+
// Failed request
|
|
36
|
+
response = http.get("https://httpbin.org/status/500");
|
|
37
|
+
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Run checks on the response
|
|
41
|
+
console.log('Response Status: ', response.status);
|
|
42
|
+
|
|
43
|
+
check(response, {
|
|
44
|
+
'Response status 200': (r) => r.status === 200,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
if (response.status !== 200) {
|
|
48
|
+
console.error('Error Response Body: ', response.body);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function handleSummary(data: any) {
|
|
54
|
+
const currentFileName = __ENV.K6_SCRIPT_NAME || 'test-reporter';
|
|
55
|
+
const reportFileName = `./reports/${currentFileName}-${new Date().toJSON().split(':').join('-')}.html`;
|
|
56
|
+
return {
|
|
57
|
+
[reportFileName]: htmlReport(data)
|
|
58
|
+
};
|
|
59
|
+
}
|