From ac8169cd7f1161c127d7554900ebefff89b8baee Mon Sep 17 00:00:00 2001 From: Carlos Santos <65308244+casantosmu@users.noreply.github.com> Date: Tue, 9 Jan 2024 11:17:20 +0100 Subject: [PATCH] doc: fix API autocannon.print (#508) --- README.md | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e75e447f..579d2a74 100644 --- a/README.md +++ b/README.md @@ -393,13 +393,28 @@ Check out [this example](./samples/track-run.js) to see it in use, as well. ### autocannon.printResult(resultObject[, opts]) -Print the result tables to the terminal, programmatically. +Returns a text string containing the result tables. * `resultObject`: The result object of autocannon. _REQUIRED_. -* `opts`: Configuration options for printing the tables. This can have the following attributes. _OPTIONAL_. - * `outputStream`: The stream to output to. default: `process.stderr`. - * `renderResultsTable`: A truthy value to enable the rendering of the results table. default: `true`. - * `renderLatencyTable`: A truthy value to enable the rendering of the latency table. default: `false`. +* `opts`: Configuration options for generating the tables. These may include the following attributes. _OPTIONAL_. + * `outputStream`: The stream to which output is directed. It is primarily used to check if the terminal supports color. default: `process.stderr`. + * `renderResultsTable`: A truthy value to enable the creation of the results table. default: `true`. + * `renderLatencyTable`: A truthy value to enable the creation of the latency table. default: `false`. + +Example: + +```js +"use strict"; + +const { stdout } = require("node:process"); +const autocannon = require("autocannon"); + +function print(result) { + stdout.write(autocannon.printResult(result)); +} + +autocannon({ url: "http://localhost:3000" }, (err, result) => print(result)); +``` ### autocannon.aggregateResult(results[, opts])