Skip to content


Repository files navigation

TypeScript with k6


This repository showcases k6 with typescript and generating boilerplate scripts from your OAS (Open API Spec). k6 recently outlined in thoughtworks tech radar tools quadrant.

.github/workflows/push.yml GitHub top language



Install dependencies

Clone the generated repository on your local machine, move to the project root folder and install the dependencies defined in package.json



Running the test

To run a test written in TypeScript, we first have to transpile the TypeScript code into JavaScript and bundle the project

yarn bundle

This command creates the final test files to the ./dist folder.

Once that is done, we can run our script the same way we usually do, for instance:

k6 run dist/test1.js

OAS integration

Showcase gen k6 script from OAS (Open API Spec)

Generate k6s scripts via open api generator and the oas file. Can run the CLI via the docker image.

docker pull openapitools/openapi-generator-cli

docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli generate \
    -i /local/oas3.yaml \
    -g k6 \
    -o /local/k6-oas3/ \

This generates script.js and is a great start to help support defining your perf test cases.

NB It is boilerplate so will need to be refined after for re-use

This auto-generation of the load test script will help streamline the API testing process, keeping on par with the latest changes to their APIs and specifications.

Test running against the API

docker run -d -p8090:8081 shanelee007/greetings-api:latest #run greetings API
yarn bundle
k6 run -e ENV=local dist/greetings.js
yarn html #generate a html report

OAuth2 integration

Showcase gen types from open api generator and k6 scripts for bpay API

  • Generate typescript client sdk (for types)
  • Generate k6 scripts from OAS
# gen client sdk from OAS using generator typescript
docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli generate \
    -i /local/bpay/oas3.yaml \
    -g typescript \
    -o /local/bpay/bpay-client/ \
    --additional-properties=supportsES6=true,platform=node \

# OR generate types from OAS via openapi-typescript
npx openapi-typescript bpay/oas3.yaml --output bpay/types/schema.ts
npx openapi-typescript bpay/oas3.yaml --output src/bpay/schema.ts

# gen k6 scripts
docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli generate \
    -i /local/bpay/oas3.yaml \
    -g k6 \
    -o /local/bpay/k6/ \

#run load test against bpay api
yarn bundle

Load testing with influxdb and grafana

docker compose up -d #run the services in the background
docker-compose run -v \
    $PWD/dist:/scripts \
    k6 run -e ENV=docker  /scripts/greetings.js

Access grafana: open http://localhost:3000 and verify connection to influxdb datasource. Access the pre-defined dashboard and set interval to the past 5 mins. You should see similar outline to below

Grafana dashboard



  • raise issue on stdout chars
  • showcase browser recorder