title: npm + Mocha + RequireJS
body: <p>I'm having quite the time trying to set up node/npm with Mocha and RequireJS.  Here's what I've done.</p>
  
  <p>I've created a testing/ directory, with this structure:</p>
  
  <pre><code>testing/
     |
     +-- package.json
     |
     +-- README.md
     |
     +-- test/
           |
           +-- mocha.opts
           |
           +-- widgets/
                  |
                  +--mywidget/
                         |
                         +-- test.js
  </code></pre>
  
  <p>Here is what each relevant file contains:</p>
  
  <p>package.json:</p>
  
  <pre><code>{
      "name":"testing-project",
      "version":"2.5.0",
      "description":"Testing Project",
      "keywords":["test"],
      "engines": { "node": "&gt;= 0.7.0 &lt; 0.11.0" },
      "scripts" : {
          "test": "./node_modules/.bin/mocha"
      },
      "devDependencies": {
          "mocha": "&gt;= 1.18.2",
          "requirejs": "&gt;= 2.1.11",
          "should": "&gt;= 3.2.0",
          "expect.js": "&gt;= 0.3.1"
      }
  }
  </code></pre>
  
  <p>test/mocha.opts:</p>
  
  <pre><code>--require expect.js
  --require should
  --require requirejs
  --require mocha
  --reporter spec
  --ui tdd
  --recursive
  --growl
  </code></pre>
  
  <p>test/widgets/mywidget/test.js</p>
  
  <pre><code>'use strict';
  var requirejs = require('requirejs');
  // Also tried with:  require('../../../r.js')  which I downloaded from RequireJS' site
  
  requirejs.config({
      baseUrl: '../../../../',
      nodeRequire: require
  });
  
  console.log('before require');
  requirejs(['mywidget/trunk/src/mywidgetfile.js'], function(myObj){
      console.log('after require');
  
      var expect = require('expect.js');
  
      // Instead of the above "requirejs['mywidget..." line, I've also tried:
      // var myObj = requirejs('mywidget/trunk/src/mywidgetfile.js');   AND:
      // var myObj = requirejs('../../../../mywidget/trunk/src/mywidgetfile.js');
  
      describe('My Widget', function(){
          describe('my-widget#getInfo', function(){
  
              it('should pass this test', function(done){
                  expect( myObj.returnString('test') ).to.equal( 'test' );
  
                  done();
              })
          })
      });
  });
  console.log('done');
  </code></pre>
  
  <p>It will output the console lines "before require" and "done", but as long as I have the requirejs(['mywidget...  line in, it will not hit the after require.  If I remove the requirejs line (and the corresponding closing brace/paren line), and instead use the direct "var myObj =" line, I get "cannot find module", and if I use the second "var myObj" line, I get "Reference Error: define is not defined".</p>
  
  <p>I'm trying to package this all, for convenience for other developers, with npm, such that I'm running the command "npm test" from within the top "testing/" directory.</p>
  
  <p>I've been scouring for answers and trying so many things, but I can't seem to require a file using RequireJS and have "define()" defined.  I can execute tests, that's not a problem... it's just trying to insert RequireJS into the mix that is when I start having the issues.</p>
  
  <p>Any help would be tremendous!</p>
  
  <p>Thank you!</p>