使用 Visual Studio 代码在 Typescript Jasmine 测试中设置断点
Setting breakpoints in Typescript Jasmine tests with Visual Studio Code
我正在尝试在 Visual Studio 代码中设置启动配置,以便我可以调试我的单元测试。
我的测试是用 Typescript 编写的。测试和他们测试的代码被编译成一个带有源映射的 js 文件。
通过下面的配置,我可以在 js 文件中设置一个断点,并让 Visual Studio 代码在 ts 文件停止时突出显示该行。这表明 sourcemap 在某种程度上是有效的。但是,如果我在 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"
}
]
}
以下配置对我来说工作正常并允许调试 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".
希望这会有所帮助。
我已将 VS Code 更新到 0.10.9,将 Typescript 更新到 1.8.2,现在 "just works"。
我正在尝试在 Visual Studio 代码中设置启动配置,以便我可以调试我的单元测试。
我的测试是用 Typescript 编写的。测试和他们测试的代码被编译成一个带有源映射的 js 文件。
通过下面的配置,我可以在 js 文件中设置一个断点,并让 Visual Studio 代码在 ts 文件停止时突出显示该行。这表明 sourcemap 在某种程度上是有效的。但是,如果我在 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"
}
]
}
以下配置对我来说工作正常并允许调试 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".
希望这会有所帮助。
我已将 VS Code 更新到 0.10.9,将 Typescript 更新到 1.8.2,现在 "just works"。