简体   繁体   English

使用 VSCode 调试 Typescript 量角器测试

[英]Debug Typescript protractor tests with VSCode

I have angular app with e2e tests in typescript and i want to run debug in VSCode.我在打字稿中有 e2e 测试的 angular 应用程序,我想在 VSCode 中运行调试。 I went to read.me to see how to run debug and it was easy.我去read.me看看如何运行调试,这很容易。 But my problem is that breakpoint in typescript tests is not stopping.但我的问题是打字稿测试中的断点并没有停止。 As I see i have sourcemap problem which are not generated.正如我所见,我有未生成的源映射问题。

tsconfig.json配置文件

{
  "compileOnSave": true,
  "compilerOptions": {
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "target": "es5",
    "typeRoots": [
      "../node_modules/@types"
    ]
  }
}

launch.json启动文件

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch",
            "type": "node",
            "request": "launch",
            "program": "${workspaceRoot}/node_modules/protractor/bin/protractor",
            "stopOnEntry": false,
            "sourceMaps": true,
            "cwd": "${workspaceRoot}",
            "args": [
                "${workspaceRoot}/protractor.conf.js"
            ]
        }
    ]
}

protractor.conf.js量角器配置文件

// Protractor configuration file, see link for more information
// https://github.com/angular/protractor/blob/master/docs/referenceConf.js

/*global jasmine */
var SpecReporter = require('jasmine-spec-reporter');

exports.config = {
  allScriptsTimeout: 11000,
  specs: [
    './e2e/**/*.e2e-spec.ts'
  ],
  capabilities: {
    'browserName': 'chrome'
  },
  directConnect: true,
  baseUrl: 'http://localhost:4200/',
  framework: 'jasmine',
  jasmineNodeOpts: {
    showColors: true,
    defaultTimeoutInterval: 30000,
    print: function() {}
  },
  useAllAngular2AppRoots: true,
  beforeLaunch: function() {
    require('ts-node').register({
      project: 'e2e'
    });
  },
  onPrepare: function() {
    jasmine.getEnv().addReporter(new SpecReporter());
  }
};

As i understand ts-node is compiling ts to js and probably its not generation sourcemap or they are stored in somespecific location据我了解,ts-node 正在将 ts 编译为 js,并且可能不是生成源映射,或者它们存储在某个特定位置

What I am doing wrong?我做错了什么?

Looks like Protractor is calling into source-map-support itself, which is overriding the call that ts-node makes.看起来 Protractor 正在调用source-map-support本身,它覆盖了ts-node发出的调用。

Try enabling the skipSourceMapSupport option in your protractor.conf.js.尝试在skipSourceMapSupport中启用skipSourceMapSupport选项

Adding the following to laumch.json worked in my case:在我的情况下,将以下内容添加到laumch.json工作:

      "type": "pwa-node",
      ...
      "sourceMaps": true,
      "resolveSourceMapLocations": [
        "${workspaceFolder}/**",
        "!**/node_modules/**"
      ],

( skipSourceMapSuppor: true did not work.) skipSourceMapSuppor: true不起作用。)

Edit: This works only for type pwa-node , not node .编辑:这仅适用于类型pwa-node ,不适用于node This targets the new debugger.这针对新的调试器。 See this answer for details: https://stackoverflow.com/a/63662561/407758有关详细信息,请参阅此答案: https : //stackoverflow.com/a/63662561/407758

This is an old post, but hopefully this helps others who stumble on this.这是一篇旧帖子,但希望这可以帮助其他偶然发现的人。 As you mentioned, with ts-node, there aren't any files being written to disk in workspace the same way they would if you compiled using tsc .正如您所提到的,使用 ts-node,不会像使用tsc编译时那样将任何文件写入工作区中的磁盘。 The way to get breakpoints to hit is to register ts-node when you run protractor.获得断点的方法是在运行量角器时注册 ts-node。

Try this (note the addition to the args property).试试这个(注意args属性的添加)。

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch",
            "type": "node",
            "request": "launch",
            "program": "${workspaceRoot}/node_modules/protractor/bin/protractor",
            "args": [
                "${workspaceRoot}/protractor.conf.js",
                "--require", "ts-node/register"
            ]
            "stopOnEntry": false,
            "sourceMaps": true,
            "cwd": "${workspaceRoot}",
        }
    ]
}

In my launch.json, I've also included the following to ensure that I'm not going into code that doesn't belong to me (as mentioned in skipping uninteresting code in vscode's documentation).在我的 launch.json 中,我还包含以下内容以确保我不会进入不属于我的代码(如跳过vscode 文档中的无趣代码中所述)。

"skipFiles": [
   "<node_internals>/**",
   "${workspaceRoot}/node_modules/**",
]

I seem to be having problems with this however.然而,我似乎对此有问题。 It breaks on my code and skips node_modules folder, but I still see it breaking on some node_internals files.它破坏了我的代码并跳过了 node_modules 文件夹,但我仍然看到它破坏了一些 node_internals 文件。 I have yet to find out why, but at least I can step through code.我还没有找出原因,但至少我可以逐步完成代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM