K6-to-junit Unable to convert output to junit xml

I am running an azure pipeline to execute k6 tests, and to visualise the results, I tried using k6-to-junit npm package. I am running the script like as below:

parser.pipeFrom(execSync('k6 run script.js').stdio).then(() => {
        const writer = createWriteStream("junit.xml");
        parser.toXml(writer);
        writer.once("finished", () => {
          process.exit(k6Parser.allPassed() ? 0 : 99);
        });

But this gives the error: input.on is not a function

Let me know if anyone can help with this.

Thanks

Hi @Fabien!

Turned out the docs in the repo give an invalid code sample for how to use the parser programmatically. I played around with it a bit myself, and managed to produce a working snippet:

const { spawn } = require("child_process");
const { createWriteStream } = require("fs");
const { K6Parser } = require("k6-to-junit");

const parser = new K6Parser();
const test = spawn("k6", ["run", "test.js"]);

parser.pipeFrom(test.stdout).then(() => {
  const writer = createWriteStream("junit.xml");
  parser.toXml(writer);
  writer.once("finished", () => {
    process.exit(parser.allPassed() ? 0 : 99);
  });
});

I’ll do a PR to the repo to make sure they have a working sample.

Thanks for pointing it out!

1 Like