Git Product home page Git Product logo

k6-template-typescript's Introduction

banner

Template to use TypeScript with k6

.github/workflows/push.yml

This repository provides a scaffolding project to start using TypeScript in your k6 scripts.

Rationale

While JavaScript is great for a myriad of reasons, one area where it fall short is type safety and developer ergonomics. It's perfectly possible to write JavaScript code that will look OK and behave OK until a certain condition forces the executor into a faulty branch.

While it, of course, still is possible to shoot yourself in the foot with TypeScript as well, it's significantly harder. Without adding much overhead, TypeScript will:

  • Improve the ability to safely refactor your code.
  • Improve readability and maintainability.
  • Allow you to drop a lot of the defensive code previously needed to make sure consumers are calling functions properly.

Prerequisites

Installation

Creating a project from the template-typescript template

To generate a TypeScript project that includes the dependencies and initial configuration, navigate to the template-typescript page and click Use this template.

Install dependencies

Clone the generated repository on your local machine, move to the project root folder and install the dependencies defined in package.json

$ yarn install

Running the test

To run a test written in TypeScript, we first have to transpile the TypeScript code into JavaScript and bundle the project

$ 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/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.
  • 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.

k6-template-typescript's People

Contributors

ppcano avatar dependabot[bot] avatar simskij avatar shavo007 avatar aklaus avatar mstoykov avatar pexa-slee avatar hinatades avatar awls99 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.