jcalfee314 jcalfee314 - 11 months ago 162
Javascript Question

mocha equivalent to webpack's resolve root

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
which in turn reads this entry from
config.resolve.root: [path.resolve(__dirname, "./app")]
so it knows to find

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...

Answer Source

How about including your app directory in $NODE_PATH:

env NODE_PATH=$NODE_PATH:$PWD/app mocha ...