title: Is it possible to use CommonJS modules with karma/mocha
body: <p>Is this possible with CommonJS?</p>
  
  <p>Basically I'm trying to take the API testing from <a href="http://thewayofcode.wordpress.com/2013/04/21/how-to-build-and-test-rest-api-with-nodejs-express-mocha/" rel="nofollow">http://thewayofcode.wordpress.com/2013/04/21/how-to-build-and-test-rest-api-with-nodejs-express-mocha/</a></p>
  
  <p>and use Karma to run the tests.</p>
  
  <p>I'm attempted to use RequireJS with karma, based off <a href="http://karma-runner.github.io/0.10/plus/requirejs.html" rel="nofollow">http://karma-runner.github.io/0.10/plus/requirejs.html</a></p>
  
  <p>My package.json is correctly setup and 'npm install' gets everything I need,
   but when I do 'karma start test/karma.conf.js' , no tests run</p>
  
  <pre><code>DEBUG [karma]: All browsers are ready, executing
  DEBUG [web-server]: serving: /home/npoklitar/project/node_modules/karma/static/context.html
  DEBUG [web-server]: serving: /home/npoklitar/project/node_modules/karma-requirejs/lib/require.js
  DEBUG [web-server]: serving: /home/npoklitar/project/node_modules/karma-requirejs/lib/adapter.js
  DEBUG [web-server]: serving: /home/npoklitar/project/node_modules/mocha/mocha.js
  DEBUG [web-server]: serving: /home/npoklitar/project/node_modules/karma-mocha/lib/adapter.js
  DEBUG [web-server]: serving: /home/npoklitar/project/test/routerSpec.js
  DEBUG [web-server]: serving: /home/npoklitar/project/test/test-main.js
  ERROR: 'There is no timestamp for /base/supertest.js!'
  Chrome 30.0.1599 (Linux): Executed 0 of 0 SUCCESS (0 secs / 0 secs)
  ERROR: 'There is no timestamp for /base/should.js!'
  Chrome 30.0.1599 (Linux): Executed 0 of 0 SUCCESS (0 secs / 0 secs)
  ERROR: 'There is no timestamp for /base/assert.js!'
  Chrome 30.0.1599 (Linux): Executed 0 of 0 SUCCESS (0 secs / 0 secs)
  Chrome 30.0.1599 (Linux): Executed 0 of 0 ERROR (0.355 secs / 0 secs)
  DEBUG [launcher]: Disconnecting all browsers
  DEBUG [launcher]: Killing Chrome
  </code></pre>
  
  <p>test/rounterSpec.js</p>
  
  <pre><code>require(['supertest','should','assert'], function(supertest,should,assert){
     describe('Routing:', function() {
        var url = 'http://localhost:16000';
  
        describe('API', function() {
           it('should return the success string and request headers', function(done){
             supertest(url)
               .get('/api')
               .expect(200)
               .end(function(err, res) {
                  if (err) {
                    throw err;
                   }
                   var text = res.text;
                   var splitted = text.split('!');
  
                   splitted[0].should.include('request successfully proxied to API');
                   done();
                });
            }); 
          });
       });
    });
  </code></pre>
  
  <p>test/karma.conf.js</p>
  
  <pre><code>module.exports = function (karma) {
      karma.set({
  
  // base path, that will be used to resolve files and exclude
          basePath: '../',
  
          frameworks: ['mocha','requirejs'],
  
  // list of files / patterns to load in the browser
          files: [
        //      {pattern: 'node_modules/chai/chai.js', include: true},
      //        {pattern: '*.js', include: false},
              'test/*.js',
  
              'test/test-main.js'
          ],
  
  
  // list of files to exclude
          exclude: [
              'karma.conf.js'
          ],
  
  
  // use dots reporter, as travis terminal does not support escaping sequences
  // possible values: 'dots', 'progress', 'junit', 'teamcity'
  // CLI --reporters progress
          reporters: ['progress', 'junit', 'coverage'],
  
          junitReporter: {
              // will be resolved to basePath (in the same way as files/exclude patterns)
              outputFile: 'junit-report/test-results.xml'
          },
  
          preprocessors: {
              'src/*.js': 'coverage'
          },
  
  //Code Coverage options. report type available:
  //- html (default)
  //- lcov (lcov and html)
  //- lcovonly
  //- text (standard output)
  //- text-summary (standard output)
  //- cobertura (xml format supported by Jenkins)
          coverageReporter: {
              // cf. http://gotwarlost.github.com/istanbul/public/apidocs/
              type: 'lcov',
              dir: 'coverage/'
          },
  
  
  // web server port
          port: 9876,
  
  
  // cli runner port
          runnerPort: 9100,
  
  
  // enable / disable colors in the output (reporters and logs)
          colors: true,
  
  
  // level of logging
  // possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
          logLevel: LOG_DEBUG,
  
  
  // enable / disable watching file and executing tests whenever any file changes
          autoWatch: true,
  
  
  // Start these browsers, currently available:
  // - Chrome
  // - ChromeCanary
  // - Firefox
  // - Opera
  // - Safari (only Mac)
  // - PhantomJS
  // - IE (only Windows)
  // CLI --browsers Chrome,Firefox,Safari
          browsers: ['Chrome'],
  
  
  // If browser does not capture in given timeout [ms], kill it
          captureTimeout: 6000,
  
  
  // Continuous Integration mode
  // if true, it capture browsers, run tests and exit
          singleRun: true,
  
  
          plugins: [
              'karma-mocha',
              'karma-chrome-launcher',
              'karma-firefox-launcher',
              'karma-junit-reporter',
              'karma-coverage',
              'karma-requirejs'
          ]
      });
  }
  </code></pre>
  
  <p>test/test-main.js</p>
  
  <pre><code>var tests = [];
  for (var file in window.__karma__.files) {
      if (/Spec\.js$/.test(file)) {
          tests.push(file);
      }
  }
  
  requirejs.config({
      // Karma serves files from '/base'
      baseUrl: '/base',
  /*
      paths: {
          'jquery': '../lib/jquery',
          'underscore': '../lib/underscore',
      },
  
      shim: {
          'underscore': {
              exports: '_'
          }
      },
  */
     // nodeRequire: require,  //doesnt work with or without this commented
  
      // ask Require.js to load these files (all our tests)
      deps: tests,
  
      // start test run, once Require.js is done
      callback: window.__karma__.start
  });
  </code></pre>