2015-09-22 20 views
9

Tôi đang cố gắng thiết lập cấu hình khởi chạy trong Visual Studio Code để tôi có thể gỡ lỗi các bài kiểm tra đơn vị của mình.Thiết lập các điểm ngắt trong các thử nghiệm Jasmine Loại với Visual Studio Code

Bài kiểm tra của tôi được viết bằng Loại. Các bài kiểm tra và mã họ kiểm tra được biên dịch thành một tệp js duy nhất với một bản đồ nguồn.

Với cấu hình bên dưới, tôi có thể đặt điểm ngắt trong tệp js và có Mã Visual Studio làm nổi bật dòng trong tệp ts khi nó dừng. Điều này cho thấy rằng sourcemap đang hoạt động ở một mức độ nào đó. Tuy nhiên nếu tôi đặt một breakpoint trong một tập tin ts sau đó nó được bỏ qua.

Bất kỳ ý tưởng nào về cách tôi có thể nhận điểm ngắt trong tệp ts để hoạt động?

{ 
    "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" 
     } 
    ] 
} 

Trả lời

1

Tôi đã cập nhật mã VS thành 0.10.9 và Typecript thành 1.8.2 và bây giờ "chỉ hoạt động".

2

Cấu hình sau hoạt động tốt cho tôi và cho phép gỡ lỗi kiểm tra hoa nhài. Trong launch.json của bạn:

{ 
    // 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" 
} 

Các runner.ts là như sau:

'use strict'; 

var Jasmine = require('jasmine'); 
var j = new Jasmine(); 

j.loadConfigFile('spec/support/jasmine.json'); 
j.configureDefaultReporter({ 
    showColors: true 
}); 
j.execute(); 

Cấu trúc tập tin dự án là:

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

Note - "dist" là thư mục nơi tập tin ts cụ thể được xây dựng. Do đó "outDir" được đặt thành "dist/spec".

Hy vọng điều này sẽ hữu ích.

Các vấn đề liên quan