This repository provides the initial structure of the k6 project with using TypeScript and is based in the template of GrafanaLabs. For more details about this template (used typescript in K6 scripts) access the page of template.
Clone this repository on your local machine and install the prerequisites and dependencies (defined in package.json
)
$ npm install
or using yarn
$ yarn install
# installed by npm
$ .\node_modules\yarn\bin\yarn webpack
To run a test written in TypeScript, we first have to transpile the TypeScript code into JavaScript and bundle the project
$ npm run start
or using Yarn
$ yarn webpack
# can be necessary set the path of node_modules to yarn
$.\node_modules\yarn\bin\yarn webpack
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/script.js
In branch sample have exemplos od k6 script ( based on template), but was modifications for use only one script to centric the suite of performance tests. In k6 project was open issue about these topic "Why use k6 to run multiple scripts together".
House rules for writing tests:
- The test code is located in
src
folder - The entry points for the tests need to have extention ".ts". You can change the entry here.
- If static files are required then add them to
./assets
folder. Its content gets copied to the destination folder (dist
) along with compiled scripts.
By default, k6 can only run ES5.1 JavaScript code. To use TypeScript, we have to set up a bundler that converts TypeScript to JavaScript code.
This project uses Babel
and Webpack
to bundle the different files - using the configuration of the webpack.config.js
file.
If you want to learn more, check out Bundling node modules in k6.