Dummy package for autocompleting k6 scripts.
k6 is an open-source load testing tool designed for modern development workflows. While this npm package serves primarily as a type definition helper for autocompleting k6 scripts in IDEs, k6 itself is a standalone CLI tool (written in Go) that executes performance tests using JavaScript. It allows developers to write test scenarios as code, defining virtual users, request patterns, and acceptance criteria through an embedded JavaScript runtime.
Unlike traditional load testing tools, k6 prioritizes developer experience by enabling version-controlled test scripts, CI/CD integration, and modular test architecture. The JavaScript engine is custom-built (not Node.js), which means excellent resource efficiency—you can generate thousands of virtual users on modest hardware. However, this also means you cannot directly import npm packages without bundling them first using tools like Webpack or Rollup.
k6 is particularly popular among backend and DevOps engineers working in cloud-native environments. It integrates seamlessly with Grafana for metrics visualization, exports results to monitoring platforms like DataDog and Prometheus, and supports Kubernetes deployments. The tool excels at protocol-level testing (HTTP, WebSocket, gRPC) and provides a comprehensive API for checks, thresholds, and grouping to structure complex test scenarios.
The ecosystem includes experimental modules for specialized testing (Redis operations, browser performance via Chrome DevTools Protocol) and extension frameworks (xk6) for custom protocols. The AGPL-3.0 license makes it free for most use cases, with commercial Grafana Cloud k6 offerings for teams needing distributed execution and advanced collaboration features.
import http from 'k6/http';
import { check, group, sleep } from 'k6';
import { Rate } from 'k6/metrics';
const errorRate = new Rate('errors');
export const options = {
stages: [
{ duration: '30s', target: 20 },
{ duration: '1m', target: 50 },
{ duration: '30s', target: 0 }
],
thresholds: {
http_req_duration: ['p(95)<500'],
errors: ['rate<0.1'],
http_req_failed: ['rate<0.05']
}
};
export default function () {
group('API Health Check', () => {
const healthRes = http.get('https://test-api.k6.io/public/crocodiles/');
const success = check(healthRes, {
'status is 200': (r) => r.status === 200,
'response time < 200ms': (r) => r.timings.duration < 200
});
errorRate.add(!success);
});
group('Create Resource', () => {
const payload = JSON.stringify({
name: `Croc-${Date.now()}`,
sex: 'M',
date_of_birth: '2020-01-01'
});
const params = {
headers: { 'Content-Type': 'application/json' }
};
const createRes = http.post('https://test-api.k6.io/public/crocodiles/', payload, params);
check(createRes, {
'created successfully': (r) => r.status === 201,
'has id': (r) => r.json('id') !== undefined
});
});
sleep(1);
}API performance validation in CI/CD pipelines: Run smoke tests on every deployment to catch performance regressions early. Define thresholds for response times and error rates that fail the build if exceeded, ensuring production-ready code reaches main branches.
Microservices stress testing: Simulate realistic traffic patterns across multiple services to identify bottlenecks, race conditions, and cascading failures. Use stages to gradually ramp up load and observe system behavior under increasing pressure.
Spike and soak testing for infrastructure planning: Test how systems handle sudden traffic surges (Black Friday scenarios) or prolonged load over hours to detect memory leaks and resource exhaustion. Configure virtual user patterns that mirror real user behavior.
Third-party API rate limit validation: Verify your application respects external API quotas and handles rate limiting gracefully. Script scenarios with controlled request rates and validate retry logic under throttling conditions.
WebSocket and real-time protocol testing: Load test chat applications, live dashboards, or streaming services using k6's protocol support. Simulate concurrent connections with bidirectional message flows to validate scalability of real-time features.
npm install k6pnpm add k6bun add k6