Skip to content

Commit

Permalink
Readme do not recommend compatibility-mode=base
Browse files Browse the repository at this point in the history
  • Loading branch information
ppcano committed Jan 26, 2024
1 parent 32eb6c7 commit 2c73a68
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 21 deletions.
25 changes: 5 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ npm install

## Running the test

To run a test written in TypeScript, we first have to transpile the TypeScript code into JavaScript running the bundler:
To run a test written in TypeScript, we first have to transpile the TypeScript code into JavaScript running a bundler. This project uses `Babel` and `Webpack` to bundle the different files into ES modules (ESM), using its [`webpack.config.js`](./webpack.config.js) configuration.

The next command transforms each TypeScript test in `./src` to the `./dist` folder as ES modules.

```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
Expand All @@ -58,24 +58,9 @@ k6 run dist/get-200-status-test.js

By default, k6 does not support TypeScript, but it supports ES modules and ES5.1 code with CommonJS modules. To use TypeScript, we have to set up a bundler that converts TypeScript to any of these formats.

This project uses `Babel` and `Webpack` to bundle the different files into CommonJS modules, using its [`webpack.config.js`](./webpack.config.js) configuration.

The bundled tests will be transpiled to ES5.1 code with CommonJS modules, this allows running the tests with [`--compatibility-mode=base`](https://grafana.com/docs/k6/latest/using-k6/javascript-compatibility-mode/) for better performance:

```bash
k6 run --compatibility-mode=base dist/get-200-status-test.js
```

## 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 "_test_" word in the name to distinguish them from auxiliary files. You can change the entry [here](./webpack.config.js#L8).
- If static files are required then add them to `./assets` folder. Its content gets copied to the destination folder (`dist`) along with compiled scripts.


**Learn more**

- [k6 Docs: working with modules](https://grafana.com/docs/k6/latest/using-k6/modules/)
- [JavaScript Compatibility Mode](https://grafana.com/docs/k6/latest/using-k6/javascript-compatibility-mode/)
- [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)
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "typescript",
"version": "1.0.0",
"main": "index.js",
"repository": "ssh://[email protected]/k6io/example-typescript.git",
"author": "Simon Aronsson <[email protected]>",
"engines": {
Expand Down

0 comments on commit 2c73a68

Please sign in to comment.