【问题标题】:How to debug e2e tests with VS Code and type script如何使用 VS Code 和类型脚本调试 e2e 测试
【发布时间】:2017-09-12 12:14:05
【问题描述】:

我有使用Angular CLI 生成的角度项目。

我想调试 e2e 测试。 正如我不明白的那样,为了做到这一点,我应该将测试从 *.ts 编译到 *.js, 我找到了这个信息here,但它对我不起作用。

我还阅读了this 文章,但它对我也不起作用。

我做错了什么?请帮帮我...我花了一个星期没有结果...

我的 .vscode 文件夹和 tasks.json 文件

{
    "version": "0.1.0",
    "command": "npm",
    "isShellCommand": true,
    "showOutput": "always",
    "suppressTaskName": true,
    "tasks": [
        {
            "taskName": "e2e-compile",
            "isBuildCommand": true,
            "args": [
                "run",
                "e2e-compile"
            ]
        }
    ]
}

launch.json 文件

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch e2e Tests",
            "type": "node",
            "request": "launch",
            "stopOnEntry": false,
            "program": "${workspaceRoot}/node_modules/protractor/bin/protractor",
            "args": [
                "${workspaceRoot}/protractor.conf.debug.js"
            ],
            "preLaunchTask": "e2e-compile",
            "cwd": "${workspaceRoot}",
            "sourceMaps": true,
            "outFiles": [
                "${workspaceRoot}/dist/out-tsc-e2e/*.js"
            ]
        }
    ]
}

protractor.config.debug.js 文件

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

exports.config = {
  allScriptsTimeout: 11000,
  specs: [
    './dist/out-tsc-e2e/**/*.e2e-spec.js'
  ],
  capabilities: {
    'browserName': 'chrome'
  },
  directConnect: true,
  baseUrl: 'http://localhost:4200/',
  framework: 'jasmine',
  jasmineNodeOpts: {
    showColors: true,
    defaultTimeoutInterval: 30000,
    print: function() {}
  },
  useAllAngular2AppRoots: true,
  beforeLaunch: function() {

  },
  onPrepare: function() {
    jasmine.getEnv().addReporter(new SpecReporter());
  }
};

然后我正在添加断点并使用 F5 进行调试,我正在等待暂停但它只是失败了。 如有任何帮助,我将不胜感激。

【问题讨论】:

    标签: angularjs angular typescript visual-studio-code


    【解决方案1】:

    我怀疑您的问题与您的量角器配置的第一行有关:var SpecReporter = require('jasmine-spec-reporter');

    看看任务执行过程中的控制台窗口输出:

    Debugger listening on [::]:26978
    [12:07:47] I/launcher - Running 1 instances of WebDriver
    [12:07:47] I/direct - Using ChromeDriver directly...
    [12:07:50] E/launcher - Error: TypeError: SpecReporter is not a constructor
        at onPrepare (c:\src\TableDojo\ClientApp\protractor.conf.debug.js:25:34)
    

    Jasmine 发生了重大变化(请参阅 SpecReporter is not a constructor error when running protractor using angular-cli)。尝试用var SpecReporter = require('jasmine-spec-reporter').SpecReporter;更改上述行

    在我的机器上工作:-)

    【讨论】:

      猜你喜欢
      • 2020-12-16
      • 2021-05-12
      • 2019-10-10
      • 1970-01-01
      • 2019-04-02
      • 2018-08-20
      • 2017-10-02
      • 2021-03-05
      相关资源
      最近更新 更多