title: Running Mocha 6 ES6 tests with Babel 7, how to set up?
body: <p>For a library written in ES6/7, I want to compile (to ES5) the library to a dist/ folder. I also want to run the tests (written in ES6/7) for this lib.</p>
  
  <p>My dev dependencies look like this (package.json):</p>
  
  <pre><code>"devDependencies": {
    "@babel/cli": "^7.4.4",
    "@babel/core": "^7.4.5",
    "@babel/preset-env": "^7.4.5",
    "@babel/register": "^7.4.4",
    "chai": "^4.2.0",
    "mocha": "^6.1.4",
    "sinon": "^7.3.2"
  },
  </code></pre>
  
  <p>My build and test scripts looks like this (package.json):</p>
  
  <pre><code>"scripts": {
    "test": "mocha --require @babel/register",
    "build": "babel src -d dist --presets=@babel/preset-env"
  },
  </code></pre>
  
  <p>Running <code>npm run build</code> works well. The dist/ folder gets populated with transpiled files.</p>
  
  <p>Running <code>npm run test</code> does not seem to work - this is my problem.</p>
  
  <pre><code>&gt; mocha --require @babel/register
  
  /Users/dro/Repos/lib/node_modules/yargs/yargs.js:1163
        else throw err
             ^
  
  ReferenceError: regeneratorRuntime is not defined
  </code></pre>
  
  <p><em>Initially I got an import error, which was resolved by adding .babelrc file.</em></p>
  
  <p>Below is my .babelrc file content.</p>
  
  <pre><code>{
    "presets": ["@babel/preset-env"]
  }
  </code></pre>
  
  <p>I was reading about <code>regeneratorRuntime</code> and it got me to <a href="https://babeljs.io/docs/en/babel-polyfill" rel="noreferrer">this link about babel-polyfill</a> where they explain I shouldn't need that polyfill.</p>
  
  <blockquote>
    <p>This will emulate a full ES2015+ environment (no &lt; Stage 4 proposals) and is intended to be used in an application rather than a library/tool.</p>
  </blockquote>
  
  <p>What is needed to set this up properly?</p>
  
  <hr>
  
  <p>I am not using webpack.</p>