我有一个使用 jest 的项目,我可以用 npm test
运行 jest如果我不设置预设,它就可以工作。
我需要预设@shelf/jest-mongodb
,我得到了这篇文章标题中的错误。
这是我的 jest.config.js:
const path = require('path')
module.exports = {
preset: '@shelf/jest-mongodb',
rootDir: path.resolve(__dirname),
testMatch: ['<rootDir>\\test\\unit\\specs\\**.js'],
moduleFileExtensions: [
'js',
'json',
'vue'
],
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1'
},
transform: {
'^.+\\.js$': '<rootDir>/node_modules/babel-jest',
'.*\\.(vue)$': '<rootDir>/node_modules/vue-jest'
},
testPathIgnorePatterns: [
'<rootDir>/test/e2e',
'<rootDir>/test/unit/specs/bundle'
],
snapshotSerializers: ['<rootDir>/node_modules/jest-serializer-vue'],
setupFiles: ['<rootDir>/test/unit/setup'],
coverageDirectory: '<rootDir>/test/unit/coverage',
collectCoverageFrom: [
'src/**/*.{js,vue}',
'!src/main.js',
'!src/router/index.js',
'!**/node_modules/**'
],
verbose: true,
testURL: 'http://localhost/'
}
我想重申,如果我删除“预设”选项,测试将按预期运行。我已经尝试了在“预设”字段中我能想到的所有字符组合,以使其找到 node_module,但它没有找到它。
如果有帮助,这里是预设的文档:
@shelf/jest-mongodb
这还没有解决。
我将添加文件夹结构以查看是否有帮助:
├───.vscode
├───build
├───config
├───node_modules
├───@shelf
│ └───jest-mongodb
│ ├───.circleci
│ └───node_modules
│ ├───.bin
│ ├───.cache
│ │ └───mongodb-memory-server
│ │ └───mongodb-binaries
│ ├───agent-base
│ │ ├───dist
│ │ │ └───src
│ │ ├───node_modules
│ │ │ ├───debug
│ │ │ │ └───src
│ │ │ └───ms
│ │ └───src
│ ├───camelcase
│ ├───cross-spawn
│ │ ├───lib
│ │ │ └───util
│ │ └───node_modules
│ │ └───.bin
│ ├───debug
│ │ ├───dist
│ │ └───src
│ ├───find-cache-dir
│ ├───find-up
│ ├───https-proxy-agent
│ │ ├───dist
│ │ └───node_modules
│ │ ├───debug
│ │ │ └───src
│ │ └───ms
│ ├───locate-path
│ ├───lru-cache
│ ├───mkdirp
│ │ ├───bin
│ │ └───lib
│ ├───mongodb-memory-server
│ ├───mongodb-memory-server-core
│ │ ├───lib
│ │ │ ├───util
│ │ │ │ ├───getos
│ │ │ │ └───__tests__
│ │ │ └───__tests__
│ │ ├───node_modules
│ │ │ ├───.bin
│ │ │ ├───debug
│ │ │ │ └───src
│ │ │ ├───ms
│ │ │ └───uuid
│ │ │ └───dist
│ │ │ ├───bin
│ │ │ ├───esm-browser
│ │ │ ├───esm-node
│ │ │ └───umd
│ │ └───scripts
│ ├───ms
│ ├───p-limit
│ ├───p-locate
│ ├───p-try
│ ├───path-exists
│ ├───path-key
│ ├───pkg-dir
│ ├───semver
│ │ ├───bin
│ │ ├───classes
│ │ ├───functions
│ │ ├───internal
│ │ └───ranges
│ ├───shebang-command
│ ├───shebang-regex
│ ├───uuid
│ │ └───dist
│ │ ├───bin
│ │ ├───esm-browser
│ │ ├───esm-node
│ │ └───umd
│ ├───which
│ │ └───bin
│ └───yallist
├───src
│ ├───assets
│ ├───backend
│ │ ├───models
│ │ └───routes
│ ├───components
│ └───router
└───test
├───e2e
│ ├───custom-assertions
│ └───specs
└───unit
├───coverage
│ └───lcov-report
│ ├───backend
│ │ ├───models
│ │ └───routes
│ └───components
└───specs
package.json、jest-mongodb-config.js 和 jest.config.js 都位于目录的根目录下。测试位于 test/unit/specs我尝试过的事情:
最佳答案
我变了:
"unit": "jest --config test/unit/jest.conf.js --coverage"
至"unit": "jest"
我不知道为什么会解决任何问题,但我很高兴它确实如此(请评论为什么会解决它)
关于javascript - 开 Jest 配置错误 : "Preset @shelf/jest-mongodb not found.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66833681/