{"id":16323742,"url":"https://github.com/shavo007/k6-demo","last_synced_at":"2025-06-23T19:35:14.914Z","repository":{"id":38625161,"uuid":"360389583","full_name":"shavo007/k6-demo","owner":"shavo007","description":"demo perf tests using k6 and OAS (open api spec)","archived":false,"fork":false,"pushed_at":"2025-05-07T09:23:15.000Z","size":4387,"stargazers_count":8,"open_issues_count":16,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-05-07T10:33:59.752Z","etag":null,"topics":["docker","grafana","k6","openapi","openapi3","performance-testing","swagger","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shavo007.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-04-22T04:16:45.000Z","updated_at":"2024-10-26T10:12:24.000Z","dependencies_parsed_at":"2024-10-27T10:55:11.644Z","dependency_job_id":"c01b5727-f71e-4585-aba5-fd3d7315d6a1","html_url":"https://github.com/shavo007/k6-demo","commit_stats":null,"previous_names":[],"tags_count":0,"template":true,"template_full_name":null,"purl":"pkg:github/shavo007/k6-demo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shavo007%2Fk6-demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shavo007%2Fk6-demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shavo007%2Fk6-demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shavo007%2Fk6-demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shavo007","download_url":"https://codeload.github.com/shavo007/k6-demo/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shavo007%2Fk6-demo/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261543724,"owners_count":23174795,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","grafana","k6","openapi","openapi3","performance-testing","swagger","typescript"],"created_at":"2024-10-10T22:55:32.974Z","updated_at":"2025-06-23T19:35:14.868Z","avatar_url":"https://github.com/shavo007.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TypeScript with k6\n\n![banner](assets/ts-js-k6.png)\n\nhttps://blog.shanelee.name/2021/12/15/performance-testing-with-k6/\n\nThis repository showcases k6 with typescript and generating boilerplate scripts from your OAS (Open API Spec). k6 recently outlined in thoughtworks [tech radar](https://www.thoughtworks.com/radar/tools?blipid=202010078) tools quadrant.\n\n![.github/workflows/push.yml](https://github.com/shavo007/k6-demo/workflows/.github/workflows/push.yml/badge.svg?branch=main)\n![GitHub top language](https://img.shields.io/github/languages/top/shavo007/k6-demo)\n\n- [TypeScript with k6](#typescript-with-k6)\n  - [Prerequisites](#prerequisites)\n  - [Installation](#installation)\n    - [Install dependencies](#install-dependencies)\n  - [Usage/Examples](#usageexamples)\n    - [Running the test](#running-the-test)\n    - [OAS integration](#oas-integration)\n      - [Test running against the API](#test-running-against-the-api)\n    - [OAuth2 integration](#oauth2-integration)\n    - [Load testing with influxdb and grafana](#load-testing-with-influxdb-and-grafana)\n  - [Resources](#resources)\n  - [TODO](#todo)\n\n## Prerequisites\n\n- [k6](https://k6.io/docs/getting-started/installation)\n- [NodeJS](https://nodejs.org/en/download/)\n- [Yarn](https://yarnpkg.com/getting-started/install)\n- [Docker](https://docs.docker.com/get-docker/)\n\n## Installation\n\n### Install dependencies\n\nClone the generated repository on your local machine, move to the project root folder and install the dependencies defined in [`package.json`](./package.json)\n\n```bash\nyarn\n```\n\n## Usage/Examples\n\n### Running the test\n\nTo run a test written in TypeScript, we first have to transpile the TypeScript code into JavaScript and bundle the project\n\n```bash\nyarn bundle\n```\n\nThis command creates the final test files to the `./dist` folder.\n\nOnce that is done, we can run our script the same way we usually do, for instance:\n\n```bash\nk6 run dist/test1.js\n```\n\n### OAS integration\n\n\u003e Showcase gen k6 script from OAS (Open API Spec)\n\nGenerate k6s scripts via [open api generator](https://openapi-generator.tech/docs/generators/#client-generators) and the [oas file](oas3.yaml). Can run the CLI via the docker image.\n\n```bash\ndocker pull openapitools/openapi-generator-cli\n\ndocker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli generate \\\n    -i /local/oas3.yaml \\\n    -g k6 \\\n    -o /local/k6-oas3/ \\\n    --skip-validate-spec\n\n```\n\nThis generates [script.js](./k6-oas3/script.js) and is a great start to help support defining your perf test cases.\n\n**NB** It is boilerplate so will need to be refined after for re-use\n\nThis 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.\n\n#### Test running against the API\n\n```bash\ndocker run -d -p8090:8081 shanelee007/greetings-api:latest #run greetings API\nyarn bundle\nk6 run -e ENV=local dist/greetings.js\nyarn html #generate a html report\n```\n\n### OAuth2 integration\n\n\u003e Showcase gen types from open api generator and k6 scripts for [bpay API](./bpay/oas3.yaml)\n\n- Generate typescript client sdk (for types)\n- Generate k6 scripts from OAS\n\n```bash\n# gen client sdk from OAS using generator typescript\ndocker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli generate \\\n    -i /local/bpay/oas3.yaml \\\n    -g typescript \\\n    -o /local/bpay/bpay-client/ \\\n    --additional-properties=supportsES6=true,platform=node \\\n    --skip-validate-spec\n\n# OR generate types from OAS via openapi-typescript\nnpx openapi-typescript bpay/oas3.yaml --output bpay/types/schema.ts\nnpx openapi-typescript bpay/oas3.yaml --output src/bpay/schema.ts\n\n# gen k6 scripts\ndocker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli generate \\\n    -i /local/bpay/oas3.yaml \\\n    -g k6 \\\n    -o /local/bpay/k6/ \\\n    --skip-validate-spec\n\n#run load test against bpay api\nyarn bundle\nCLIENT_ID=REDACTED CLIENT_SECRET=REDACTED k6 run dist/bpay.js\n```\n\n### Load testing with influxdb and grafana\n\n```bash\ndocker compose up -d #run the services in the background\ndocker-compose run -v \\\n    $PWD/dist:/scripts \\\n    k6 run -e ENV=docker  /scripts/greetings.js\n\n```\n\nAccess 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\n\n![Grafana dashboard](./assets/grafana.png)\n\n## Resources\n\n- [k6 and oas](https://k6.io/blog/load-testing-your-api-with-swagger-openapi-and-k6/)\n- [k6 vs jmeter](https://k6.io/blog/k6-vs-jmeter/)\n- [prettier pre-commit](https://prettier.io/docs/en/precommit.html)\n\n## TODO\n\n- raise issue on stdout chars\n- showcase browser recorder\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshavo007%2Fk6-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshavo007%2Fk6-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshavo007%2Fk6-demo/lists"}