1

使用正确的调试配置文件,我可以让 VSCode 通过 Mocha 运行当前关注的文件。但是,令我沮丧的是,如果我正在处理实际代码而不是规范文件,然后按F5,它会尝试通过 Mocha 将实际代码作为规范文件运行。

所以,我的问题是;给定这样的文件结构:

Folder
    File.js
    File.spec.js

和这样的调试配置(.vscode/launch.json):

{
    // Use IntelliSense to learn about possible 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": "Unit Tests: Current File",
            "program": "${workspaceRoot}/node_modules/.bin/_mocha",
            "cwd": "${workspaceRoot}",
            "args": [
                "-u", "tdd",
                "--timeout=999999",
                "--colors",
                "--opts", "${workspaceRoot}/mocha.opts",
                "${file}"  // I want to make this dynamic
            ],
        }
    ]
}

是否可以让 VSCode 调试规范文件,无论选择规范文件(File.spec.js)还是它的主题(File.js)?

4

1 回答 1

1

您可以通过编写仅定义一个命令(例如smartFile命令)的简单扩展来引入新的动态变量。然后,您可以在启动配置中将该命令引用为${command:smartFile}.

对于命令的实现,您可以使用 VS Code 扩展 API 中可用的所有内容。因此,您不仅可以根据文件夹结构计算路径,还可以弹出 UI。例如,您可以使用 QuickPick 从所有测试列表中选择一个测试用例。

于 2018-09-19T13:56:32.130 回答