Skip to content

otakmager/k6-be-cms

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

K6 Backend CMS Performance Testing

k6 Node.js

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.

Key Features

  • 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 options configuration.
  • Automated Reporting: Automatically generates visual HTML reports and raw JSON data in the /report folder.
  • Environment Variable Support: Integrated with .env for managing credentials and URLs.
  • Global Checks: Global status code validation (e.g., protection against 5xx errors).

Prerequisites

Before starting, ensure you have the following installed:

  • k6
  • Node.js (to run npm scripts)

Installation

  1. Clone this repository.
  2. Install dependencies (for supporting utilities like dotenv-cli):
    npm install
  3. Duplicate the .env.example file to .env and fill in the variables:
    cp .env.example .env

Environment Configuration

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)

Project Structure

├── 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)

Running Tests

All npm scripts automatically create the report/ folder and generate reports.

1. Running Specific Tests

# 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.js

2. Running k6 Directly

dotenv -- k6 run tests/auth.test.js

Test Reports

After 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)

About

Modular performance testing suite for Backend CMS APIs using k6. Features automated HTML/JSON reporting and support for Load, Stress, Spike, and Soak scenarios

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors