Skip to content

Commit

Permalink
refactor #5017
Browse files Browse the repository at this point in the history
  • Loading branch information
CheadleCheadle committed Jul 8, 2024
1 parent 11a0615 commit 5a65f9c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
Empty file modified bin/mocha.js
100644 → 100755
Empty file.
14 changes: 7 additions & 7 deletions lib/reporters/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,16 @@ function JSONReporter(runner, options = {}) {

runner.testResults = obj;

var optionsIndentSize;
if (options.reporterOption && 'indentSize' in options.reporterOption) {
optionsIndentSize = options.reporterOption.indentSize;
options.indentation = options.reporterOption?.indentSize ?? 2; // Default indenation

var json;

if (options.indentation === '\\t') {
json = JSON.stringify(obj, null, '\t');
} else {
optionsIndentSize = 2; // Default Indentation size
json = JSON.stringify(obj, null, parseInt(options.indentation, 10));
}

var indentSize = parseInt(optionsIndentSize, 10); // Cast string to int

var json = JSON.stringify(obj, null, indentSize);
if (output) {
try {
fs.mkdirSync(path.dirname(output), {recursive: true});
Expand Down
14 changes: 14 additions & 0 deletions test/reporters/json.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,5 +229,19 @@ describe('JSON reporter', function () {
'file output not supported in browser'
);
});

it('should set options.indentation correctly', function () {
var options = {indentation: 4};
var mochaReporter = new mocha._reporter(runner, options);

expect(mochaReporter.options.indentation, 'to be', 4);
});

it('should set options.indentation correctly with a tab', function () {
var options = {indentation: '\t'};
var mochaReporter = new mocha._reporter(runner, options);

expect(mochaReporter.options.indentation, 'to be', '\t');
});
});
});

0 comments on commit 5a65f9c

Please sign in to comment.