Skip to content

Commit

Permalink
Fixing errors that prevent mocha.js from loading in the browser - fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
callmevlad committed Feb 18, 2015
1 parent a11ad6c commit e3ba0ae
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
8 changes: 5 additions & 3 deletions lib/reporters/base.js
Expand Up @@ -6,7 +6,7 @@ var tty = require('tty')
, diff = require('diff')
, ms = require('../ms')
, utils = require('../utils')
, supportsColor = require('supports-color');
, supportsColor = process.env ? require('supports-color') : null;

/**
* Save timer references to avoid Sinon interfering (see GH-237).
Expand All @@ -31,10 +31,12 @@ var isatty = tty.isatty(1) && tty.isatty(2);
exports = module.exports = Base;

/**
* Enable coloring by default.
* Enable coloring by default, except in the browser interface.
*/

exports.useColors = supportsColor || (process.env.MOCHA_COLORS !== undefined);
exports.useColors = process.env
? (supportsColor || (process.env.MOCHA_COLORS !== undefined))
: false;

/**
* Inline diffs instead of +/-
Expand Down
2 changes: 1 addition & 1 deletion lib/utils.js
Expand Up @@ -173,7 +173,7 @@ var isArray = Array.isArray || function (obj) {
* Buffer.prototype.toJSON polyfill
* @type {Function}
*/
if(Buffer && Buffer.prototype) {
if(typeof Buffer !== 'undefined' && Buffer.prototype) {
Buffer.prototype.toJSON = Buffer.prototype.toJSON || function () {
return Array.prototype.slice.call(this, 0);
};
Expand Down
10 changes: 6 additions & 4 deletions mocha.js
Expand Up @@ -1974,7 +1974,7 @@ var tty = require('browser/tty')
, diff = require('browser/diff')
, ms = require('../ms')
, utils = require('../utils')
, supportsColor = require('supports-color');
, supportsColor = process.env ? require('supports-color') : null;

/**
* Save timer references to avoid Sinon interfering (see GH-237).
Expand All @@ -1999,10 +1999,12 @@ var isatty = tty.isatty(1) && tty.isatty(2);
exports = module.exports = Base;

/**
* Enable coloring by default.
* Enable coloring by default, except in the browser interface.
*/

exports.useColors = supportsColor || (process.env.MOCHA_COLORS !== undefined);
exports.useColors = process.env
? (supportsColor || (process.env.MOCHA_COLORS !== undefined))
: false;

/**
* Inline diffs instead of +/-
Expand Down Expand Up @@ -5845,7 +5847,7 @@ var isArray = Array.isArray || function (obj) {
* Buffer.prototype.toJSON polyfill
* @type {Function}
*/
if(Buffer && Buffer.prototype) {
if(typeof Buffer !== 'undefined' && Buffer.prototype) {
Buffer.prototype.toJSON = Buffer.prototype.toJSON || function () {
return Array.prototype.slice.call(this, 0);
};
Expand Down

0 comments on commit e3ba0ae

Please sign in to comment.