☕️ Classic, reliable, trusted test framework for Node.js and the browser
build
TJ Holowaychuk82765058ff57
diff --git a/index.html b/index.htmlindex ad122533..3cc92480 100644--- a/index.html+++ b/index.html@@ -30,37 +30,37 @@<li>growl notification support</li><li>reports test durations</li><li>highlights slow tests</li>+<li>file watcher support</li><li>global variable leak detection</li><li>optionally run tests that match a regexp</li>-<li>auto-exit to prevent “hanging” with an active loop</li>+<li>auto-exit to prevent "hanging" with an active loop</li><li>easily meta-generate suites & test-cases</li><li>mocha.opts file support</li><li><code>mocha-debug(1)</code> for node debugger support</li><li>detects multiple calls to <code>done()</code></li><li>use any assertion library you want</li><li>extensible reporting, bundled with 9+ reporters</li>-<li>extensible test DSLs or “interfaces”</li>+<li>extensible test DSLs or "interfaces"</li><li>before, after, before each, after each hooks</li><li>coffee-script support</li><li>TextMate bundle</li><li>and more!</li></ul>-<h2>Installation</h2>-<p> Install with <a href="http://npmjs.org">npm</a>:</p>+<p>Install with <a href="http://npmjs.org">npm</a>:</p><pre><code>$ npm install -g mocha</code></pre><h2>Assertions</h2>-<p>Mocha allows you to use any assertion library you want, if it throws an error, it will work! This means you can utilize libraries such as <a href="http://github.com/visionmedia/should.js">should.js</a>, node’s regular <code>assert</code> module, or others.</p>+<p>Mocha allows you to use any assertion library you want, if it throws an error, it will work! This means you can utilize libraries such as <a href="http://github.com/visionmedia/should.js">should.js</a>, node's regular <code>assert</code> module, or others.</p><h2>Synchronous code</h2>-<p> When testing synchronous code, omit the callback and Mocha will automatically continue on to the next test.</p>+<p>When testing synchronous code, omit the callback and Mocha will automatically continue on to the next test.</p><pre><code>describe('Array', function(){describe('#indexOf()', function(){@@ -89,7 +89,7 @@})</code></pre>-<p> To make things even easier, the <code>done()</code> callback accepts an error, so we may use this directly:</p>+<p>To make things even easier, the <code>done()</code> callback accepts an error, so we may use this directly:</p><pre><code>describe('User', function(){describe('#save()', function(){@@ -101,7 +101,7 @@})</code></pre>-<p> All “hooks”, that is <code>before()</code>, <code>after()</code>, <code>beforeEach()</code>, <code>afterEach()</code> may be sync or async as well, behaving much like a regular test-case. For example you may wish to populate database with dummy content before each test:</p>+<p>All "hooks", that is <code>before()</code>, <code>after()</code>, <code>beforeEach()</code>, <code>afterEach()</code> may be sync or async as well, behaving much like a regular test-case. For example you may wish to populate database with dummy content before each test:</p><pre><code>describe('Connection', function(){var db = new Connection@@ -130,7 +130,7 @@<h2>Pending tests</h2>-<p> Pending test-cases are simply those without a callback:</p>+<p>Pending test-cases are simply those without a callback:</p><pre><code>describe('Array', function(){describe('#indexOf()', function(){@@ -141,11 +141,11 @@<h2>Test duration</h2>-<p> Most of the reporters support some form of displaying+<p>Most of the reporters support some form of displayingtest duration, as well as flagging tests that are slow,- as shown here with the “spec” reporter:</p>+ as shown here with the "spec" reporter:</p>-<p> <img src="images/reporter-spec-duration.png" alt="test duration" /></p>+<p><img src="images/reporter-spec-duration.png" alt="test duration" title="" /></p><h2>mocha(1)</h2>@@ -161,35 +161,53 @@ Options:-g, --grep <pattern> only run tests matching <pattern>-t, --timeout <ms> set test-case timeout in milliseconds [2000]-s, --slow <ms> "slow" test threshold in milliseconds [75]+ -w, --watch watch test files for changes-C, --no-colors force disabling of colors- -G, --growl enable growl support+ -c, --colors force enabling of colors+ -G, --growl enable growl notification support+ --globals <names> allow the given comma-delimited global [names]+ --ignore-leaks ignore global variable leaks+ --interfaces display available interfaces+ --reporters display available reporters</code></pre>-<h3>-r, —require <name></h3>+<h3>-w, --watch</h3>++<p>Executes tests on changes to the test files.</p>++<h3>--globals <names></h3>++<p>Accepts a comma-delimited list of accepted global variable names. For example suppose your app deliberately exposes a global named <code>app</code> and <code>YUI</code>, you may want to add <code>--globals app,YUI</code>.</p>++<h3>--ignore-leaks</h3>-<p> The <code>--require</code> option is useful for libraries such as <a href="http://github.com/visionmedia/should.js">should.js</a>, so you may simply <code>--require should</code> instead of manually invoking <code>require('should')</code> within each test file.</p>+<p>By default Mocha will fail when global variables are introduced, you may use <code>--globals</code> to specify a few, or use <code>--ignore-leaks</code> to disable this functionality. </p>-<h3>-u, —ui <name></h3>+<h3>-r, --require <name></h3>-<p> The <code>--ui</code> option lets you specify the interface to use, defaulting to “bdd”.</p>+<p>The <code>--require</code> option is useful for libraries such as <a href="http://github.com/visionmedia/should.js">should.js</a>, so you may simply <code>--require should</code> instead of manually invoking <code>require('should')</code> within each test file.</p>-<h3>-R, —reporter <name></h3>+<h3>-u, --ui <name></h3>-<p> The <code>--reporter</code> option allows you to specify the reporter that will be used, defaulting to “dot”.</p>+<p>The <code>--ui</code> option lets you specify the interface to use, defaulting to "bdd".</p>-<h3>-t, —timeout <ms></h3>+<h3>-R, --reporter <name></h3>-<p> Specifies the test-case timeout, defaulting to 2 seconds. To override you may pass the timeout in milliseconds, or a value with the <code>s</code> suffix, ex: <code>--timeout 2s</code> or <code>--timeout 2000</code> would be equivalent.</p>+<p>The <code>--reporter</code> option allows you to specify the reporter that will be used, defaulting to "dot".</p>-<h3>-s, —slow <ms></h3>+<h3>-t, --timeout <ms></h3>-<p> Specify the “slow” test threshold, defaulting to 75ms. Mocha uses this to highlight test-cases that are taking too long.</p>+<p>Specifies the test-case timeout, defaulting to 2 seconds. To override you may pass the timeout in milliseconds, or a value with the <code>s</code> suffix, ex: <code>--timeout 2s</code> or <code>--timeout 2000</code> would be equivalent.</p>-<h3>-g, —grep <pattern></h3>+<h3>-s, --slow <ms></h3>-<p> The <code>--grep</code> option when specified will trigger mocha to only run tests matching the given <code>pattern</code> which is internally compiled to a <code>RegExp</code>.</p>+<p>Specify the "slow" test threshold, defaulting to 75ms. Mocha uses this to highlight test-cases that are taking too long.</p>-<p> Suppose for example you have “api” related tests, as well as “app” related tests, as shown in the following snippet; One could use <code>--grep api</code> or <code>--grep app</code> to run one or the other. The same goes for any other part of a suite or test-case title, <code>--grep users</code> would be valid as well, or even <code>--grep GET</code>.</p>+<h3>-g, --grep <pattern></h3>++<p>The <code>--grep</code> option when specified will trigger mocha to only run tests matching the given <code>pattern</code> which is internally compiled to a <code>RegExp</code>. </p>++<p>Suppose for example you have "api" related tests, as well as "app" related tests, as shown in the following snippet; One could use <code>--grep api</code> or <code>--grep app</code> to run one or the other. The same goes for any other part of a suite or test-case title, <code>--grep users</code> would be valid as well, or even <code>--grep GET</code>.</p><pre><code>describe('api', function(){describe('GET /api/users', function(){@@ -206,15 +224,15 @@ describe('app', function(){<h2>mocha-debug(1)</h2>-<p> <code>mocha-debug(1)</code> is identical to <code>mocha(1)</code>, however it enables node’s debugger so you may step through tests with the <strong>debugger</strong> statement.</p>+<p><code>mocha-debug(1)</code> is identical to <code>mocha(1)</code>, however it enables node's debugger so you may step through tests with the <strong>debugger</strong> statement.</p><h2>Interfaces</h2>-<p> Mocha “interface” system allows developers to choose their style of DSL. Shipping with <strong>BDD</strong>, <strong>TDD</strong>, and <strong>exports</strong> flavoured interfaces.</p>+<p>Mocha "interface" system allows developers to choose their style of DSL. Shipping with <strong>BDD</strong>, <strong>TDD</strong>, and <strong>exports</strong> flavoured interfaces.</p><h3>BDD</h3>-<p> The “<strong>BDD</strong>” interface provides <code>describe()</code>, <code>it()</code>, <code>before()</code>, <code>after()</code>, <code>beforeEach()</code>, and <code>afterEach()</code>:</p>+<p>The "<strong>BDD</strong>" interface provides <code>describe()</code>, <code>it()</code>, <code>before()</code>, <code>after()</code>, <code>beforeEach()</code>, and <code>afterEach()</code>: </p><pre><code>describe('Array', function(){before(function(){@@ -231,7 +249,7 @@ describe('app', function(){<h3>TDD</h3>-<p> The “<strong>TDD</strong>” interface provides <code>suite()</code>, <code>test()</code>, <code>setup()</code>, and <code>teardown()</code>.</p>+<p>The "<strong>TDD</strong>" interface provides <code>suite()</code>, <code>test()</code>, <code>setup()</code>, and <code>teardown()</code>.</p><pre><code>suite('Array', function(){setup(function(){@@ -248,7 +266,7 @@ describe('app', function(){<h3>Exports</h3>-<p> The “<strong>exports</strong>” interface is much like Mocha’s predecessor <a href="http://github.com/visionmedia/expresso">expresso</a>. The keys <code>before</code>, <code>after</code>, <code>beforeEach</code>, and <code>afterEach</code> are special-cased, object values+<p>The "<strong>exports</strong>" interface is much like Mocha's predecessor <a href="http://github.com/visionmedia/expresso">expresso</a>. The keys <code>before</code>, <code>after</code>, <code>beforeEach</code>, and <code>afterEach</code> are special-cased, object valuesare suites, and function values are test-cases.</p><pre><code>module.exports = {@@ -268,76 +286,76 @@ describe('app', function(){<h2>Reporters</h2>-<p> Mocha reporters adjust to the terminal window,+<p>Mocha reporters adjust to the terminal window,and always disable ansi-escape colouring whenthe stdio streams are not associated with a tty.</p><h3>Dot Matrix</h3>-<p> The “dot” matrix reporter is simply a series of dots+<p>The "dot" matrix reporter is simply a series of dotsthat represent test cases, failures highlight in red,pending in blue, slow as yellow.</p>-<p> <img src="images/reporter-dot.png" alt="dot matrix reporter" /></p>+<p><img src="images/reporter-dot.png" alt="dot matrix reporter" title="" /></p><h3>Spec</h3>-<p> The “spec” reporter outputs a hierarchical view+<p>The "spec" reporter outputs a hierarchical viewnested just as the test cases are.</p>-<p> <img src="images/reporter-spec.png" alt="spec reporter" />- <img src="images/reporter-spec-fail.png" alt="spec reporter with failure" /></p>+<p><img src="images/reporter-spec.png" alt="spec reporter" title="" />+ <img src="images/reporter-spec-fail.png" alt="spec reporter with failure" title="" /></p><h3>TAP</h3>-<p> The TAP reporter emits lines for a <a href="http://en.wikipedia.org/wiki/Test_Anything_Protocol">Test-Anything-Protocol</a> consumer.</p>+<p>The TAP reporter emits lines for a <a href="http://en.wikipedia.org/wiki/Test_Anything_Protocol">Test-Anything-Protocol</a> consumer.</p>-<p> <img src="images/reporter-tap.png" alt="test anything protocol" /></p>+<p><img src="images/reporter-tap.png" alt="test anything protocol" title="" /></p><h3>Landing Strip</h3>-<p> The Landing Strip reporter is a gimmicky test reporter simulating+<p>The Landing Strip reporter is a gimmicky test reporter simulatinga plane landing :) unicode ftw</p>-<p> <img src="images/reporter-landing.png" alt="landing strip plane reporter" />- <img src="images/reporter-landing-fail.png" alt="landing strip with failure" /></p>+<p><img src="images/reporter-landing.png" alt="landing strip plane reporter" title="" />+ <img src="images/reporter-landing-fail.png" alt="landing strip with failure" title="" /></p><h3>List</h3>-<p> The “List” reporter outputs a simple specifications list as- test cases pass or fail, outputting the failure details at+<p>The "List" reporter outputs a simple specifications list as+ test cases pass or fail, outputting the failure details atthe bottom of the output.</p>-<p> <img src="images/reporter-list.png" alt="list reporter" /></p>+<p><img src="images/reporter-list.png" alt="list reporter" title="" /></p><h3>Progress</h3>-<p> The progress reporter implements a simple progress-bar:</p>+<p>The progress reporter implements a simple progress-bar:</p>-<p> <img src="images/reporter-progress.png" alt="progress bar" /></p>+<p><img src="images/reporter-progress.png" alt="progress bar" title="" /></p><h3>JSON</h3>-<p> The JSON reporter outputs a single large JSON object when+<p>The JSON reporter outputs a single large JSON object whenthe tests have completed (failures or not).</p>-<p> <img src="images/reporter-json.png" alt="json reporter" /></p>+<p><img src="images/reporter-json.png" alt="json reporter" title="" /></p><h3>JSON Stream</h3>-<p> The JSON Stream reporter outputs newline-delimited JSON “events” as they occur, beginning with a “start” event, followed by test passes or failures, and then the final “end” event.</p>+<p>The JSON Stream reporter outputs newline-delimited JSON "events" as they occur, beginning with a "start" event, followed by test passes or failures, and then the final "end" event.</p>-<p> <img src="images/reporter-json-stream.png" alt="json stream reporter" /></p>+<p><img src="images/reporter-json-stream.png" alt="json stream reporter" title="" /></p><h3>Doc</h3>-<p> The “doc” reporter outputs a hierarchical HTML body representation+<p>The "doc" reporter outputs a hierarchical HTML body representationof your tests, wrap it with a header, footer, some styling and youhave some fantastic documentation!</p>-<p> <img src="images/reporter-doc.png" alt="doc reporter" /></p>+<p><img src="images/reporter-doc.png" alt="doc reporter" title="" /></p>-<p> For example suppose you have the following JavaScript:</p>+<p>For example suppose you have the following JavaScript:</p><pre><code>describe('Array', function(){describe('#indexOf()', function(){@@ -349,7 +367,7 @@ describe('app', function(){})</code></pre>-<p> The command <code>mocha --reporter doc array</code> would yield:</p>+<p>The command <code>mocha --reporter doc array</code> would yield:</p><pre><code><section class="suite"><h1>Array</h1>@@ -368,14 +386,14 @@ describe('app', function(){<h3>HTML</h3>-<p> The <strong>HTML</strong> reporter is currently the only browser reporter+<p>The <strong>HTML</strong> reporter is currently the only browser reportersupported by Mocha, and it looks like this:</p>-<p> <img src="images/reporter-html.png" alt="HTML test reporter" /></p>+<p><img src="images/reporter-html.png" alt="HTML test reporter" title="" /></p><h2>Browser support</h2>-<p> Mocha runs in the browser. Every release of Mocha will have new builds of <em>./mocha.js</em> and <em>./mocha.css</em> for use in the browser. To setup Mocha for browser use all you have to do is include the script, stylesheet, tell Mocha which interface you wish to use, and then run the tests. A typical setup might look something like the following, where we call <code>mocha.setup('bdd')</code> to use the <strong>BDD</strong> interface before loading the test scripts, running them <code>onload</code> with <code>mocha.run()</code>.</p>+<p>Mocha runs in the browser. Every release of Mocha will have new builds of <em>./mocha.js</em> and <em>./mocha.css</em> for use in the browser. To setup Mocha for browser use all you have to do is include the script, stylesheet, tell Mocha which interface you wish to use, and then run the tests. A typical setup might look something like the following, where we call <code>mocha.setup('bdd')</code> to use the <strong>BDD</strong> interface before loading the test scripts, running them <code>onload</code> with <code>mocha.run()</code>.</p><pre><code><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js" type="text/javascript"></script><link rel="stylesheet" href="style.css" />@@ -387,16 +405,20 @@ describe('app', function(){<script>onload = mocha.run;</script></code></pre>+<h3>grep</h3>++<p>The client-side may utilize <code>--grep</code> as well, however you use the query-string, for example <code>?grep=api</code>.</p>+<h2>mocha.opts</h2>-<p> Mocha will attempt to load <code>./test/mocha.opts</code>, these are concatenated with <code>process.argv</code>, though command-line args will take precedence. For example suppose you have the following <em>mocha.opts</em> file:</p>+<p>Mocha will attempt to load <code>./test/mocha.opts</code>, these are concatenated with <code>process.argv</code>, though command-line args will take precedence. For example suppose you have the following <em>mocha.opts</em> file:</p><pre><code>--require should--reporter dot--ui bdd</code></pre>-<p> This will default the reporter to <code>dot</code>, require the <code>should</code> library,+<p>This will default the reporter to <code>dot</code>, require the <code>should</code> library,and use <code>bdd</code> as the interface. With this you may then invoke <code>mocha(1)</code>with additional arguments, here enabling growl support and changingthe reporter to <code>spec</code>:</p>@@ -406,7 +428,7 @@ describe('app', function(){<h2>Suite merging</h2>-<p> Suites with common names are “merged” in order+<p>Suites with common names are "merged" in orderto produce unified reporting, especially whenmeta-generating tests.</p>@@ -433,20 +455,20 @@ describe('merge stuff', function(){})</code></pre>-<p>Instead of reporting these as distinct suites, they are merged, yielding the following:</p>+<p>Instead of reporting these as distinct suites, they are merged, yielding the following: </p>-<p> <img src="http://f.cl.ly/items/380R3S1t1t0b0O2K250V/Screenshot.png" alt="mocha suite merging" /></p>+<p><img src="http://f.cl.ly/items/380R3S1t1t0b0O2K250V/Screenshot.png" alt="mocha suite merging" title="" /></p><h2>Best practices</h2><h3>test/*</h3>-<p> By default <code>mocha(1)</code> will use the pattern <code>./test/*.js</code>, so- it’s usually a good place to put your tests.</p>+<p>By default <code>mocha(1)</code> will use the pattern <code>./test/*.js</code>, so+ it's usually a good place to put your tests.</p><h3>Makefiles</h3>-<p> Be kind and don’t make developers hunt around in your docs to figure+<p>Be kind and don't make developers hunt around in your docs to figureout how to run the tests, add a <code>make test</code> target to your <em>Makefile</em>:</p><pre><code> test:@@ -458,11 +480,11 @@ describe('merge stuff', function(){<h2>Editors</h2>-<p> The following editor-related packages are available:</p>+<p>The following editor-related packages are available:</p><h3>TextMate bundle</h3>-<p> The Mocha TextMate bundle includes snippets to+<p>The Mocha TextMate bundle includes snippets tomake writing tests quicker and more enjoyable.To install the bundle run:</p>@@ -471,31 +493,30 @@ describe('merge stuff', function(){<h2>Example test suites</h2>-<p> The following test suites are from real projects putting Mocha to use,+<p>The following test suites are from real projects putting Mocha to use,so they serve as good examples:</p><ul>-<li> <a href="https://github.com/visionmedia/express/tree/master/test">Express</a></li>-<li> <a href="https://github.com/senchalabs/connect/tree/master/test">Connect</a></li>-<li> <a href="https://github.com/visionmedia/superagent/tree/master/test/node">SuperAgent</a></li>-<li> <a href="https://github.com/LearnBoost/websocket.io/tree/master/test">WebSocket.io</a></li>-<li> <a href="https://github.com/visionmedia/mocha/tree/master/test">Mocha</a></li>+<li><a href="https://github.com/visionmedia/express/tree/master/test">Express</a></li>+<li><a href="https://github.com/senchalabs/connect/tree/master/test">Connect</a></li>+<li><a href="https://github.com/visionmedia/superagent/tree/master/test/node">SuperAgent</a></li>+<li><a href="https://github.com/LearnBoost/websocket.io/tree/master/test">WebSocket.io</a></li>+<li><a href="https://github.com/visionmedia/mocha/tree/master/test">Mocha</a></li></ul>+<h2>Running mocha's tests</h2>-<h2>Running mocha’s tests</h2>--<p> Run the tests:</p>+<p>Run the tests:</p><pre><code> $ make test</code></pre>-<p> Run all tests, including interfaces:</p>+<p>Run all tests, including interfaces:</p><pre><code> $ make test-all</code></pre>-<p> Alter the reporter:</p>+<p>Alter the reporter:</p><pre><code> $ make test REPORTER=list</code></pre>