diff --git a/Makefile b/Makefile index 333086277d..37e887f9a4 100644 --- a/Makefile +++ b/Makefile @@ -21,6 +21,7 @@ mocha.js BUILDTMP/mocha.js: $(SRC) browser-entry.js @printf "==> [Browser :: build]\n" mkdir -p ${@D} $(BROWSERIFY) ./browser-entry \ + --require buffer/:buffer \ --plugin ./scripts/dedefine \ --ignore 'fs' \ --ignore 'glob' \ diff --git a/karma.conf.js b/karma.conf.js index 21e1e68870..94e4a0e7d7 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -49,6 +49,7 @@ module.exports = function (config) { .ignore('fs') .ignore('path') .ignore('supports-color') + .require(path.join(__dirname, 'node_modules', 'buffer'), {expose: 'buffer'}) .on('bundled', function (err, content) { if (!err && bundleDirpath) { // write bundle to directory for debugging diff --git a/lib/utils.js b/lib/utils.js index 046e097296..9bac5a8cf7 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -209,17 +209,6 @@ var isArray = typeof Array.isArray === 'function' ? Array.isArray : function (ob exports.isArray = isArray; -/** - * Buffer.prototype.toJSON polyfill. - * - * @type {Function} - */ -if (typeof Buffer !== 'undefined' && Buffer.prototype) { - Buffer.prototype.toJSON = Buffer.prototype.toJSON || function () { - return Array.prototype.slice.call(this, 0); - }; -} - /** * Ignored files. * @@ -411,7 +400,7 @@ var type = exports.type = function type (value) { return 'undefined'; } else if (value === null) { return 'null'; - } else if (typeof Buffer !== 'undefined' && Buffer.isBuffer(value)) { + } else if (Buffer.isBuffer(value)) { return 'buffer'; } return Object.prototype.toString.call(value) @@ -439,7 +428,7 @@ exports.stringify = function (value) { if (!~indexOf(['object', 'array', 'function'], typeHint)) { if (typeHint === 'buffer') { - var json = value.toJSON(); + var json = Buffer.prototype.toJSON.call(value); // Based on the toJSON result return jsonStringify(json.data && json.type ? json.data : json, 2) .replace(/,(\n|$)/g, '$1'); @@ -549,17 +538,6 @@ function jsonStringify (object, spaces, depth) { (str.length !== 1 ? '\n' + repeat(' ', --space) + end : end); } -/** - * Test if a value is a buffer. - * - * @api private - * @param {*} value The value to test. - * @return {boolean} True if `value` is a buffer, otherwise false - */ -exports.isBuffer = function (value) { - return typeof Buffer !== 'undefined' && Buffer.isBuffer(value); -}; - /** * Return a new Thing that has the keys in sorted order. Recursive. * diff --git a/package.json b/package.json index 3a603d37b2..63d87fe2b0 100644 --- a/package.json +++ b/package.json @@ -321,7 +321,8 @@ "devDependencies": { "@coderbyheart/karma-sauce-launcher": "git://github.com/coderbyheart/karma-sauce-launcher#5259942cd6d40090eaa13ceeef5b0b8738c7710f", "assert": "^1.4.1", - "browserify": "^13.0.0", + "browserify": "^14.4.0", + "buffer": "^4.9.1", "coffee-script": "^1.10.0", "coveralls": "^2.11.15", "cross-spawn": "^5.1.0", @@ -367,7 +368,8 @@ "fs": false, "glob": false, "path": false, - "supports-color": false + "supports-color": false, + "buffer": "buffer" }, "homepage": "https://mochajs.org", "logo": "https://cldup.com/S9uQ-cOLYz.svg" diff --git a/test/unit/utils.spec.js b/test/unit/utils.spec.js index 3f643ea27a..cb33a7c520 100644 --- a/test/unit/utils.spec.js +++ b/test/unit/utils.spec.js @@ -495,18 +495,6 @@ describe('lib/utils', function () { }); }); - describe('isBuffer()', function () { - var isBuffer = utils.isBuffer; - it('should test if object is a Buffer', function () { - expect(isBuffer(Buffer.from([0x01]))) - .to - .equal(true); - expect(isBuffer({})) - .to - .equal(false); - }); - }); - describe('map()', function () { var map = utils.map; it('should behave same as Array.prototype.map', function () {