How to add a directory to Node path before the tests are run?

253 views
Skip to first unread message

Volkan Unsal

unread,
Dec 3, 2014, 4:42:01 PM12/3/14
to jes...@googlegroups.com
In my webpack config file, I have the following configuration option that resolves all modules to a few common root paths where they might be found:

resolve: {
    // you can now require('file') instead of require('file.coffee')
    extensions: ['', '.js', '.json', '.coffee'],
    // Now you can require('file') instead of require('../../file')
    root: [__dirname + '/assets', path.join(__dirname, 'vendor/assets/components')]
  },

This allows me to use absolute paths in my require() calls. How would I be able to replicate the same feature with jest? I have looked at the setupEnvScriptFile configuration option. Here are the content of my configuration block and the testSetup.js file:

# package.json
"jest": {
    "globals": {
      "__DEV__": true
    },
    "setupEnvScriptFile": "script/testSetup2.js",
    "scriptPreprocessor": "script/preprocessor.js",
    "testFileExtensions": ["coffee", "js"],
    "unmockedModulePathPatterns": ["<rootDir>/node_modules/react"]
  }

# testSetup.js
process.env.NODE_PATH = __dirname + "/assets";



This doesn't work for me for whatever reason. What am I doing wrong?

Volkan Unsal

unread,
Dec 3, 2014, 4:44:58 PM12/3/14
to jes...@googlegroups.com
By the way, note the filename is different for testScript.js file in config block. I was just testing something there.
Reply all
Reply to author
Forward
0 new messages