[英]react storybook jest snapshots leads to an error Cannot find module '../../package' from 'node.js'
I want to combine storybooks and jest snapshot testing, but I don't get it working. 我想结合故事书和开玩笑快照测试,但我没有让它工作。 As soon as I follow the doc and add the Snapshot.test.js, it leads to following error, when I run npm test.
一旦我按照文档添加Snapshot.test.js,当我运行npm test时,它会导致跟随错误。
FAIL ./Storyshots.test.js Test suite failed to run
Cannot find module '../../package' from 'node.js'
at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:169:17)
at Object.<anonymous> (node_modules/babel-core/lib/api/node.js:60:16)
anyone has a clue / hint if this is a failure of implementation or a bug? 任何人都有线索/提示,如果这是实施失败或错误? thnx a lot!
thnx很多!
this is my jest configuration, it my gives a hint? 这是我的开玩笑配置,我给出了一个提示?
"jest": {
"rootDir": "",
"transform": {
".*": "<rootDir>/node_modules/babel-jest"
},
"moduleFileExtensions": [
"js",
"jsx"
],
"collectCoverage": false,
"collectCoverageFrom": [
"**/*.{js,jsx}",
"!**/node_modules/**",
"!**/vendor/**"
],
"coverageDirectory": "<rootDir>/coverage",
"setupTestFrameworkScriptFile": "<rootDir>/jestSetup.js",
"unmockedModulePathPatterns": [
"<rootDir>/node_modules/react",
"<rootDir>/node_modules/react-dom",
"<rootDir>/node_modules/react-addons-test-utils",
"moment",
"jasmine-expect-jsx",
"fbjs",
"enzyme",
"expect",
"cheerio",
"htmlparser2",
"lodash",
"domhandler",
"object.assign",
"define-properties",
"function-bind",
"object-keys",
"object.values",
"es-abstract"
]
},
I had this same problem and my solution was add "json" into "moduleFileExtensions", just like this: 我有同样的问题,我的解决方案是将“json”添加到“moduleFileExtensions”中,就像这样:
...
"moduleFileExtensions": [
"js",
"jsx",
"json"
],
...
Seems like the file 'package' was not a js[x] file, but a json one, and jest refused to load it. 好像文件'package'不是js [x]文件,而是json文件,而jest拒绝加载它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.