Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

Fixing errors that prevent mocha.js from loading in the browser - fixes #1558

Vlad Magdaline3ba0ae812c8
diff --git a/lib/reporters/base.js b/lib/reporters/base.js
index 6ef22bbb..c253c11f 100644
--- a/lib/reporters/base.js
+++ b/lib/reporters/base.js
@@ -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).
@@ -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 +/-
diff --git a/lib/utils.js b/lib/utils.js
index 081c512e..bda5b8e8 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -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);
};
diff --git a/mocha.js b/mocha.js
index 178e2495..82f1c0bf 100644
--- a/mocha.js
+++ b/mocha.js
@@ -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).
@@ -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 +/-
@@ -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);
};