babel node_modules
simple wrapper for babel-register to make including ES6 modules easier
Installation
$ npm install --save-dev babel-node-modules
...or:
$ yarn add --dev babel-node-modules
Motivation
This is for making the process of using ES6/ES2015 modules (using import
syntax rather than CommonJS's require
style) in projects easier, especially when testing, which can be a bit of a nightmare. This is specifically for when an ES6 module has been installed via npm or yarn and resides somewhere in your node_modules/
directory.
Usage
First write your test file in ES6/ES2015, including import
ing any ES6/ES2016 modules.
test/test.js
test/node_modules/helloworld/world.js
{ return `hello !`}
test/node_modules/helloworld/package.json
test/testPolyfill.js
'helloworld' // add an array of module names here
...then run your tests:
$ mocha --require test/testPolyfill.js