A comprehensive and modular performance testing suite for Backend CMS APIs built with k6. This project supports realistic load testing, stress testing, spike testing, and soak testing with automated HTML and JSON reporting.
- Modular Scripting: Clear separation of request logic (
lib), configurations (config), and utilities (utils). - Multiple Test Scenarios: Support for Load, Stress, Spike, and Soak testing via
optionsconfiguration. - Automated Reporting: Automatically generates visual HTML reports and raw JSON data in the
/reportfolder. - Environment Variable Support: Integrated with
.envfor managing credentials and URLs. - Global Checks: Global status code validation (e.g., protection against 5xx errors).
Before starting, ensure you have the following installed:
- k6
- Node.js (to run npm scripts)
- Clone this repository.
- Install dependencies (for supporting utilities like
dotenv-cli):npm install
- Duplicate the
.env.examplefile to.envand fill in the variables:cp .env.example .env
Edit your .env file with the appropriate values:
| Variable | Description |
|---|---|
BASE_URL |
API Base URL (e.g., http://localhost:3000) |
ADMIN_SECRET_KEY |
Key for accessing admin statistics endpoints |
TOKEN |
Bearer token for testing protected endpoints |
TYPE |
Default test type (load, stress, spike, soak) |
├── report/ # Report output (HTML & JSON)
├── src/
│ ├── config/ # k6 configuration (options, global checks)
│ ├── lib/ # API request modules (auth, contact, home, etc.)
│ └── utils/ # Constants and reporter helpers
├── tests/ # Main test entry files
└── .env # Environment file (sensitive)
All npm scripts automatically create the report/ folder and generate reports.
# Load Test (Normal load)
npm run k6-load tests/auth.test.js
# Stress Test (Finding system limits)
npm run k6-stress tests/contact.test.js
# Spike Test (Sudden traffic surge)
npm run k6-spike tests/home.test.js
# Soak Test (Long-term endurance test)
npm run k6-soak tests/stats.test.jsdotenv -- k6 run tests/auth.test.jsAfter each test run, reports are saved in the /report folder:
- HTML Report:
report/summary.html— Interactive visual report (open in browser). - JSON Report:
report/summary.json— Raw data for analysis.
Key Metrics:
- Response time (
http_req_duration) - Failure rate (
http_req_failed) - Checks pass rate
- Requests per second (RPS)
- Virtual Users (VUs)