I'm writing some mocha tests that load code that have paths like this:
import MyStore from "stores/MyStore"
This works fine in the web browser because we are using the webpack-dev-server
which in turn reads this entry from webpack.config.js
: config.resolve.root: [path.resolve(__dirname, "./app")]
so it knows to find ./app/stores/MyStore
.
This path does not work when running it from mocha --compilers js:babel/register
. I'm trying to locate a package or configuration that I may use for this. It would save us from having to change may code references and of course keep our imports more portable.
Not sure if it matters, we use iojs. If this really can't be done it would be fine just to update the paths. Thank you...
I'm writing some mocha tests that load code that have paths like this:
import MyStore from "stores/MyStore"
This works fine in the web browser because we are using the webpack-dev-server
which in turn reads this entry from webpack.config.js
: config.resolve.root: [path.resolve(__dirname, "./app")]
so it knows to find ./app/stores/MyStore
.
This path does not work when running it from mocha --compilers js:babel/register
. I'm trying to locate a package or configuration that I may use for this. It would save us from having to change may code references and of course keep our imports more portable.
Not sure if it matters, we use iojs. If this really can't be done it would be fine just to update the paths. Thank you...
Share Improve this question edited Jul 10, 2015 at 6:22 Felix Kling 816k180 gold badges1.1k silver badges1.2k bronze badges asked Jul 9, 2015 at 19:08 jcalfee314jcalfee314 4,8309 gold badges46 silver badges77 bronze badges 1- That's a non-standard webpack feature, it probably won't work easily in Node. Why not use standard relative paths? – loganfsmyth Commented Jul 9, 2015 at 20:00
3 Answers
Reset to default 13How about including your app
directory in $NODE_PATH
:
env NODE_PATH=$NODE_PATH:$PWD/app mocha ...
Here's a cross-platform method. First install cross-env
:
npm install cross-env --save-dev
then in your package.json
:
"scripts": {
...
"test": "cross-env NODE_PATH=./app mocha ..."
}
In windows, I had to do this:
set NODE_PATH=%CD%/app&& mocha...
for some reason, adding a space after 'app' would cause it not to work