Setting breakpoints in Typescript Jasmine tests with Visual Studio Code

前端 未结 2 1228
终归单人心
终归单人心 2021-02-08 15:13

I am trying to set up a launch configuration in Visual Studio Code so that I can debug my unit tests.

My tests are written in Typescript. The tests and the code they tes

2条回答
  •  粉色の甜心
    2021-02-08 15:44

    The following configuration works fine for me and allow to debug jasmine tests. In your 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"
    }
    

    The runner.ts is as follows:

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

    The project file structure is:

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

    Note - "dist" is the folder where spec ts files are built to. Therefore "outDir" is set to "dist/spec".

    Hope this will help.

提交回复
热议问题