☕️ Classic, reliable, trusted test framework for Node.js and the browser
changed client-side to use mocha.setup(ui) and mocha.run()
TJ Holowaychukb77248e61cff
diff --git a/mocha.js b/mocha.jsindex 4225ddb7..58f62b9b 100644--- a/mocha.js+++ b/mocha.js@@ -642,9 +642,9 @@ function Doc(runner) {});runner.on('pass', function(test){- console.log('%s<dt>%s</dt>', indent(), test.title);+ console.log('%s <dt>%s</dt>', indent(), test.title);var code = clean(test.fn.toString());- console.log('%s<dd><pre><code>%s</code></pre></dd>', indent(), code);+ console.log('%s <dd><pre><code>%s</code></pre></dd>', indent(), code);});runner.on('end', function(){@@ -2026,34 +2026,36 @@ Test.prototype.run = function(fn){** These are meant only to allow* mocha.js to run untouched, not- * to allow running node code on- * the server.+ * to allow running node code in+ * the browser.*/process = {};-process.nextTick = function(fn){ setTimeout(fn, 0); };process.on = function(){};process.exit = function(status){};process.stdout = {};-global = this;+mocha = require('mocha');+// boot;(function(){- var mocha = require('mocha');var suite = new mocha.Suite;var Reporter = mocha.reporters.HTML;- mocha.interfaces.bdd(suite);- suite.emit('pre-require', global);- global.onload = run; // TODO: remove+ mocha.setup = function(ui){+ ui = mocha.interfaces[ui];+ if (!ui) throw new Error('invalid mocha interface "' + ui + '"');+ ui(suite);+ suite.emit('pre-require', global);+ };- function run() {+ mocha.run = function(){suite.emit('run');var runner = new mocha.Runner(suite);var reporter = new Reporter(runner);runner.run();- }+ };})();\ No newline at end of filediff --git a/support/tail.js b/support/tail.jsindex 1f07fcfe..97513745 100644--- a/support/tail.js+++ b/support/tail.js@@ -4,34 +4,36 @@** These are meant only to allow* mocha.js to run untouched, not- * to allow running node code on- * the server.+ * to allow running node code in+ * the browser.*/process = {};-process.nextTick = function(fn){ setTimeout(fn, 0); };process.on = function(){};process.exit = function(status){};process.stdout = {};-global = this;+mocha = require('mocha');+// boot;(function(){- var mocha = require('mocha');var suite = new mocha.Suite;var Reporter = mocha.reporters.HTML;- mocha.interfaces.bdd(suite);- suite.emit('pre-require', global);- global.onload = run; // TODO: remove+ mocha.setup = function(ui){+ ui = mocha.interfaces[ui];+ if (!ui) throw new Error('invalid mocha interface "' + ui + '"');+ ui(suite);+ suite.emit('pre-require', global);+ };- function run() {+ mocha.run = function(){suite.emit('run');var runner = new mocha.Runner(suite);var reporter = new Reporter(runner);runner.run();- }+ };})();\ No newline at end of filediff --git a/test/browser/index.html b/test/browser/index.htmlindex 5e79d046..62324872 100644--- a/test/browser/index.html+++ b/test/browser/index.html@@ -4,6 +4,7 @@<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js" type="text/javascript"></script><script src="../../mocha.js"></script>+ <script>mocha.setup('bdd')</script><link rel="stylesheet" href="style.css" /><script>function assert(expr, msg) {@@ -13,6 +14,7 @@<script src="array.js"></script><script src="../duration.js"></script><script src="../timeout.js"></script>+ <script>onload = mocha.run;</script></head><body><div id="mocha"></div>