首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用Visual Studio代码调试CucumberJS脚本

如何使用Visual Studio代码调试CucumberJS脚本
EN

Stack Overflow用户
提问于 2017-05-10 03:52:37
回答 2查看 4.4K关注 0票数 6

我正在使用Visual Studio代码构建cucumberjs测试。我能够从命令行使用npm运行测试,并且能够使用启动配置从VS Code中运行它们。

但是,我无法从Visual Studio代码中调试该测试。这是在装有VSCode 1.12.1的Windows7上

基本文件结构:

代码语言:javascript
复制
.
+-- .vscode
|   +-- launch.json
+-- features
|   +-- step_definitions
|   |   +-- sampleSteps.js
|   +-- support
|   |   +-- customWorld.js
|   +-- sampletest.feature
+-- node_modules
|   +-- .bin
|   |   +-- cucumberjs
+-- package.json
+-- README.md

在package.json中,我有以下内容:

代码语言:javascript
复制
  "scripts": {
    "test": "./node_modules/.bin/cucumberjs"
  },

在命令行中,我可以成功地运行npm testnpm run-script test。我有一个如下的launch.json配置:

代码语言:javascript
复制
{
    // Use IntelliSense to learn about possible Node.js debug attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Launch via NPM",
            "runtimeExecutable": "npm",
            "windows": {
                "runtimeExecutable": "npm.cmd"
            },
            "runtimeArgs": [
                "run-script",
                "test"
            ]
        }
    ]
}

当我在VS Code中运行调试器时,它只是运行测试,给出结果,但不支持断点。

我希望能够单步执行我的代码,而launch.json似乎就是这样做的工具。我尝试过直接从launch.json调用cucumber,但在这种情况下,它似乎找不到所有正确的文件(包括cucumberjs)。

EN

回答 2

Stack Overflow用户

发布于 2017-06-21 03:03:33

我能够用这个launch.json让它工作:

代码语言:javascript
复制
{
    // Use IntelliSense to learn about possible Node.js debug attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Via NPM",
            "runtimeExecutable": "npm",
            "windows": {
                "runtimeExecutable": "npm.cmd"
            },
            "env":{
               "NODE_PATH": "test/"
            },
            "runtimeArgs": [
                "run-script",
                "debug"
            ],
            "port": 5858
        }
    ]
}

然后在package.json中:

代码语言:javascript
复制
"scripts": {
    "debug": "node --debug-brk=5858 ./node_modules/cucumber/bin/cucumber.js --profile TEST -t '@my_tag'"
}

希望这能有所帮助!(请注意,这是在MacOS上完成的)

票数 3
EN

Stack Overflow用户

发布于 2020-08-20 14:08:29

或者只需在Windows10/ VSCode中使用它

launch.json

代码语言:javascript
复制
 {
     "type": "node",
     "request": "launch",
     "name": "Cucumber Tests",
     "program": "${workspaceRoot}/node_modules/cucumber/bin/cucumber-js",
     "internalConsoleOptions": "openOnSessionStart",
 }

或者,如果是Mac OS,请将程序替换为以下内容

代码语言:javascript
复制
"program": "${workspaceRoot}/node_modules/.bin/cucumber-js",

您不需要在package.json

中添加scripts

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43878772

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档