diff --git a/README.md b/README.md index 2ace5b1..2aed985 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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) \ No newline at end of file diff --git a/package.json b/package.json index da25945..9513def 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,6 @@ { "name": "typescript", "version": "1.0.0", - "main": "index.js", "repository": "ssh://git@github.com/k6io/example-typescript.git", "author": "Simon Aronsson ", "engines": {