Skip to content

armgit / mocha

Public Imported from GitHub
0

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

Test inherits from Runnable

Tj Holowaychukc9d930d329d2
diff --git a/lib/test.js b/lib/test.js
index 9e764f75..c910cc58 100644
--- a/lib/test.js
+++ b/lib/test.js
@@ -1,4 +1,10 @@
+/**
+ * Module dependencies.
+ */
+
+var Runnable = require('./runnable');
+
/**
* Expose `Test`.
*/
@@ -14,82 +20,12 @@ module.exports = Test;
*/
function Test(title, fn) {
- this.title = title;
- this.fn = fn;
+ Runnable.call(this, title, fn);
this.pending = !fn;
- this.async = fn && fn.length;
- this.sync = ! this.async;
- this.timeout(2000);
}
/**
- * Set timeout `ms`.
- *
- * @param {Number} ms
- * @return {Test} for chaining
- * @api private
- */
-
-Test.prototype.timeout = function(ms){
- this._timeout = ms;
- return this;
-};
-
-/**
- * Return the full title generated by recursively
- * concatenating the parent's full title.
- *
- * @return {String}
- * @api public
- */
-
-Test.prototype.fullTitle = function(){
- return this.parent.fullTitle() + ' ' + this.title;
-};
-
-/**
- * Run the test and invoke `fn(err)`.
- *
- * @param {Function} fn
- * @api private
+ * Inherit from `Runnable.prototype`.
*/
-Test.prototype.run = function(fn){
- var self = this
- , ms = this._timeout
- , start = new Date
- , timer;
-
- // timeout
- if (this.async) {
- timer = setTimeout(function(){
- fn(new Error('timeout of ' + ms + 'ms exceeded'));
- }, ms);
- }
-
- // async
- if (this.async) {
- try {
- this.fn(function(err){
- clearTimeout(timer);
- self.duration = new Date - start;
- fn(err);
- self.finished = true;
- });
- } catch (err) {
- clearTimeout(timer);
- fn(err);
- this.finished = true;
- }
- return;
- }
-
- // sync
- try {
- if (!this.pending) this.fn();
- this.duration = new Date - start;
- fn();
- } catch (err) {
- fn(err);
- }
-};
+Test.prototype.__proto__ = Runnable.prototype;