我正在尝试在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"
}
]
}
答案 0 :(得分:2)
以下配置对我来说很好,并允许调试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"是构建spec ts文件的文件夹。因此" outDir"设置为" dist / spec"。
希望这会有所帮助。
答案 1 :(得分:1)
我已将VS Code更新为0.10.9,将Typescript更新为1.8.2,现在“正常”。