{"id":13651613,"url":"https://github.com/Mattihew/k6-to-junit","last_synced_at":"2025-04-22T22:31:39.134Z","repository":{"id":55076828,"uuid":"199381057","full_name":"Mattihew/k6-to-junit","owner":"Mattihew","description":"tool to convert k6 output to junit xml","archived":false,"fork":false,"pushed_at":"2023-10-19T20:31:56.000Z","size":483,"stargazers_count":21,"open_issues_count":9,"forks_count":7,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-14T12:26:58.215Z","etag":null,"topics":["junit","junit-xml","k6"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Mattihew.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-07-29T04:58:30.000Z","updated_at":"2025-04-11T20:14:17.000Z","dependencies_parsed_at":"2024-01-03T05:40:31.895Z","dependency_job_id":"7d94ad16-d6bd-4ccc-9f67-ed2f45989e5d","html_url":"https://github.com/Mattihew/k6-to-junit","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mattihew%2Fk6-to-junit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mattihew%2Fk6-to-junit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mattihew%2Fk6-to-junit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mattihew%2Fk6-to-junit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Mattihew","download_url":"https://codeload.github.com/Mattihew/k6-to-junit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250333972,"owners_count":21413487,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["junit","junit-xml","k6"],"created_at":"2024-08-02T02:00:50.947Z","updated_at":"2025-04-22T22:31:38.821Z","avatar_url":"https://github.com/Mattihew.png","language":"TypeScript","funding_links":[],"categories":["Tools"],"sub_categories":[],"readme":"# k6-to-junit\n\n![https://www.npmjs.com/package/k6-to-junit](https://img.shields.io/npm/v/k6-to-junit?style=plastic) ![https://github.com/Mattihew/k6-to-junit](https://img.shields.io/github/v/release/mattihew/k6-to-junit?label=github\u0026style=plastic)\n\n## Description\n\nk6-to-junit is a simple command line utility to convert the stdout of k6 tests into a junit xml format ready to be used for ci tools such as jenkins.\n\nCurrently this just works by looking for thresholds in the output and creating a testcase for each threshold in the output xml file.\n\nGiven the following output the below xml file will be created\n\n```properties\n\n          /\\      |‾‾|  /‾‾/  /‾/   \n     /\\  /  \\     |  |_/  /  / /    \n    /  \\/    \\    |      |  /  ‾‾\\  \n   /          \\   |  |‾\\  \\ | (_) | \n  / __________ \\  |__|  \\__\\ \\___/ .io\n\n  execution: local\n     output: json=k6/exampleResults.json\n     script: /k6/test/example.k6.js\n\n    duration: -, iterations: 20\n         vus: 1, max: 1\n\n    ✗ is status 200\n     ↳  50% — ✓ 10 / ✗ 10\n    ✗ not empty\n     ↳  50% — ✓ 10 / ✗ 10\n\n  ✓ checks.....................: 50.00% ✓ 20  ✗ 20 \n    data_received..............: 18 kB  29 kB/s\n    data_sent..................: 2.0 kB 3.2 kB/s\n  ✗ errors.....................: 50.00% ✓ 10  ✗ 10 \n    http_req_blocked...........: avg=1.29ms  min=2.4µs   med=3.45µs  max=25.87ms p(90)=4.52µs  p(95)=1.29ms \n    http_req_connecting........: avg=1.19ms  min=0s      med=0s      max=23.98ms p(90)=0s      p(95)=1.19ms \n    http_req_duration..........: avg=30.69ms min=26.53ms med=28.75ms max=44.37ms p(90)=35.74ms p(95)=41.02ms\n    http_req_receiving.........: avg=47.19µs min=27µs    med=43.3µs  max=92.6µs  p(90)=58.72µs p(95)=64µs   \n    http_req_sending...........: avg=17.44µs min=8.9µs   med=11.8µs  max=103.6µs p(90)=17.49µs p(95)=39.66µs\n    http_req_tls_handshaking...: avg=0s      min=0s      med=0s      max=0s      p(90)=0s      p(95)=0s     \n    http_req_waiting...........: avg=30.63ms min=26.47ms med=28.69ms max=44.17ms p(90)=35.68ms p(95)=40.94ms\n    http_reqs..................: 20     31.052819/s\n    iteration_duration.........: avg=32.19ms min=26.75ms med=28.97ms max=70.59ms p(90)=35.96ms p(95)=42.54ms\n    iterations.................: 20     31.052819/s\n    vus........................: 1      min=1 max=1\n    vus_max....................: 1      min=1 max=1\n\n```\n\n```xml\n\u003c?xml version=\"1.0\"?\u003e\n\u003ctestsuites tests=\"2\" failures=\"1\" time=\"0.839\"\u003e\n  \u003ctestsuite name=\"/k6/test/example.k6.js\" tests=\"2\" failures=\"1\" time=\"0.839\" timestamp=\"2019-11-25T18:17:45.353Z\"\u003e\n    \u003ctestcase name=\"checks\"\u003e\n      \u003csystem-out\u003e  ✓ checks.....................: 50.00% ✓ 20  ✗ 20 \u003c/system-out\u003e\n    \u003c/testcase\u003e\n    \u003ctestcase name=\"errors\"\u003e\n      \u003cfailure message=\"  ✗ errors.....................: 50.00% ✓ 10  ✗ 10 \"\u003e  ✗ errors.....................: 50.00% ✓ 10  ✗ 10 \u003c/failure\u003e\n      \u003csystem-out\u003e  ✗ errors.....................: 50.00% ✓ 10  ✗ 10 \u003c/system-out\u003e\n    \u003c/testcase\u003e\n    \u003csystem-out\u003e\n      \u003c!-- Raw output from k6 command --\u003e\n    \u003c/system-out\u003e\n  \u003c/testsuite\u003e\n\u003c/testsuites\u003e\n```\n\n## Installing\n\n```shell\nnpm install -g k6-to-junit\n```\n\n## Usage as command\n\nthe `k6-to-junit` command is created which reads input from the stdin and can output to either stdout or a file.\n\n### Output to stdout\n\nthis allows you to pipe the xml output to another program for further processing\n\n```shell\nk6 run script.js | k6-to-junit\n```\n\n### Output to file\n\nthis passes through the stdin to the stdout\n\n```shell\nk6 run script.js | k6-to-junit junit.xml\n```\n\n## Usage as library\n\n### `K6Parser`\n\nthe main way of using this library is to use the K6Parser class. This allows creating a stateful object that can internaly store multiple test results before outputing them to a single xml structure.\n\n```javascript\nconst K6Parser = require(\"k6-to-junit\").K6Parser;\nconst parser = new K6Parser();\n```\n\n```typescript\nimport K6Parser from \"k6-to-junit\";\nconst parser = new K6Parser();\n```\n\n#### `K6Parser.pipeFrom(input, options)`\n\n- `input` (Readable): a stream to read from.\n  Common examples would be reading from stdin or a file\n\n- `options` (optional): options to use when parsing. all of the following are optional.\n\n  - `name` (string): the name to use for the generated TestSuite(s). will be read from input if omited.\n  - `startTime` (number): the start time to use for the test. will use `Date.now()` when stream starts if omited.\n  - `endTime` (number): the end time to use for the test. will use `Date.now()` when stream ends if omited.\n  - `output` (Writable): stream to forward input to. All data written to input stream will be mirrored here.\n\n- Returns a `Promise\u003cvoid\u003e` that resolves when the input stream closes or rejects if stream is interupted.\n\n```javascript\nk6Parser.pipeFrom(process.stdin, { output: process.stdout }).then(() =\u003e {\n  //do next stuff\n});\n```\n\n#### `K6Parser.allPassed()`\n\n- Returns false if any currently parsed tests have failed, else returns true.\n\n```javascript\nprocess.exit(k6Parser.allPassed() ? 0 : 99);\n```\n\n#### `K6Parser.toXml(stream)`\n\n- `stream` (Writable): an optional writable stream to write to. otherwise returns the xml data as a string.\n- Returns a string reprenstation of the junit xml data.\n\n```javascript\nk6Parser.toXml(fs.createWriteStream(\"junit.xml\"));\n```\n\n## Examples\n\n```javascript\n\nconst { spawn } = require(\"child_process\");\nconst { createWriteStream } = require(\"fs\");\nconst { K6Parser } = require(\"k6-to-junit\");\n\nconst parser = new K6Parser();\nconst test = spawn(\"k6\", [\"run\", \"test.js\"]);\n\nparser.pipeFrom(test.stdout).then(() =\u003e {\n  const writer = createWriteStream(\"junit.xml\");\n  parser.toXml(writer);\n  writer.once(\"finished\", () =\u003e {\n    process.exit(parser.allPassed() ? 0 : 99);\n  });\n});\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMattihew%2Fk6-to-junit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FMattihew%2Fk6-to-junit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMattihew%2Fk6-to-junit/lists"}