1freitas / perfTests

Testes de performance template K6

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

banner

Exemple to use K6 with TypeScript

Sample k6-action Sample K6 Side by Side

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.

Installation

Clone this repository on your local machine and install the prerequisites and dependencies (defined in package.json)

Prerequisites

Install dependencies

$ npm install

or using yarn

$ yarn install
# installed by npm
$ .\node_modules\yarn\bin\yarn webpack

Running the test

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

Samples

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".

Writing own tests

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.

Transpiling and Bundling

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.

About

Testes de performance template K6


Languages

Language:TypeScript 64.4%Language:JavaScript 35.6%