From f1af1c30df3319120c700369204c6ab0037a960a Mon Sep 17 00:00:00 2001 From: Jamie King Date: Tue, 12 Mar 2024 03:45:15 -0700 Subject: [PATCH] fix: table would still be rendered in JSON mode when writing to file (#514) --- lib/validate.js | 4 ++++ test/validate.test.js | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/lib/validate.js b/lib/validate.js index 93ac5aef..bbc7f458 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -66,6 +66,10 @@ module.exports = function validateOpts (opts, cbPassedIn) { // fill in defaults after opts = defaultOpts(opts) + if (opts.json === true) { + opts.renderProgressBar = opts.renderResultsTable = opts.renderLatencyTable = false + } + if (opts.requests) { if (opts.requests.some(r => !isValidFn(r.setupRequest))) { return new Error('Invalid option setupRequest, please provide a function (or file path when in workers mode)') diff --git a/test/validate.test.js b/test/validate.test.js index eed3fd95..41903612 100644 --- a/test/validate.test.js +++ b/test/validate.test.js @@ -228,3 +228,21 @@ test('validateOpts should return an error when forever is used with workers', { t.ok(result instanceof Error) t.equal(result.message, 'Using `forever` option isn\'t currently supported with workers') }) + +test('validateOpts should not set render options by default', (t) => { + t.plan(3) + + const result = validateOpts({ url: 'http://localhost' }) + t.equal(result.renderProgressBar, undefined) + t.equal(result.renderResultsTable, undefined) + t.equal(result.renderLatencyTable, undefined) +}) + +test('validateOpts should disable render options when json is true', (t) => { + t.plan(3) + + const result = validateOpts({ url: 'http://localhost', json: true }) + t.equal(result.renderProgressBar, false) + t.equal(result.renderResultsTable, false) + t.equal(result.renderLatencyTable, false) +})