Core k6 module with test utilities and assertion functions
The k6 module contains k6-specific functionality for writing load tests. This is the core module that provides essential functions like checks, groups, and sleep.
Returns true if all checks have succeeded, false otherwise.
import http from 'k6/http';import { check } from 'k6';export default function () { const res = http.get('https://quickpizza.grafana.com/'); check(res, { 'response code was 200': (res) => res.status == 200, });}
Checks are not asserts. A failed assertion throws an error, while a check always returns with a pass or failure. Use thresholds to control failure conditions.
import http from 'k6/http';import { check, fail } from 'k6';export default function () { const res = http.get('https://k6.io'); if ( !check(res, { 'status code MUST be 200': (res) => res.status == 200, }) ) { fail('status code was *not* 200'); }}
fail() does not abort the test or exit with non-0 status. It only aborts the current iteration. To halt test execution, use test.abort() from k6/execution.
import { sleep } from 'k6';import http from 'k6/http';export default function () { http.get('https://k6.io'); sleep(Math.random() * 30); http.get('https://k6.io/features');}
Don’t use sleep with async code like promises or event handlers. sleep blocks VU execution and prevents the event loop from processing. Use setTimeout from k6/timers for async code instead.