<div align="center">
<h1 style="width: 100%; text-align: center">Elixir-K6</h1>
<p style="font-size: 18px; white-space: pre-line">Quick and painless load testing for Elixir applications.
Generate and run load tests via a local installation of <a href="https://k6.io">k6</a>.
</p>
<p>
Originally developed at <a href="https://spawnfest.org/">SpawnFest</a> 2021.
</p>
</div>
<div align="center" style="text-align: center;">
<img alt="Hex.pm" src="https://img.shields.io/hexpm/l/k6">
<img alt="GitHub Workflow Status" src="https://img.shields.io/github/actions/workflow/status/besughi/elixir-k6/ci.yml?branch=main">
<img alt="Hex.pm" src="https://img.shields.io/hexpm/v/k6">
</div>
## Installation
The package can be installed by adding `k6` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:k6, "~> 0.2.1"}
]
end
```
## Usage
To generate new k6 tests run:
```shell
mix k6.gen.test <test_name>
```
By default k6 tests will be placed under the `priv/k6` directory of your project.
The template to use for the test can be set via the `--type` argument.
Supported types are `rest` (default), `graphql`, `grpc`, `websocket`, `phoenix-channel` (experimental) and `liveview` (experimental).
Run `mix help k6.gen.test` for more info on generating tests.
To execute k6 tests run:
```shell
mix k6 run <test_name>.js
```
Run `mix help k6` for more info on running k6.
### Configuration
`elixir-k6` can be configured via `config.exs` as follows:
```elixir
config :k6,
version: "vX.Y.Z",
env: [VAR_KEY: "some value"],
workdir: "priv/my_load_tests_dir"
```
The supported configuration parameters are:
- `version`: the desired version of k6. Defaults to `v0.39.0`.
- `env`: environment variables to pass to load tests. K6 will expose those variables to load test scripts within the `__ENV` object.
- `workdir`: path of the directory that contains k6 load tests. Relative to the project, defaults to `priv/k6`.
### K6 installation
K6 is automatically installed the first time you run k6 tests, and it is stored in `_build/k6`.
In case you want to explicitly install it before running any test, you can run `mix k6.install`.
At the moment the following architectures are supported:
| OS | Architecture |
| :---: | :----------------: |
| MacOs | amd64 |
| MacOs | arm64 (not tested) |
| Linux | amd64 |
| Linux | arm64 (not tested) |
By default the installation task will install k6 version `v0.39.0`.
You can override this in your config file, as documented above.
## Contributing
Issues and contributions are welcome!
To run static analysis run:
```shell
mix check
```
To execute tests run:
```shell
mix test
```
The test suite also includes some end-to-end tests, which are not executed by default as they are much slower.
To execute all tests run:
```shell
mix test --include end_to_end
```