Browse Source

fix ctx issue in runner

Kyle P Davis 12 years ago
parent
commit
ca6f250aea
2 changed files with 4 additions and 4 deletions
  1. 2 2
      lib/reporter.js
  2. 2 2
      lib/runner.js

+ 2 - 2
lib/reporter.js

@@ -6,10 +6,10 @@
  * @namespace benchmarksman
  * @param {Benchmark} bench  The `benchmark.js` test
  */
-module.exports = function reporter(bench){
+module.exports = function reporter(bench) {
 	var ctx = this;
 	return bench
-		.on("error", function(){
+		.on("error", function() {
 			if (ctx.file) console.error("ERROR in file: " + ctx.file);
 			throw bench.error;
 		})

+ 2 - 2
lib/runner.js

@@ -12,7 +12,7 @@ var path = require("path"),
  *    if {Array}, should be list of tests
  */
 module.exports = function runner(tests) { //jshint maxcomplexity:19
-	var ctx = this && this !== global && this !== require("./") ? this : {};
+	var ctx = this && this.constructor === Object ? this : {};
 	if (!ctx.reporter) ctx.reporter = reporter;
 	if (typeof tests === "string") tests = require(ctx.file = path.resolve(tests));
 	if (Array.isArray(tests) && !ctx.parent) return tests.forEach(runner.bind(ctx));
@@ -27,7 +27,7 @@ module.exports = function runner(tests) { //jshint maxcomplexity:19
 			for (var key in ctx) {
 				if (ctx.hasOwnProperty(key) && !bench.hasOwnProperty(key)) bench[key] = ctx[key];
 			}
-			reporter.call(ctx, bench);
+			ctx.reporter.call(ctx, bench);
 			try {
 				if (tests.beforeEach instanceof Function) tests.beforeEach.call(bench);
 				test.call(bench); // run once outside of bench for better error handling