Skip to content

Commit

Permalink
refactor a reporterOptions check for highlight tags.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mia-jeong committed Oct 14, 2019
1 parent f12807d commit c21a5a3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 25 deletions.
6 changes: 0 additions & 6 deletions browser-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,6 @@ mocha.setup = function(opts) {
}
for (var opt in opts) {
if (opts.hasOwnProperty(opt)) {
if (opt === 'noHighlighting' && opt) {
require('./lib/utils').deprecate(
'noHighlighting is deprecated; provide {reporterOption: {highlight: false}} to mocha.setup().'
);
}

if (opt === 'reporterOptions') {
this.options.reporterOptions = opts[opt];
} else {
Expand Down
8 changes: 5 additions & 3 deletions lib/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -682,15 +682,17 @@ Mocha.prototype.asyncOnly = function() {
* Disables syntax highlighting (in browser).
*
* @public
* @param {boolean} enableHighlight - Whether to enable highlight.
* @return {Mocha} this
* @chainable
*/
Mocha.prototype.noHighlighting = function() {
Mocha.prototype.noHighlighting = function(enableHighlight) {
utils.deprecate(
'noHighlighting is deprecated; provide {reporterOption: {highlight: false}} to mocha.setup().'
);

this.options.noHighlighting = true;
this.options.reporterOptions = this.options.reporterOptions || {};
this.options.reporterOptions.highlight =
enableHighlight !== undefined && enableHighlight !== true;
return this;
};

Expand Down
23 changes: 9 additions & 14 deletions lib/reporters/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,14 @@ var playIcon = '‣';
*/
function HTML(runner, options) {
Base.call(this, runner, options);
for (var opt in options) {
if (options.hasOwnProperty(opt) && opt === 'reporterOptions') {
if (
options[opt] &&
(options[opt].highlight ||
typeof options[opt].highlight === 'undefined')
) {
options[opt].highlight = true;
}
if (!options[opt]) {
options[opt] = {highlight: true};
}
}

var enableHighlight = true;
if (
options.reporterOptions &&
options.reporterOptions.hasOwnProperty('highlight') &&
!options.reporterOptions.highlight
) {
enableHighlight = false;
}

var self = this;
Expand Down Expand Up @@ -240,7 +235,7 @@ function HTML(runner, options) {
});

runner.once(EVENT_RUN_END, function() {
if (options.reporterOptions.highlight === true) {
if (enableHighlight) {
utils.highlightTags('code');
}
});
Expand Down
9 changes: 7 additions & 2 deletions test/unit/mocha.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,15 @@ describe('Mocha', function() {

describe('#noHighlighting()', function() {
// :NOTE: Browser-only option...
it('should set the noHighlighting option to true', function() {
it('should set the reporterOptions.highlight to false', function() {
var mocha = new Mocha(opts);
mocha.noHighlighting();
expect(mocha.options, 'to have property', 'noHighlighting', true);
expect(
mocha.options.reporterOptions,
'to have property',
'highlight',
false
);
});

it('should be chainable', function() {
Expand Down

0 comments on commit c21a5a3

Please sign in to comment.