Visual studio code VS代码在ES6代码上出现Mocha调试错误
我正在尝试在VS代码中调试React Redux应用程序的测试 在Jest中运行测试效果很好,但是当我运行调试器时,会出现以下错误:Visual studio code VS代码在ES6代码上出现Mocha调试错误,visual-studio-code,mocha.js,jestjs,Visual Studio Code,Mocha.js,Jestjs,我正在尝试在VS代码中调试React Redux应用程序的测试 在Jest中运行测试效果很好,但是当我运行调试器时,会出现以下错误: (function (exports, require, module, __filename, __dirname) { import * as actions from "../src/redux/actions/tasksActions";
(function (exports, require, module, __filename, __dirname) { import * as actions from "../src/redux/actions/tasksActions";
^^^^^^
SyntaxError: Unexpected token import
我在我的launch.json中使用了以下配置:
{
"type": "node",
"request": "launch",
"name": "Mocha Tests",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"args": [
"--require @babel/register",
"--inspect-brk",
"-u",
"tdd",
"--timeout",
"999999",
"--colors",
"${workspaceFolder}/tests"
],
"internalConsoleOptions": "openOnSessionStart"
}
配置中的第一个参数--require@babel/register“,--inspect brk“,
来自我在谷歌搜索错误时发现的博客上的建议(据说第一个参数修复了这个错误)。但是,无论是否使用这些参数,都会发生相同的错误
这是我的package.json
,如果有帮助的话
{
"name": "client",
"version": "0.1.0",
"private": true,
"devDependencies": {
"@babel/cli": "^7.4.4",
"@babel/core": "^7.4.4",
"@babel/node": "^7.2.2",
"@babel/preset-env": "^7.4.4",
"@babel/register": "^7.4.4",
"babel-jest": "^24.7.1",
"chai": "^4.2.0",
"enzyme": "^3.9.0",
"expect": "^24.7.1",
"jest": "^24.7.1",
"jsdom": "^15.0.0",
"mocha": "^6.1.4",
"react-addons-test-utils": "^15.6.2",
"react-scripts": "0.7.0"
},
"dependencies": {
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-redux": "^7.0.2",
"redux": "^4.0.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "jest",
"test:watch": "npm test -- --watch",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
有什么想法吗?谢谢 嗯……您使用
mocha
进行调试,但通常使用jest
运行测试,有什么原因吗?似乎您应该使用jest
将vscode配置为调试。听起来很合理。我该怎么做?这应该让你开始: