Skip to content

armgit / mocha

Public Imported from GitHub
0

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

Fixed self.test reference in runner. Closes #189

Tj Holowaychukee33c41b9ec5
diff --git a/lib/browser/path.js b/lib/browser/path.js
new file mode 100644
index 00000000..e69de29b
diff --git a/lib/runner.js b/lib/runner.js
index 248dbc6f..3fef8825 100644
--- a/lib/runner.js
+++ b/lib/runner.js
@@ -308,8 +308,10 @@ Runner.prototype.runTests = function(suite, fn){
// execute test and hook(s)
self.emit('test', self.test = test);
self.hookDown('beforeEach', function(){
- self.currentRunnable = test;
+ self.currentRunnable = self.test;
self.runTest(function(err){
+ test = self.test;
+
if (err) {
self.fail(test, err);
self.emit('test end', test);
diff --git a/mocha.js b/mocha.js
index 4288511e..c226f415 100644
--- a/mocha.js
+++ b/mocha.js
@@ -242,6 +242,10 @@ require.register("browser/fs.js", function(module, exports, require){
}); // module: browser/fs.js
+require.register("browser/path.js", function(module, exports, require){
+
+}); // module: browser/path.js
+
require.register("browser/progress.js", function(module, exports, require){
/**
@@ -698,7 +702,6 @@ exports.Runner = require('./runner');
exports.Suite = require('./suite');
exports.Hook = require('./hook');
exports.Test = require('./test');
-exports.watch = require('./watch');
}); // module: mocha.js
@@ -2464,8 +2467,10 @@ Runner.prototype.runTests = function(suite, fn){
// execute test and hook(s)
self.emit('test', self.test = test);
self.hookDown('beforeEach', function(){
- self.currentRunnable = test;
+ self.currentRunnable = self.test;
self.runTest(function(err){
+ test = self.test;
+
if (err) {
self.fail(test, err);
self.emit('test end', test);
@@ -2839,6 +2844,21 @@ Test.prototype.constructor = Test;
require.register("utils.js", function(module, exports, require){
+/**
+ * Module dependencies.
+ */
+
+var fs = require('browser/fs')
+ , path = require('browser/path')
+ , join = path.join
+ , debug = require('browser/debug')('watch');
+
+/**
+ * Ignored directories.
+ */
+
+var ignore = ['node_modules', '.git'];
+
/**
* Escape special characters in the given string of html.
*
@@ -2948,27 +2968,57 @@ exports.keys = Object.keys || function(obj) {
return keys;
};
-}); // module: utils.js
+/**
+ * Watch the given `files` for changes
+ * and invoke `fn(file)` on modification.
+ *
+ * @param {Array} files
+ * @param {Function} fn
+ * @api private
+ */
-require.register("watch.js", function(module, exports, require){
+exports.watch = function(files, fn){
+ var options = { interval: 100 };
+ files.forEach(function(file){
+ debug('file %s', file);
+ fs.watchFile(file, options, function(curr, prev){
+ if (prev.mtime < curr.mtime) fn(file);
+ });
+ });
+};
/**
- * Module dependencies.
+ * Ignored files.
*/
-var fs = require('browser/fs')
- , debug = require('browser/debug')('watch');
+function ignored(path){
+ return !~ignore.indexOf(path);
+}
-module.exports = function(paths, fn){
- var options = { interval: 100 };
- paths.forEach(function(path){
- debug('watch %s', path);
- fs.watchFile(path, options, function(curr, prev){
- if (prev.mtime < curr.mtime) fn(path);
- });
+/**
+ * Lookup files in the given `dir`.
+ *
+ * @return {Array}
+ * @api public
+ */
+
+exports.files = function(dir, ret){
+ ret = ret || [];
+
+ fs.readdirSync(dir)
+ .filter(ignored)
+ .forEach(function(path){
+ path = join(dir, path);
+ if (fs.statSync(path).isDirectory()) {
+ exports.files(path, ret);
+ } else if (path.match(/\.js$/)) {
+ ret.push(path);
+ }
});
+
+ return ret;
};
-}); // module: watch.js
+}); // module: utils.js
/**
* Node shims.
diff --git a/support/compile.js b/support/compile.js
index aaa9f4d4..abea707b 100644
--- a/support/compile.js
+++ b/support/compile.js
@@ -45,6 +45,7 @@ function parseRequires(js) {
return js
.replace(/require\('events'\)/g, "require('browser/events')")
.replace(/require\('debug'\)/g, "require('browser/debug')")
+ .replace(/require\('path'\)/g, "require('browser/path')")
.replace(/require\('tty'\)/g, "require('browser/tty')")
.replace(/require\('fs'\)/g, "require('browser/fs')")
}