title: Karma unit test for ES6 modules with babel
body: <p>I'm following instructions from <a href="https://github.com/babel/karma-babel-preprocessor" rel="nofollow noreferrer">karma-babel-preprocessor</a> to set up unit tests in a project I'm currently working, but I always the error</p>
  
  <p>'require is not defined'</p>
  
  <p>My karma.conf.js is as follows:</p>
  
  <pre><code>files: [
     { pattern: './test/unit/*.spec.js', watched: true },
     { pattern: './src/js/es6_modules/*.js', watched: false },
  ],
  
  preprocessors: {
      './src/js/es6_modules/*.js': ['babel'],
      './test/unit/*.spec.js': ['babel'] //, 'coverage'
  },
  
  babelPreprocessor: {
    options: {
      presets: ['es2015'],
      sourceMap: 'inline'
    },
    filename: function (file) {
      return file.originalPath.replace(/\.js$/, '.es5.js');
    },
    sourceFileName: function (file) {
      return file.originalPath;
    }
  }
  </code></pre>
  
  <p>The scripts in src/js/es6_modules jave ES6 classes exported. Something like:</p>
  
  <pre><code>export default class MyClass {
  
  }
  </code></pre>
  
  <p>And my spec file would need to import this</p>
  
  <pre><code>import { MyClass } from "../../src/js/es6_modules/myclass";
  </code></pre>
  
  <p>I have seen some thread here at SO that said I would need to use browserify, but I can't find any doc (or example) on how to use it together with babel in karma. Does anyone know to configure this properly?</p>