Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@bryanlarsen/har-to-k6

loadimpact15Apache-2.00.5.2TypeScript support: included

Convert LI-HAR to k6 script

k6, har, li-har, loadtest, load-test, load-testing, server-load, performance

readme

har-to-k6 cover image

har-to-k6

Converts LI-HAR and HAR to K6 script.

GitHub Actions Status NPM Version NPM Weekly Downloads DockerHub



Content

Installation

While possible to install globally, we recommend that you, if possible, add the converter to the node_modules of your test project using:

$ npm install --save har-to-k6

Note that this will require you to run the converter with npx har-to-k6 your-har-file or, if you are using an older version of npm, ./node_modules/.bin/har-to-k6 your-har-file`.

Global Installation

$ npm install --global har-to-k6

Docker

$ docker pull loadimpact/har-to-k6:latest

Usage

CLI Usage

Npx

$ npx har-to-k6 archive.har -o my-k6-script.js

From node_modules

$ ./node_modules/.bin/har-to-k6 archive.har -o my-k6-script.js

Global

$ har-to-k6 archive.tar -o my-k6-script.js

Programmatic Usage

Converting

const fs = require("fs");
const { liHARToK6Script } = require("har-to-k6");

async function run () {
  const archive = readArchive();
  const { main } = await liHARToK6Script(archive);
  fs.writeFileSync("./load-test.js", main);
}

Validating

Use validate() to run validation alone. Returns without error for a valid archive. Throws InvalidArchiveError for validation failure.

const { InvalidArchiveError, validate } = require("har-to-k6");

const archive = readArchive();
try {
  validate(archive);
} catch (error) {
  if (error instanceof InvalidArchiveError) {
    // Handle invalid archive
  } else {
    throw error;
  }
}

Browser Usage

har-to-k6 can be ran in the browser. This exposes the standard API under harToK6.

Importing as ES module

import { liHARToK6Script } from "har-to-k6";

CommonJS style

const { liHARToK6Script } = require("har-to-k6");

Using a <script> tag

Load standalone.js into your HTML page:

<html>
  <head>
    <title>HAR Converter</title>
    <script src="standalone.js"></script>
    <script src="index.js"></script>
  </head>
</html>

Example

The API is available:

async function run () {
    const archive = readArchive();
    harToK6.validate(archive);
    const { main } = await harToK6.liHARToK6Script(archive);
    displayResult(main);
}

Specifications

Credits

Thanks to bookmoons for creating this tool 🎉

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

Unreleased

0.3.3 - 2020-06-08

Fixed

  • Set engine node >= 11.0.0

0.3.2 - 2020-06-05

Fixed

  • Empty name queryString item throws validation error.
  • Make cookie validation less strict.

0.3.1 - 2020-05-28

Fixed

  • Variables not being resolved in correct order

0.3.0 - 2020-04-03

Added

  • Support fixed cases of multipart/form-data

Fixed

  • Empty postData param value causes converter crash

0.2.0 - 2020-03-13

Changed

  • Less strict validation for postData
  • Prioritize postData.params over postData.text

Added

  • Run babel on standalone bundle

0.1.5 - 2020-02-17

Fixed

  • Remove pseudo headers
  • Remove cookies
  • Remove Content-Length header

0.1.4 - 2020-02-05

Fixed

  • Allow charset in postData mimeType
  • Use both id and title for group name

0.1.3 - 2019-08-05

Changed

Start using scheme for jslib module imports.

0.1.2 - 2019-07-10

Fixed

Missing sleep import.

0.1.1 - 2019-07-09

Added

  • add CHANGELOG

Fixed

Broken positional arg in caporal resulting in broken har-to-k6 command.

0.1.0 - 2019-07-09

Added

  • Initial release