From e29345607863d39dd38d402de8ada339c2a18422 Mon Sep 17 00:00:00 2001 From: CheadleCheadle Date: Tue, 17 Oct 2023 15:09:32 -0700 Subject: [PATCH 1/4] added optional jsw format to json reporter --- lib/cli/run-option-metadata.js | 3 ++- lib/reporters/json.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/cli/run-option-metadata.js b/lib/cli/run-option-metadata.js index 492608fbdd..58821fa4e7 100644 --- a/lib/cli/run-option-metadata.js +++ b/lib/cli/run-option-metadata.js @@ -49,7 +49,7 @@ const TYPES = (exports.types = { 'sort', 'watch' ], - number: ['retries', 'jobs'], + number: ['retries', 'jobs', 'jsonStringifyWhitespace'], string: [ 'config', 'fgrep', @@ -78,6 +78,7 @@ exports.aliases = { ignore: ['exclude'], invert: ['i'], jobs: ['j'], + jsonStringifyWhitespace: ['jsw'], 'no-colors': ['C'], 'node-option': ['n'], parallel: ['p'], diff --git a/lib/reporters/json.js b/lib/reporters/json.js index 6194d8747d..ff52d3b8a6 100644 --- a/lib/reporters/json.js +++ b/lib/reporters/json.js @@ -78,7 +78,7 @@ function JSONReporter(runner, options = {}) { runner.testResults = obj; - var json = JSON.stringify(obj, null, 2); + var json = JSON.stringify(obj, null, options.jsonStringifyWhitespace ?? 2); if (output) { try { fs.mkdirSync(path.dirname(output), {recursive: true}); From ce07d18d20b0ec311edabbd3a8d8f9b0c5664c55 Mon Sep 17 00:00:00 2001 From: Grant Cheadle Date: Mon, 4 Mar 2024 19:58:35 -0800 Subject: [PATCH 2/4] reporter option indentSize --- lib/cli/run-option-metadata.js | 3 +-- lib/reporters/json.js | 9 ++++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/cli/run-option-metadata.js b/lib/cli/run-option-metadata.js index 58821fa4e7..492608fbdd 100644 --- a/lib/cli/run-option-metadata.js +++ b/lib/cli/run-option-metadata.js @@ -49,7 +49,7 @@ const TYPES = (exports.types = { 'sort', 'watch' ], - number: ['retries', 'jobs', 'jsonStringifyWhitespace'], + number: ['retries', 'jobs'], string: [ 'config', 'fgrep', @@ -78,7 +78,6 @@ exports.aliases = { ignore: ['exclude'], invert: ['i'], jobs: ['j'], - jsonStringifyWhitespace: ['jsw'], 'no-colors': ['C'], 'node-option': ['n'], parallel: ['p'], diff --git a/lib/reporters/json.js b/lib/reporters/json.js index ff52d3b8a6..988f6d0249 100644 --- a/lib/reporters/json.js +++ b/lib/reporters/json.js @@ -45,6 +45,7 @@ function JSONReporter(runner, options = {}) { var output; if (options.reporterOption && options.reporterOption.output) { + Base.consoleLog('JSON Options:', options.reporterOption); if (utils.isBrowser()) { throw createUnsupportedError('file output not supported in browser'); } @@ -78,7 +79,13 @@ function JSONReporter(runner, options = {}) { runner.testResults = obj; - var json = JSON.stringify(obj, null, options.jsonStringifyWhitespace ?? 2); + var optionsIndentSize; + if (options.reporterOption && 'indentSize' in options.reporterOption) { + optionsIndentSize = options.reporterOption.indentSize; + } + var indentSize = parseInt(optionsIndentSize, 10) || 2; // Cast string to int or default indentation + + var json = JSON.stringify(obj, null, indentSize); if (output) { try { fs.mkdirSync(path.dirname(output), {recursive: true}); From 8d165129c4712d51d213936cfd2afe8fbdf18235 Mon Sep 17 00:00:00 2001 From: "Grant A. Cheadle" <108553712+CheadleCheadle@users.noreply.github.com> Date: Mon, 4 Mar 2024 20:11:14 -0800 Subject: [PATCH 3/4] removed Base.consoleLog within json.js --- lib/reporters/json.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/reporters/json.js b/lib/reporters/json.js index 988f6d0249..7cc096db79 100644 --- a/lib/reporters/json.js +++ b/lib/reporters/json.js @@ -45,7 +45,6 @@ function JSONReporter(runner, options = {}) { var output; if (options.reporterOption && options.reporterOption.output) { - Base.consoleLog('JSON Options:', options.reporterOption); if (utils.isBrowser()) { throw createUnsupportedError('file output not supported in browser'); } From 092824c8c2bd755409a3051e7f589f1727d74b7c Mon Sep 17 00:00:00 2001 From: Grant Cheadle Date: Wed, 6 Mar 2024 18:30:54 -0800 Subject: [PATCH 4/4] refactor json reporter --- lib/reporters/json.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/reporters/json.js b/lib/reporters/json.js index 7cc096db79..2ea4ed913b 100644 --- a/lib/reporters/json.js +++ b/lib/reporters/json.js @@ -81,8 +81,11 @@ function JSONReporter(runner, options = {}) { var optionsIndentSize; if (options.reporterOption && 'indentSize' in options.reporterOption) { optionsIndentSize = options.reporterOption.indentSize; + } else { + optionsIndentSize = 2; // Default Indentation size } - var indentSize = parseInt(optionsIndentSize, 10) || 2; // Cast string to int or default indentation + + var indentSize = parseInt(optionsIndentSize, 10); // Cast string to int var json = JSON.stringify(obj, null, indentSize); if (output) {