mcollina / autocannon

fast HTTP/1.1 benchmarking tool written in Node.js
MIT License
7.86k stars 326 forks source link

Can't print results with printResults #505

Closed wsierakowski closed 9 months ago

wsierakowski commented 10 months ago

I have the following script:

const autocannon = require('autocannon');

const test = async () => {
  const result1 = await autocannon({
    url: 'https://google.com',
    connections: 10, //default
    pipelining: 1, // default
    duration: 10, // default
  });

  autocannon.printResult(result1, {
    outputStream: process.stdout,
    renderResultsTable: true
  });
};

test();

This prints nothing on the screen. Why?

casantosmu commented 9 months ago

According to the documentation, the "printResult" function is supposed to 'Print the result tables to the terminal.' However, upon reviewing the code, it appears that it doesn't actually print anything to the terminal; instead, it only returns a string containing the result table. The "outputStream" option is only used to determine whether the terminal supports color. You can see it here.

To print the result to the terminal, use the value returned by the function. For example:

const { stdout } = require("node:process");
const autocannon = require("autocannon");

const test = async () => {
  const result = await autocannon({
    url: "https://google.com",
    connections: 10, //default
    pipelining: 1, // default
    duration: 10, // default
  });

  stdout.write(autocannon.printResult(result));
};

test();