【问题标题】:Setting breakpoints in Typescript Jasmine tests with Visual Studio Code使用 Visual Studio Code 在 Typescript Jasmine 测试中设置断点
【发布时间】:2015-12-20 02:14:52
【问题描述】:

我正在尝试在 Visual Studio Code 中设置启动配置,以便调试我的单元测试。

我的测试是用 Typescript 编写的。测试和他们测试的代码被编译成一个带有源映射的单个 js 文件。

通过下面的配置,我可以在 js 文件中设置断点,并让 Visual Studio Code 在 ts 文件停止时突出显示该行。这表明源地图在某种程度上正在发挥作用。但是,如果我在 ts 文件中放置断点,则会被忽略。

关于如何让 ts 文件中的断点起作用的任何想法?

{
    "version": "0.1.0",
    // List of configurations. Add new configurations or edit existing ones.
    // ONLY "node" and "mono" are supported, change "type" to switch.
    "configurations": [
        {
            // Name of configuration; appears in the launch configuration drop down menu.
            "name": "Unit tests",
            // Type of configuration. Possible values: "node", "mono".
            "type": "node",
            // Workspace relative or absolute path to the program.
            "program": "node_modules/jasmine/bin/jasmine.js",
            // Automatically stop program after launch.
            "stopOnEntry": false,
            // Command line arguments passed to the program.
            "args": ["JASMINE_CONFIG_PATH=test/script/jasmine.json"],
            // Workspace relative or absolute path to the working directory of the program being debugged. Default is the current workspace.
            "cwd": ".",
            // Workspace relative or absolute path to the runtime executable to be used. Default is the runtime executable on the PATH.
            "runtimeExecutable": null,
            // Optional arguments passed to the runtime executable.
            "runtimeArgs": ["--nolazy"],
            // Environment variables passed to the program.
            "env": { },
            // Use JavaScript source maps (if they exist).
            "sourceMaps": true,
            // If JavaScript source maps are enabled, the generated code is expected in this directory.
            "outDir": "test/script"
        }
    ]
}

【问题讨论】:

    标签: typescript visual-studio-code


    【解决方案1】:

    以下配置对我来说很好,并允许调试 jasmine 测试。 在您的 launch.json 中:

    {
        // Name of configuration; appears in the launch configuration drop down menu.
        "name": "Launch Unit Tests",
        // Type of configuration.
        "type": "node",
        // Workspace relative or absolute path to the program.
        "program": "spec/runner.ts",
        // Automatically stop program after launch.
        "stopOnEntry": false,
        // Command line arguments passed to the program.
        "args": [],
        // Workspace relative or absolute path to the working directory of the program being debugged. Default is the current workspace.
        "cwd": ".",
        // Workspace relative or absolute path to the runtime executable to be used. Default is the runtime executable on the PATH.
        "runtimeExecutable": null,
        // Optional arguments passed to the runtime executable.
        "runtimeArgs": ["--nolazy"],
        // Environment variables passed to the program.
        "env": {
            "NODE_ENV": "development"
        },
        // Use JavaScript source maps (if they exist).
        "sourceMaps": true,
        // If JavaScript source maps are enabled, the generated code is expected in this directory.
        "outDir": "dist/spec",
        "request": "launch"
    }
    

    runner.ts如下:

    'use strict';
    
    var Jasmine = require('jasmine');
    var j = new Jasmine();
    
    j.loadConfigFile('spec/support/jasmine.json');
    j.configureDefaultReporter({
        showColors: true
    });
    j.execute();
    

    项目文件结构为:

    -spec
    --runner.ts
    --support
    ----jasmine.json
    --folderWithTests1
    -dist
    --spec
    .....
    

    注意 - “dist”是构建规范文件的文件夹。因此“outDir”设置为“dist/spec”。

    希望这会有所帮助。

    【讨论】:

      【解决方案2】:

      我已将 VS Code 更新为 0.10.9,将 Typescript 更新为 1.8.2,这现在“正常工作”。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-10-14
        • 1970-01-01
        • 2023-03-17
        • 2017-01-07
        • 2020-05-09
        • 2017-05-29
        • 2018-10-16
        • 1970-01-01
        相关资源
        最近更新 更多