gpt4 book ai didi

jestjs - 试图运行 jest 的 jest 版本不正确

转载 作者:行者123 更新时间:2023-12-05 07:19:12 29 4
gpt4 key购买 nike

我在我的角度项目中进行了 Jest 测试。

我有一个 package.json 文件指定了我想用来运行测试的 jest 版本。该文件包括:

"@types/jest": "^24.0.18",
"jest": "^24.9.0",
"jest-preset-angular": "^7.1.1",

jest 配置还包括:

"setupFilesAfterEnv": [
"<rootDir>/setup-jest.ts"
],

这就是问题发生的地方。尝试运行 jest 时,我收到以下消息:

● Validation Warning:

Unknown option "setupFilesAfterEnv" with value ["<rootDir>/setup-jest.ts"] was found.
This is probably a typing mistake. Fixing it will remove this message.

Configuration Documentation:
https://jestjs.io/docs/configuration.html

我查看了 jest -h 并找到了一个标志,它为我提供了 jest 环境的设置。

jest --showConfig

然而,这表明我在版本上运行 jest

"version": "23.6.0"

所以我的问题就在这里。为什么在我执行 npm i 之后,尝试运行测试的 jest 版本不同/旧。

我尝试使用 -g 标志和 save-dev 标志安装 jest-cli。

还尝试在 VS Code 中运行测试,如果有帮助的话。

请帮忙。

提前谢谢你。

npx jest --showConfig 的完整日志

● Validation Warning:

Unknown option "setupFilesAfterEnv" with value ["<rootDir>/setup-jest.ts"] was found.
This is probably a typing mistake. Fixing it will remove this message.

Configuration Documentation:
https://jestjs.io/docs/configuration.html

{
"configs": [
{
"automock": false,
"browser": false,
"cache": true,
"cacheDirectory": "/var/folders/bs/wrvrgl6132df8l5ndxv40m3m0000gn/T/jest_dx",
"clearMocks": false,
"coveragePathIgnorePatterns": [
"/node_modules/",
"setup-jest.ts"
],
"detectLeaks": false,
"detectOpenHandles": false,
"errorOnDeprecated": false,
"filter": null,
"forceCoverageMatch": [],
"globals": {
"ts-jest": {
"tsConfig": "<rootDir>/tsconfig.spec.json",
"stringifyContentPathRegex": "\\.html$",
"astTransformers": [
"jest-preset-angular/InlineHtmlStripStylesTransformer"
]
}
},
"haste": {
"providesModuleNodeModules": []
},
"moduleDirectories": [
"node_modules"
],
"moduleFileExtensions": [
"ts",
"html",
"js",
"json"
],
"moduleNameMapper": [
[
"@app/(.*)",
"/Users/name/Projects/project/src/app/$1"
],
...
],
"modulePathIgnorePatterns": [],
"name": "6caa4...",
"prettierPath": "/Users/name/Projects/project/node_modules/prettier/index.js",
"resetMocks": false,
"resetModules": false,
"resolver": null,
"restoreMocks": false,
"rootDir": "/Users/name/Projects/project",
"roots": [
"/Users/name/Projects/project"
],
"runner": "jest-runner",
"setupFiles": [],
"setupTestFrameworkScriptFile": null,
"skipFilter": false,
"snapshotSerializers": [],
"testEnvironment": "/Users/name/Projects/project/node_modules/jest-environment-jsdom-thirteen/build/index.js",
"testEnvironmentOptions": {},
"testLocationInResults": false,
"testMatch": [
"**/__tests__/**/*.js?(x)",
"**/?(*.)+(spec|test).js?(x)"
],
"testRegex": "",
"testRunner": "/Users/name/node_modules/jest-jasmine2/build/index.js",
"testURL": "http://localhost",
"timers": "real",
"transform": [
[
"^.+\\.(ts|js|html)$",
"/Users/name/Projects/project/node_modules/ts-jest/dist/index.js"
]
],
"watchPathIgnorePatterns": []
}
],
"globalConfig": {
"bail": false,
"changedFilesWithAncestor": false,
"collectCoverage": true,
"collectCoverageFrom": null,
"coverageDirectory": "/Users/name/Projects/project/coverage",
"coverageReporters": [
"json",
"text",
"lcov",
"clover"
],
"coverageThreshold": null,
"detectLeaks": false,
"detectOpenHandles": false,
"errorOnDeprecated": false,
"expand": false,
"filter": null,
"globalSetup": null,
"globalTeardown": null,
"listTests": false,
"maxWorkers": 7,
"noStackTrace": false,
"nonFlagArgs": [],
"notify": false,
"notifyMode": "always",
"passWithNoTests": false,
"projects": null,
"rootDir": "/Users/name/Projects/project",
"runTestsByPath": false,
"skipFilter": false,
"testFailureExitCode": 1,
"testPathPattern": "",
"testResultsProcessor": null,
"updateSnapshot": "new",
"useStderr": false,
"verbose": null,
"watch": false,
"watchman": true
},
"version": "23.6.0"
}

此处也显示 npm config get 日志:

; cli configs
metrics-registry = "http://.../.../npm-group/"
scope = ""
user-agent = "npm/6.9.0 node/v10.15.3 darwin x64"

; project config /Users/user/Projects/project/.npmrc
registry = "http://.../.../npm-group/"

; node bin location = /Users/user/.nvm/versions/node/v10.15.3/bin/node
; cwd = /Users/user/Projects/project
; HOME = /Users/user
; "npm config ls -l" to show all defaults.

最佳答案

我遇到了同样的问题,经过长时间的搜索我尝试了这个:

type jest

哪个给了我位置:

/usr/local/bin/jest

重命名此文件(或删除它),解决了问题(注意现在运行 jest 将给出 command not found)。

关于jestjs - 试图运行 jest 的 jest 版本不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57886882/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com