Skip to content

Commit

Permalink
resolves mochajs#1329: ability to disable syntax highlighting
Browse files Browse the repository at this point in the history
also built.
  • Loading branch information
Christopher Hiller committed Aug 30, 2014
1 parent 070a2fb commit 7d89662
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
10 changes: 10 additions & 0 deletions lib/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,16 @@ Mocha.prototype.asyncOnly = function(){
return this;
};

/**
* Disable syntax highlighting (in browser).
* @returns {Mocha}
* @api public
*/
Mocha.prototype.noHighlighting = function() {
this.options.noHighlighting = true;
return this;
};

/**
* Run tests and invoke `fn()` when complete.
*
Expand Down
17 changes: 14 additions & 3 deletions mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -1757,6 +1757,16 @@ Mocha.prototype.asyncOnly = function(){
return this;
};

/**
* Disable syntax highlighting (in browser).
* @returns {Mocha}
* @api public
*/
Mocha.prototype.noHighlighting = function() {
this.options.noHighlighting = true;
return this;
};

/**
* Run tests and invoke `fn()` when complete.
*
Expand Down Expand Up @@ -3143,7 +3153,7 @@ function clean(test) {
title: test.title,
fullTitle: test.fullTitle(),
duration: test.duration,
err: errorJSON(test.err)
err: errorJSON(test.err || {})
}
}

Expand Down Expand Up @@ -4302,6 +4312,7 @@ Runnable.prototype.resetTimeout = function(){
if (!this._enableTimeouts) return;
this.clearTimeout();
this.timer = setTimeout(function(){
if (!self._enableTimeouts) return;
self.callback(new Error('timeout of ' + ms + 'ms exceeded'));
self.timedOut = true;
}, ms);
Expand Down Expand Up @@ -5778,7 +5789,7 @@ function highlight(js) {
*/

exports.highlightTags = function(name) {
var code = document.getElementsByTagName(name);
var code = document.getElementById('mocha').getElementsByTagName(name);
for (var i = 0, len = code.length; i < len; ++i) {
code[i].innerHTML = highlight(code[i].innerHTML);
}
Expand Down Expand Up @@ -5979,7 +5990,7 @@ mocha.run = function(fn){

return Mocha.prototype.run.call(mocha, function(err){
// The DOM Document is not available in Web Workers.
if (global.document) {
if (global.document && options.noHighlighting !== false) {
Mocha.utils.highlightTags('code');
}
if (fn) fn(err);
Expand Down
2 changes: 1 addition & 1 deletion support/tail.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ mocha.run = function(fn){

return Mocha.prototype.run.call(mocha, function(err){
// The DOM Document is not available in Web Workers.
if (global.document) {
if (global.document && options.noHighlighting !== false) {
Mocha.utils.highlightTags('code');
}
if (fn) fn(err);
Expand Down

0 comments on commit 7d89662

Please sign in to comment.