title: ReferenceError: can't find variable x when using grunt test in yeoman
body: <p>I'm using yeoman, grunt, mocha. I want to do BDD so I make basic unit test and run <code>grunt test</code> in console, which gives me <code>ReferenceError: can't find variable: Creature</code> opening test/index.html in browser works as it should.</p>
  
  <p>This is my creature.js file in app/scripts:</p>
  
  <pre><code>'use strict';
  var Creature = (function () {
      function Creature(name) {
          this.name = name;
      }
      Creature.prototype.sayHello = function (message) {
          return this.name + ' ' + message;
      };
      Creature.prototype.eat = function (item){
          return this.name + ' is eating ' + item;
      }
      return Creature;
  })();
  </code></pre>
  
  <p>This is my test/index.html</p>
  
  <pre><code>&lt;!doctype html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;meta charset="utf-8"&gt;
      &lt;meta http-equiv="X-UA-Compatible" content="IE=edge"&gt;
      &lt;title&gt;Mocha Spec Runner&lt;/title&gt;
      &lt;link rel="stylesheet" href="bower_components/mocha/mocha.css"&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;div id="mocha"&gt;&lt;/div&gt;
      &lt;script src="bower_components/mocha/mocha.js"&gt;&lt;/script&gt;
      &lt;script&gt;mocha.setup('bdd')&lt;/script&gt;
      &lt;script src="bower_components/chai/chai.js"&gt;&lt;/script&gt;
      &lt;script&gt;
          var assert = chai.assert;
          var expect = chai.expect;
          var should = chai.should();
      &lt;/script&gt;
  
      &lt;!-- include source files here... --&gt;
      &lt;script src="../app/scripts/creature.js"&gt;&lt;/script&gt;
      &lt;!-- include spec files here... --&gt;
      &lt;script src="spec/test.js"&gt;&lt;/script&gt;
  
      &lt;script&gt;mocha.run()&lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>This is my test/spec/test.js file:</p>
  
  <pre><code>/* global describe, it */
  
  (function () {
      'use strict';
  
      describe('Creature', function () {
          describe('Comunnications', function () {
              it('should say &lt;name&gt; hi', function () {
                  var creature = new Creature('test');
                  expect(creature.sayHello('hi')).to.equal('test hi');
              });
              it('should say &lt;name&gt; is eating &lt;item&gt;', function () {
                  var creature = new Creature('test');
                  expect(creature.eat('pear')).to.equal('test is eating pear');
              });
          });
      });
  })();
  </code></pre>
  
  <p>Console log:</p>
  
  <pre><code>Running "copy:styles" (copy) task
  
  Done, without errors.
  
  Running "autoprefixer:dist" (autoprefixer) task
  
  Running "connect:test" (connect) task
  Started connect web server on http://localhost:9001
  
  Running "mocha:all" (mocha) task
  Testing: http://localhost:9001/index.html
  
    ..
  
    0 passing (113ms)
    2 failing
  
    1) Creature Comunnications should say &lt;name&gt; hi:
       ReferenceError: Can't find variable: Creature
        at http://localhost:9001/spec/test.js:9
        at http://localhost:9001/bower_components/mocha/mocha.js:4263
        at http://localhost:9001/bower_components/mocha/mocha.js:4635
        at http://localhost:9001/bower_components/mocha/mocha.js:4694
        at next (http://localhost:9001/bower_components/mocha/mocha.js:4561)
        at http://localhost:9001/bower_components/mocha/mocha.js:4570
        at next (http://localhost:9001/bower_components/mocha/mocha.js:4514)
        at http://localhost:9001/bower_components/mocha/mocha.js:4538
        at timeslice (http://localhost:9001/bower_components/mocha/mocha.js:5531)
  
    2) Creature Comunnications should say &lt;name&gt; is eating &lt;item&gt;:
       ReferenceError: Can't find variable: Creature
        at http://localhost:9001/spec/test.js:13
        at http://localhost:9001/bower_components/mocha/mocha.js:4263
        at http://localhost:9001/bower_components/mocha/mocha.js:4635
        at http://localhost:9001/bower_components/mocha/mocha.js:4694
        at next (http://localhost:9001/bower_components/mocha/mocha.js:4561)
        at http://localhost:9001/bower_components/mocha/mocha.js:4570
        at next (http://localhost:9001/bower_components/mocha/mocha.js:4514)
        at http://localhost:9001/bower_components/mocha/mocha.js:4538
        at timeslice (http://localhost:9001/bower_components/mocha/mocha.js:5531)
  
  
  &gt;&gt; 2/2 tests failed (0.11s)
  Warning: Task "mocha:all" failed. Use --force to continue.
  
  Aborted due to warnings.
  
  
  Execution Time (2014-06-08 14:40:23 UTC)
  concurrent:test     3s  ■■■■■■■■■■■■■■■ 32%
  connect:test     447ms  ■■■ 5%
  mocha:all         5.9s  ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 63%
  Total 9.4s
  </code></pre>
  
  <p>Perhaps it has to do with the reference to ../app/scripts/creature.js when running through phantomjs it has a different path compared to using it in a real browser?</p>
  
  <h2>EDIT</h2>
  
  <p>It seems like <code>grunt test</code> opens the wrong path to test on. It seems to open root/index.html When it opens... I got it to work by changing the path to the creature.js (removed the <strong>app/</strong>)</p>
  
  <pre><code>&lt;!-- include source files here... --&gt;
  &lt;script src="../scripts/creature.js"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>However when running <code>grunt test</code> it now works, but opening the test/index.html file it now gives me the error <code>ReferenceError: Creature is not defined</code> in firebug console.</p>
  
  <p><strong>Do I do something wrong or is that de correct behaviour? Anything I can do to make it work both ways?</strong></p>
  
  <p>I discovered where the issue was by changing the gruntfile.js changed test:options:open to true.</p>
  
  <pre><code>// The actual grunt server settings
  
  
  connect: {
          options: {
              port: 9000,
              open: true,
              livereload: 35729,
              // Change this to '0.0.0.0' to access the server from outside
              hostname: 'localhost'
          },
          livereload: {
              options: {
                  ...
              }
          },
          test: {
              options: {
                  open: false,
                  port: 9001,
                  middleware: function(connect) {
                      return [
                          connect.static('.tmp'),
                          connect.static('test'),
                          connect().use('/bower_components', connect.static('./bower_components')),
                          connect.static(config.app)
                      ];
                  }
              }
          },
          dist: {
              ...
              }
          }
      }
  </code></pre>
  
  <p>Thanks in advance!</p>
  
  <p>Possibly related to <a href="https://stackoverflow.com/questions/20084421/running-mocha-on-the-command-line-and-including-a-file">Running Mocha on the command line and Including a file</a></p>