Skip to content

Instantly share code, notes, and snippets.

@deepak
Last active August 30, 2016 14:18
Show Gist options
  • Save deepak/c45bfefdfcf93b5a6aaea2422cdcb158 to your computer and use it in GitHub Desktop.
Save deepak/c45bfefdfcf93b5a6aaea2422cdcb158 to your computer and use it in GitHub Desktop.
How does mocha require work
my question is related to http://stackoverflow.com/questions/31326199/mocha-equivalent-to-webpacks-resolve-root
am using root paths in my app code.
webpack config snippet:
```json
const path = require('path'),
webpack = require('webpack'),
PATHS = {
app: path.join(__dirname, 'app'),
images: path.join(__dirname, 'app/images'),
css: path.join(__dirname, 'app/css'),
build: path.join(__dirname, 'build')
};
module.exports = {
// Entry accepts a path or an object of entries.
// We'll be using the latter form given it's
// convenient with more complex configurations.
entry: {
app: [
'babel-polyfill',
PATHS.app
]
},
output: {
path: PATHS.build,
publicPath: '/',
filename: '[name].js'
},
resolve: {
root: [
PATHS.app,
PATHS.images,
PATHS.css
],
extensions: ['', '.js', '.json', '.jsx']
}
}
```
after changing the NODE_PATH. my mocha tests work as well
but the imports used in my mocha tests are still relative
eg. import { attemptLogin } from '../../app/actions/action_creators';
in my mocha tests
but in the app code, i use relative to webpack root
something like
import { attemptLogin } from 'app/actions/action_creators';
how to use something similar in my mocha tests as well ?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment