我的 test.js 文件包含此行,以便从 page-model.js 文件导入“Page”类: 从 './page-model' 导入页面;
当我使用命令“npm test”通过 Shell 运行 test.js 时,它运行良好。
尝试在 Visual Studio 代码上调试 Testcafe 测试时收到“意外标识符”错误。 这是完整的消息: ”
(function (exports, require, module, __filename, __dirname) { import Page from './page-model';
^^^^
SyntaxError: Unexpected identifier
at new Script (vm.js:79:7)
at createScript (vm.js:251:10)
at Object.runInThisContext (vm.js:303:10)
at Module._compile (internal/modules/cjs/loader.js:656:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
at Module.load (internal/modules/cjs/loader.js:598:32)
at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
at Function.Module._load (internal/modules/cjs/loader.js:529:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:741:12)
at startup (internal/bootstrap/node.js:285:19)
Waiting for the debugger to disconnect...
"
This are my dependencies on 'package.json' file:
"devDependencies": {
"babel-preset-es2015": "^6.24.1",
"babel-register": "^6.26.0",
"testcafe": "^0.23.1-alpha.4"
}
谢谢!
最佳答案
您的 launch.json
配置在 program
属性中指定您的测试脚本:
"program": "${workspaceRoot}/testcafe-example/test.js"
使用此配置时,Visual Studio Code 会尝试将脚本作为常规 Node.js 脚本执行,但会失败,因为 Node.js 不支持 import
语句。
在此属性中指定主要 TestCafe 脚本,如 Debug in Visual Studio Code 中所述。食谱:
"program": "${workspaceRoot}/node_modules/testcafe/bin/testcafe.js"
如果您想运行特定的测试脚本,请将 "arguments"
属性中的 "{relativePath}"
变量替换为测试脚本的路径:
"program": "${workspaceRoot}/node_modules/testcafe/bin/testcafe.js"
"args": [
"firefox",
"${workspaceRoot}/testcafe-example/test.js"
],
关于javascript - 尝试调试 TestCafe 测试时 VS 代码出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53208115/