Do you want to request a feature or report a bug? Bug
What is the current behavior? When I run jest, I get this error:
$ jest -c src/__tests__/jestconfig.json --no-cache
FAIL src/__tests__/test_foo.js
โ Test suite failed to run
Cannot find module '../package' from 'node-pre-gyp.js'
at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:179:17)
at Object.<anonymous> (node_modules/sqlite3/node_modules/node-pre-gyp/lib/node-pre-gyp.js:60:17)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 0.753s
Ran all test suites.
^C
Steps to reproduce:
See this repo: https://github.com/iffy/sqlite-node-jest-bug
git clone https://github.com/iffy/sqlite-node-jest-bug
cd sqlite-node-jest-bug/
yarn
yarn test
What is the expected behavior? I expect sqlite to be found/required without error. I don't know enough about jest-require and node-pre-gyp to know which library has the error. I am able to use sqlite in my electron app (non-jest).
Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.
package.json:
{
"dependencies": {
"jest": "20.0.4",
"sqlite3": "3.1.8"
},
"scripts": {
"test": "jest -c src/__tests__/jestconfig.json"
}
}
src/__tests__/jestconfig.json:
{
"rootDir": "../../",
"moduleFileExtensions": [
"js"
],
"testRegex": "test_.*\\.js$"
}
OS: macOS 10.12.4
$ yarn --version
0.24.6
$ node --version
v7.4.0
$ jest --version
v20.0.4
FWIW, if I change this line in jest-resolve/src/index.js from
const extensions = this._options.extensions.slice();
to
const extensions = this._options.extensions.slice().concat('.json');
I'm sure that's not the right place to support requiring .json, but that's the heart of the problem. Node's require supports loading .json files without an extension but jest-resolve doesn't.
So you're saying I did this to myself :) Derp. Thank you!
Most helpful comment
https://facebook.github.io/jest/docs/en/configuration.html#modulefileextensions-array-string