I am trying to pass along a configuration file to Jest in order to run tests only from a given directory.
According to documentation, you can use config.testPathDi
As of the current date of October 5, 2018, I was able to setup a jest configuration file with ease, without it requiring it to be in JSON format.
My package.json scripts section:
"scripts": {
"start": "node server.js",
"dev": "webpack-dev-server --hot --inline",
"test": "jest --config ./jest-config.js",
"build": "webpack",
"postinstall": "webpack"
}
I decided to keep the jest-config file in the root path alongside package.json, so that's where it is pointing to, but you can put it anywhere you want. Here is the configuration file, albeit a little short:
module.exports = {
verbose: true,
setupTestFrameworkScriptFile: "./enzyme.js",
roots: [
"../__tests__"
],
modulePaths: [
"./__stubs__"
],
moduleNameMapper: {
".scss$": "scss-stub.js"
}
}
The Jest documentation in the "Configuring Jest" section (link here) says that you can create it with a module.exports object. They include a caveat that says, "Please keep in mind that the resulting configuration must be JSON-serializable", which adds to the confusion. "Delightful Javascript Testing!" Hah!
P.S. The roots property in the config tells Jest where to look for all of your tests. Thought it might help.