簡體   English   中英

玩笑配置錯誤:“未找到預設 @shelf/jest-mongodb。”

[英]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,但它沒有找到它。

如果有幫助,這里是預設的文檔:

@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

我嘗試過的事情:

  • 刪除 package-lock.json 和 node_modules 文件夾,然后再次安裝包
  • 從 jest.config.js 文件中刪除除預設之外的所有內容
  • 將預設名稱更改為 node_module (./node_modules/@shelf/jest-mongodb) 的相對路徑

我變了:

"unit": "jest --config test/unit/jest.conf.js --coverage"

"unit": "jest"

我不知道為什么會解決任何問題,但我很高興它確實如此(請評論為什么會解決它)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM