Skip to content

armgit / mocha

Public Imported from GitHub
0

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

Replace __proto__ with lodash.create

Nathan Houle98c20ea906c6
diff --git a/lib/hook.js b/lib/hook.js
index 3dec54b7..429a60cb 100644
--- a/lib/hook.js
+++ b/lib/hook.js
@@ -3,6 +3,7 @@
*/
var Runnable = require('./runnable');
+var create = require('lodash.create');
/**
* Expose `Hook`.
@@ -25,7 +26,10 @@ function Hook(title, fn) {
/**
* Inherit from `Runnable.prototype`.
*/
-Hook.prototype.__proto__ = Runnable.prototype;
+
+Hook.prototype = create(Runnable.prototype, {
+ constructor: Hook
+});
/**
* Get or set the test `err`.
diff --git a/lib/reporters/dot.js b/lib/reporters/dot.js
index b9cb785b..2ecdb5e1 100644
--- a/lib/reporters/dot.js
+++ b/lib/reporters/dot.js
@@ -3,6 +3,7 @@
*/
var Base = require('./base');
+var create = require('lodash.create');
var color = Base.color;
/**
@@ -63,4 +64,6 @@ function Dot(runner) {
* Inherit from `Base.prototype`.
*/
-Dot.prototype.__proto__ = Base.prototype;
+Dot.prototype = create(Base.prototype, {
+ constructor: Dot
+});
diff --git a/lib/reporters/landing.js b/lib/reporters/landing.js
index 1dd952cb..a29c2472 100644
--- a/lib/reporters/landing.js
+++ b/lib/reporters/landing.js
@@ -3,6 +3,7 @@
*/
var Base = require('./base');
+var create = require('lodash.create');
var cursor = Base.cursor;
var color = Base.color;
@@ -89,4 +90,6 @@ function Landing(runner) {
* Inherit from `Base.prototype`.
*/
-Landing.prototype.__proto__ = Base.prototype;
+Landing.prototype = create(Base.prototype, {
+ constructor: Landing
+});
diff --git a/lib/reporters/list.js b/lib/reporters/list.js
index 5f6d37e8..f9b39696 100644
--- a/lib/reporters/list.js
+++ b/lib/reporters/list.js
@@ -3,6 +3,7 @@
*/
var Base = require('./base');
+var create = require('lodash.create');
var color = Base.color;
var cursor = Base.cursor;
@@ -58,4 +59,6 @@ function List(runner) {
* Inherit from `Base.prototype`.
*/
-List.prototype.__proto__ = Base.prototype;
+List.prototype = create(Base.prototype, {
+ constructor: List
+});
diff --git a/lib/reporters/min.js b/lib/reporters/min.js
index f0b85578..f9c3a148 100644
--- a/lib/reporters/min.js
+++ b/lib/reporters/min.js
@@ -3,6 +3,7 @@
*/
var Base = require('./base');
+var create = require('lodash.create');
/**
* Expose `Min`.
@@ -33,4 +34,6 @@ function Min(runner) {
* Inherit from `Base.prototype`.
*/
-Min.prototype.__proto__ = Base.prototype;
+Min.prototype = create(Base.prototype, {
+ constructor: Min
+});
diff --git a/lib/reporters/nyan.js b/lib/reporters/nyan.js
index 21b77498..2baa9010 100644
--- a/lib/reporters/nyan.js
+++ b/lib/reporters/nyan.js
@@ -3,6 +3,7 @@
*/
var Base = require('./base');
+var create = require('lodash.create');
/**
* Expose `Dot`.
@@ -58,6 +59,14 @@ function NyanCat(runner) {
});
}
+/**
+ * Inherit from `Base.prototype`.
+ */
+
+NyanCat.prototype = create(Base.prototype, {
+ constructor: NyanCat
+});
+
/**
* Draw the nyan cat
*
@@ -253,9 +262,3 @@ NyanCat.prototype.rainbowify = function(str) {
function write(string) {
process.stdout.write(string);
}
-
-/**
- * Inherit from `Base.prototype`.
- */
-
-NyanCat.prototype.__proto__ = Base.prototype;
diff --git a/lib/reporters/progress.js b/lib/reporters/progress.js
index 29c67854..2ea25bda 100644
--- a/lib/reporters/progress.js
+++ b/lib/reporters/progress.js
@@ -3,6 +3,7 @@
*/
var Base = require('./base');
+var create = require('lodash.create');
var color = Base.color;
var cursor = Base.cursor;
@@ -86,4 +87,6 @@ function Progress(runner, options) {
* Inherit from `Base.prototype`.
*/
-Progress.prototype.__proto__ = Base.prototype;
+Progress.prototype = create(Base.prototype, {
+ constructor: Progress
+});
diff --git a/lib/reporters/spec.js b/lib/reporters/spec.js
index 1b447c17..9fbd805a 100644
--- a/lib/reporters/spec.js
+++ b/lib/reporters/spec.js
@@ -3,6 +3,7 @@
*/
var Base = require('./base');
+var create = require('lodash.create');
var color = Base.color;
var cursor = Base.cursor;
@@ -80,4 +81,6 @@ function Spec(runner) {
* Inherit from `Base.prototype`.
*/
-Spec.prototype.__proto__ = Base.prototype;
+Spec.prototype = create(Base.prototype, {
+ constructor: Spec
+});
diff --git a/lib/reporters/xunit.js b/lib/reporters/xunit.js
index 8286cd3f..70bfc755 100644
--- a/lib/reporters/xunit.js
+++ b/lib/reporters/xunit.js
@@ -3,6 +3,7 @@
*/
var Base = require('./base');
+var create = require('lodash.create');
var fs = require('fs');
var escape = require('../utils').escape;
@@ -95,7 +96,9 @@ XUnit.prototype.done = function(failures, fn) {
* Inherit from `Base.prototype`.
*/
-XUnit.prototype.__proto__ = Base.prototype;
+XUnit.prototype = create(Base.prototype, {
+ constructor: XUnit
+});
/**
* Write out the given line.
diff --git a/lib/runnable.js b/lib/runnable.js
index aa824174..d0c0f607 100644
--- a/lib/runnable.js
+++ b/lib/runnable.js
@@ -4,6 +4,7 @@
var EventEmitter = require('events').EventEmitter;
var Pending = require('./pending');
+var create = require('lodash.create');
var debug = require('debug')('mocha:runnable');
var milliseconds = require('./ms');
var utils = require('./utils');
@@ -55,7 +56,9 @@ function Runnable(title, fn) {
* Inherit from `EventEmitter.prototype`.
*/
-Runnable.prototype.__proto__ = EventEmitter.prototype;
+Runnable.prototype = create(EventEmitter.prototype, {
+ constructor: Runnable
+});
/**
* Set & get timeout `ms`.
diff --git a/lib/runner.js b/lib/runner.js
index 51bd3c54..18e94119 100644
--- a/lib/runner.js
+++ b/lib/runner.js
@@ -4,6 +4,7 @@
var EventEmitter = require('events').EventEmitter;
var Pending = require('./pending');
+var create = require('lodash.create');
var debug = require('debug')('mocha:runner');
var filter = require('./utils').filter;
var indexOf = require('./utils').indexOf;
@@ -86,7 +87,9 @@ Runner.immediately = global.setImmediate || process.nextTick;
* Inherit from `EventEmitter.prototype`.
*/
-Runner.prototype.__proto__ = EventEmitter.prototype;
+Runner.prototype = create(EventEmitter.prototype, {
+ constructor: Runner
+});
/**
* Run tests with full titles matching `re`. Updates runner.total
diff --git a/lib/suite.js b/lib/suite.js
index b59b3c8a..eb89fb34 100644
--- a/lib/suite.js
+++ b/lib/suite.js
@@ -4,6 +4,7 @@
var EventEmitter = require('events').EventEmitter;
var Hook = require('./hook');
+var create = require('lodash.create');
var debug = require('debug')('mocha:suite');
var milliseconds = require('./ms');
var utils = require('./utils');
@@ -66,7 +67,9 @@ function Suite(title, parentContext) {
* Inherit from `EventEmitter.prototype`.
*/
-Suite.prototype.__proto__ = EventEmitter.prototype;
+Suite.prototype = create(EventEmitter.prototype, {
+ constructor: Suite
+});
/**
* Return a clone of this `Suite`.
diff --git a/lib/test.js b/lib/test.js
index c6cbfd14..057e7728 100644
--- a/lib/test.js
+++ b/lib/test.js
@@ -3,6 +3,7 @@
*/
var Runnable = require('./runnable');
+var create = require('lodash.create');
/**
* Expose `Test`.
@@ -27,4 +28,6 @@ function Test(title, fn) {
* Inherit from `Runnable.prototype`.
*/
-Test.prototype.__proto__ = Runnable.prototype;
+Test.prototype = create(Runnable.prototype, {
+ constructor: Test
+});
diff --git a/package.json b/package.json
index d544796c..fb7a8476 100644
--- a/package.json
+++ b/package.json
@@ -282,6 +282,7 @@
"glob": "3.2.3",
"growl": "1.8.1",
"jade": "0.26.3",
+ "lodash.create": "^3.1.1",
"mkdirp": "0.5.0",
"supports-color": "1.2.0"
},