![](/img/trans.png)
[英]How to configure jest-mongodb(@shelf/jest-mongodb) in typescript-node project?
[英]Error with jest config: “Preset @shelf/jest-mongodb not found.”
我有一個使用 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,但它沒有找到它。
如果有幫助,這里是預設的文檔:
這還沒有解決。
我將添加文件夾結構以查看是否有幫助:
├───.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"
我不知道為什么會解決任何問題,但我很高興它確實如此(請評論為什么會解決它)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.