From 04481a26e19917f18c9550a25dcab4a5802ad1f6 Mon Sep 17 00:00:00 2001 From: Stefan Ollinger Date: Thu, 5 Oct 2023 16:36:57 +0200 Subject: [PATCH 1/2] Show response time in milliseconds per request and total --- packages/bruno-cli/src/commands/run.js | 3 ++- .../bruno-cli/src/runner/run-single-request.js | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/packages/bruno-cli/src/commands/run.js b/packages/bruno-cli/src/commands/run.js index ff0ab42e..b7bb0d62 100644 --- a/packages/bruno-cli/src/commands/run.js +++ b/packages/bruno-cli/src/commands/run.js @@ -356,7 +356,8 @@ const handler = async function (argv) { } const summary = printRunSummary(results); - console.log(chalk.dim(chalk.grey('Ran all requests.'))); + const totalTime = results.reduce((acc, res) => acc + res.response.responseTime, 0); + console.log(chalk.dim(chalk.grey(`Ran all requests. - ${totalTime} ms`))); if (outputPath && outputPath.length) { const outputDir = path.dirname(outputPath); diff --git a/packages/bruno-cli/src/runner/run-single-request.js b/packages/bruno-cli/src/runner/run-single-request.js index 79435785..69ecb1fa 100644 --- a/packages/bruno-cli/src/runner/run-single-request.js +++ b/packages/bruno-cli/src/runner/run-single-request.js @@ -122,13 +122,16 @@ const runSingleRequest = async function ( request.data = qs.stringify(request.data); } - let response; + let response, responseTime; try { // run request + const start = Date.now(); response = await axios(request); + responseTime = Date.now() - start; } catch (err) { if (err && err.response) { response = err.response; + responseTime = Date.now() - start; } else { console.log(chalk.red(stripExtension(filename)) + chalk.dim(` (${err.message})`)); return { @@ -142,7 +145,8 @@ const runSingleRequest = async function ( status: null, statusText: null, headers: null, - data: null + data: null, + responseTime: 0 }, error: err.message, assertionResults: [], @@ -151,7 +155,10 @@ const runSingleRequest = async function ( } } - console.log(chalk.green(stripExtension(filename)) + chalk.dim(` (${response.status} ${response.statusText})`)); + console.log( + chalk.green(stripExtension(filename)) + + chalk.dim(` (${response.status} ${response.statusText}) - ${responseTime} ms`) + ); // run post-response vars const postResponseVars = get(bruJson, 'request.vars.res'); @@ -247,7 +254,8 @@ const runSingleRequest = async function ( status: response.status, statusText: response.statusText, headers: response.headers, - data: response.data + data: response.data, + responseTime }, error: null, assertionResults, From e90718f47bf90084b9017662d62b1ea2ecb6cc2e Mon Sep 17 00:00:00 2001 From: Stefan Ollinger Date: Thu, 5 Oct 2023 16:42:49 +0200 Subject: [PATCH 2/2] Show response time in milliseconds per request and total --- packages/bruno-cli/src/commands/run.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/bruno-cli/src/commands/run.js b/packages/bruno-cli/src/commands/run.js index b7bb0d62..7866425e 100644 --- a/packages/bruno-cli/src/commands/run.js +++ b/packages/bruno-cli/src/commands/run.js @@ -357,7 +357,7 @@ const handler = async function (argv) { const summary = printRunSummary(results); const totalTime = results.reduce((acc, res) => acc + res.response.responseTime, 0); - console.log(chalk.dim(chalk.grey(`Ran all requests. - ${totalTime} ms`))); + console.log(chalk.dim(chalk.grey(`Ran all requests - ${totalTime} ms`))); if (outputPath && outputPath.length) { const outputDir = path.dirname(outputPath);