i had to change
exports.version = require('./package').version;
to
exports.version = require('./package.json').version;
in
https://github.com/cheeriojs/cheerio/blob/master/index.js
Otherwise i got this error
Using Jest CLI v0.9.2, jasmine2, babel-jest
FAIL __tests__/components/CoolComponent.js
โ Runtime Error
Error: Cannot find module './package' from 'index.js'
at Loader._resolveNodeModule (/home/nils/Programmering/relay/phoenix-hipster-stack/node_modules/jest-cli/src/HasteModuleLoader/HasteModuleLoader.js:431:11)
at Object.<anonymous> (/home/nils/Programmering/relay/phoenix-hipster-stack/node_modules/cheerio/index.js:11:19)
at Object.<anonymous> (/home/nils/Programmering/relay/phoenix-hipster-stack/node_modules/enzyme/build/ReactWrapper.js:13:16)
Running Ubuntu 15.10
If you are using webpack, you can work around this issue by putting in the following plugin configuration:
plugins: [
// other plugins that you need
new NormalModuleReplacementPlugin(/^\.\/package$/, function(result) {
if(/cheerio/.test(result.context)) {
result.request = "./package.json"
}
})
]
This looks for any require("./package") in the cheerio module path, and replaces it with require("./package.json")
It's also possible to work around this with Jest's configuration:
//package.json
"jest": {
"moduleFileExtensions": [
"json"
]
}
Most helpful comment
It's also possible to work around this with Jest's configuration: