# handleSummary in k6
[k6 docs](https://k6.io/docs/results-visualization/end-of-test-summary/)
In [[k6 (tool)|k6]], the `handleSummary()` function can be used to modify or add to the end-of-test summary of results that is displayed by k6 after executing a test.
## The default end-of-test summary
The default output of k6 at the end of a test follows below:
```bash
nic@sopirulino k6 % ./k6 run pokeapi.js
]
/\ |‾‾| /‾‾/ /‾‾/
/\ / \ | |/ / / /
/ \/ \ | ( / ‾‾\
/ \ | |\ \ | (‾) |
/ __________ \ |__| \__\ \_____/ .io
execution: local
script: pokeapi.js
output: -
scenarios: (100.00%) 2 scenarios, 3 max VUs, 11m30s max duration (incl. graceful stop):
* pokeapi: Up to 2 looping VUs for 3m0s over 1 stages (gracefulRampDown: 1m0s, exec: catchEmAll, gracefulStop: 30s)
* chaos: 1 iterations for each of 1 VUs (maxDuration: 10m0s, exec: killPod, startTime: 1m0s, gracefulStop: 30s)
running (03m04.4s), 0/3 VUs, 17 complete and 0 interrupted iterations
pokeapi ✓ [======================================] 0/2 VUs 3m0s
chaos ✓ [======================================] 1 VUs 00m04.9s/10m0s 1/1 iters, 1 per VU
✗ is status 200
↳ 93% — ✓ 15 / ✗ 1
✗ 01-text verification
↳ 93% — ✓ 15 / ✗ 1
checks.........................: 93.75% ✓ 30 ✗ 2
data_received..................: 2.2 MB 12 kB/s
data_sent......................: 4.9 kB 26 B/s
http_req_blocked...............: avg=161.59ms min=3µs med=9µs max=5.17s p(90)=13.8µs p(95)=14.45µs
http_req_connecting............: avg=1.07ms min=0s med=0s max=34.37ms p(90)=0s p(95)=0s
http_req_duration..............: avg=480.08ms min=36.86ms med=91.3ms max=2.11s p(90)=1.24s p(95)=1.79s
{ expected_response:true }...: avg=493.84ms min=36.86ms med=94.61ms max=2.11s p(90)=1.24s p(95)=1.79s
✓ http_req_failed................: 3.12% ✓ 1 ✗ 31
http_req_receiving.............: avg=86.46ms min=63µs med=181.5µs max=441.84ms p(90)=314.34ms p(95)=337.32ms
http_req_sending...............: avg=47.18µs min=13µs med=44.5µs max=134µs p(90)=67.9µs p(95)=79.7µs
http_req_tls_handshaking.......: avg=0s min=0s med=0s max=0s p(90)=0s p(95)=0s
http_req_waiting...............: avg=393.57ms min=36.72ms med=91.09ms max=1.67s p(90)=1.13s p(95)=1.46s
http_reqs......................: 32 0.17356/s
iteration_duration.............: avg=5.84s min=2.16s med=5.73s max=11.01s p(90)=7.55s p(95)=8.45s
iterations.....................: 17 0.092204/s
vus............................: 1 min=0 max=2
vus_max........................: 3 min=3 max=3
```
All parts of this can be changed using `handleSummary()`.
## Creating a new handleSummary
If `handleSummary()` does not exist, k6 uses the default format. Exporting a `handleSummary()` function overwrites the default. Within the function, you can specify your own code that transforms the metrics displayed or outputs results in other or multiple formats.
However, the [[k6 jslib]] repo also includes some functions for use with `handleSummary()`, including [one created by k6 developer Ned Andreev](https://jslib.k6.io/k6-summary/0.0.1/index.js). To use a function from jslib, you first need to import it:
`import {textSummary } from 'https://jslib.k6.io/k6-summary/0.0.1/index.js';`
Then, use it in the script like this:
```js
export function handleSummary(data) {
return {
'stdout': textSummary(data, { indent: ' ', enableColors: true}),
};
}
```
### Considerations for changing the end-of-test summary
Each [[Number of virtual users|virtual user]] in [[k6 (tool)|k6]] has its own runtime, so there is no way to set a variable in one of them and be able to access it in `handleSummary()`, which is like its own separate VU.
If you need to do access a variable in the summary, you have a few options:
- Write the variable value to a database
- Create a k6 extension that will store the variable
- Modify k6 and attempt to make a PR