JetBrains WebStorm Jest遇到一个意想不到的令牌



我有一个在WebStorm IDE中运行一个简单项目的问题。这是我点击run时得到的结果:

Test suite failed to run
Jest encountered an unexpected token
This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.
By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".
Here's what you can do:
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/en/configuration.html
Details:
/home/patryk/WebstormProjects/Case Converter/node_modules/hs-test-web/hstest/stage/stageTest.js:12
runner = new PureJsApplicationRunner();
^
SyntaxError: Unexpected token =
at ScriptTransformer._transformAndBuildScript (node_modules/jest/node_modules/jest-runtime/build/script_transformer.js:403:17)
at Object.<anonymous> (node_modules/hs-test-web/hstest/index.js:1:110)

此时,我的项目只包含1个html文件。我试着重新安装nodejs和npm,但没有工作

一天的好时光,我在WebStorm IDE中的一个Edu项目中遇到了同样的问题-当我按下"检查"时。按钮的任务-我有问题:"测试套件"未能运行遇到一个意想不到的符号…">

如何解决:

  1. 请检查是否安装了nodejs和npm -在IDE: FileSettings, section: Languages &框架在Nodejs和NPM章节>"节点解释器"您会发现类似于:"node/usr/bin/node"和at字段:"包管理器";npm/usr/share/npm">
  2. 在IDE中-你需要展开"项目面板"并选择查看模式"项目文件"-然后你需要打开"package.json"最初,这个文件包含以下代码:
{
"devDependencies": {
"@types/jest": "^23.3.12",
"hs-test-web": "https://github.com/hyperskill/hs-test-web/archive/release.tar.gz",
"jest": "^27.3.1",
"puppeteer": ">=8.0.0"
},
"scripts": {
"test": "jest"
}
}

您需要添加"jest"-请查收完整的包裹。json在

{
"devDependencies": {
"@types/jest": "^23.3.12",
"hs-test-web": "https://github.com/hyperskill/hs-test-web/archive/release.tar.gz",
"jest": "^27.3.1",
"puppeteer": ">=8.0.0"
},
"scripts": {
"test": "jest"
},
"jest": {
"verbose": true,
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json"
],
"transform": {
"^.+\.jsx?$": "babel-jest",
"^.+\.tsx?$": "<rootDir>/node_modules/ts-jest/preprocessor.js"
},
"transformIgnorePatterns": ["/node_modules/(?!lodash-es)"],
"testRegex": "test/.*\.spec\.ts$"
}
}

所以,我希望它能帮助你。

相关内容

  • 没有找到相关文章

最新更新