Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/grafana/k6-template-es6
Template using Webpack and Babel to enable ES6 features in k6 tests
https://github.com/grafana/k6-template-es6
babel bundling es6 javascript k6 load-testing performance-testing templates webpack
Last synced: 27 days ago
JSON representation
Template using Webpack and Babel to enable ES6 features in k6 tests
- Host: GitHub
- URL: https://github.com/grafana/k6-template-es6
- Owner: grafana
- License: apache-2.0
- Created: 2020-03-27T11:37:41.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-01-26T17:35:19.000Z (9 months ago)
- Last Synced: 2024-04-14T09:15:29.722Z (7 months ago)
- Topics: babel, bundling, es6, javascript, k6, load-testing, performance-testing, templates, webpack
- Language: JavaScript
- Homepage: https://k6.io/docs/using-k6/modules#bundling-node-modules
- Size: 55.7 KB
- Stars: 78
- Watchers: 128
- Forks: 21
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-k6 - k6-template-es6 - Starter template using Webpack and Babel to enable ES6 features in k6 tests. (Examples/Templates)
README
> [!WARNING]
> This template is deprecated due to native ES6+TypeScript support released in k6 [v0.52.0](https://github.com/grafana/k6/releases/tag/v0.52.0). Set the `--compatibility-mode=experimental_enhanced` option to use it. Check the [documentation for the details](https://grafana.com/docs/k6/latest/using-k6/javascript-typescript-compatibility-mode/#experimental-enhanced-mode).This is a template repository showing how to use `Babel` and `Webpack` to bundle the different files into CommonJS modules, using its [`webpack.config.js`](./webpack.config.js) configuration.
In this project, you can write k6 tests using:
1. node module resolution.
2. external node modules and getting them automatically bundled.
3. unsupported ES+ features like the optional chaining ( `?.` ) operator.## Installation
Click **Use this template** to create a repository from this template.
Clone the generated repository on your local machine, move to the project root folder and install the dependencies defined in [`package.json`](./package.json)
```bash
npm install
```## Running the test
Attempting to run the tests in [src](./src/) will fail because:
- k6 does not know how to resolve node modules.
- k6 does not recognize some ES+ features like the optional chaining ( `?.` ) operator.To address this, we'll use `Webpack` to bundle the dependencies and polyfill ES+ features.
```bash
npm run 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:
```bash
k6 run dist/optional-chaining-test.js
# or
k6 run dist/faker-test.js
```## See also
- [Using k6 / Modules](https://grafana.com/docs/k6/latest/using-k6/modules/)
- [Using k6 / JavaScript compatibility mode](https://grafana.com/docs/k6/latest/using-k6/javascript-compatibility-mode/)
- [grafana/k6-rollup-example](https://github.com/grafana/k6-rollup-example)
- [grafana/k6-template-typescript](https://github.com/grafana/k6-template-typescript)