Skip to content

Latest commit

 

History

History
65 lines (50 loc) · 1.59 KB

cli-tool.spec.md

File metadata and controls

65 lines (50 loc) · 1.59 KB

LI-HAR to K6 CLI tool

A Node.js CLI tool exposing an interface for converting a LI-HAR config to a K6 script.

Requirements

  • The CLI tool should be installable and runnable in Node.js (current LTS release) on OS X, Windows and Linux.
  • The CLI tool should utilise the LI-HAR converter package.

Naive implementation

// har-to-k6 CLI tool
const fs = require("fs-extra");
const yargs = require("yargs");
const { liHARToK6Script } = require("har-to-k6");

const argv = yargs
  .usage("har-to-k6 <har-file>")
  .usage("har-to-k6 <har-file> -o <k6-file>")
  .option("out", {
    alias: "o",
    describe: "Output file",
    type: "string"
  }).argv;

function exit() {
  yargs.showHelp();
  process.exit(1);
}

const input = argv._[0] || exit();
const output = argv.out;

if (output) {
  const har = fs.readFileSync(input, { encoding: "utf8" });
  fs.outputFileSync(`${output}/test.js`, liHARToK6Script(har));
  console.log("Success");
} else {
  console.log("Please specify output file name");
}
# Usage

$ har-to-k6

har-to-k6 <har-file>
har-to-k6 <har-file> -o <k6-file>

Options:
  --help     Show help                                                 [boolean]
  --version  Show version number                                       [boolean]
  --out, -o  Output file                                                [string]
$ har-to-k6 myharfile.har -o myk6script.js

Resources