title: Running Jasmine Tests from Grunt on JavaScript that uses Require
body: <p>I am writing some extensions to lodash. The code related to this question can be download from <a href="https://onedrive.live.com/redir?resid=378D4C71F3B80604%21107" rel="nofollow">here</a>. The structure is that code is located in /shared/modules/myExtensions.js. Currently, my code is very basic and looks like this:</p>
  
  <pre><code>'use strict';
  
  var _ = require('lodash');
  _.mixin({
    'myFunction' : function(s) {
      return 'Hello ' + s; 
    }
  });
  
  module.exports = _;
  </code></pre>
  
  <p>My code will grow in complexity. For that reason, I want to setup unit tests from the start on this. Right now, my tests are located at /shared/tests/myExtensions.tests.js. That file looks like this:</p>
  
  <pre><code>'use strict';
  
  describe('myModule', function() {
    it('should work', function() {
      expect(true).toBe(true);
    });
  });
  </code></pre>
  
  <p>This test always asserts to true. I'm trying to execute this Jasmine test via grunt. When I execute the this via Grunt, I get an error. The error confuses me because the grunt-jasmine-node module is defined in my package.json file. I've also checked that it got downloaded when I ran npm install. Either way, here is the error:</p>
  
  <pre><code>&gt;&gt; Local Npm module "grunt-jasmine-node" not found. Is it installed?
  
  Running "jasmine:testShared" (jasmine) task
  Testing jasmine specs via PhantomJS
  
  &gt;&gt; Error: notloaded: Module name "../" has not been loaded yet for context: _. Use require([])
  &gt;&gt; http://requirejs.org/docs/errors.html#notloaded at
  &gt;&gt; ..\..\C:\Tests\jasmine\_SpecRunner.html:21
  &gt;&gt; ..\..\C:\Tests\jasmine\.grunt\grunt-contrib-jasmine\require.js:12 v
  &gt;&gt; ..\..\C:\Tests\jasmine\.grunt\grunt-contrib-jasmine\require.js:26 h
  &gt;&gt; ..\..\C:\Tests\jasmine\.grunt\grunt-contrib-jasmine\require.js:31
  &gt;&gt; ..\..\C:\Tests\jasmine\node_modules\glob\examples\g.js:1
  &gt;&gt; Error: notloaded: Module name "../" has not been loaded yet for context: _. Use require([])
  &gt;&gt; http://requirejs.org/docs/errors.html#notloaded at
  &gt;&gt; ..\..\C:\Tests\jasmine\_SpecRunner.html:21
  &gt;&gt; ..\..\C:\Tests\jasmine\.grunt\grunt-contrib-jasmine\require.js:12 v
  &gt;&gt; ..\..\C:\Tests\jasmine\.grunt\grunt-contrib-jasmine\require.js:26 h
  &gt;&gt; ..\..\C:\Tests\jasmine\.grunt\grunt-contrib-jasmine\require.js:31
  &gt;&gt; ..\..\C:\Tests\jasmine\node_modules\glob\examples\usr-local.js:1
  &gt;&gt; ReferenceError: Can't find variable: module at
  &gt;&gt; ..\..\C:\Tests\jasmine\node_modules\glob\glob.js:37
  &gt;&gt; Error caught from PhantomJS. More info can be found by opening the Spec Runner in a browser.
  Warning: SyntaxError: Parse error Use --force to continue.
  
  Aborted due to warnings.
  </code></pre>
  
  <p>This is so frustrating. My code can be downloaded from <a href="https://onedrive.live.com/redir?resid=378D4C71F3B80604%21107" rel="nofollow">here</a>. I've been working on this for 2 days now. If I don't get it done today, I'll have to go back to .NET. Can someone please help me get this resolved? I really want to keep moving in this direction. I believe this is just something really small.</p>