【问题标题】:Angular Karma not capturing browserAngular Karma 未捕获浏览器
【发布时间】:2019-03-18 23:43:29
【问题描述】:

我有一个 Angular 6 上的现有项目,其中测试未运行。它是如何发生的:在 PhpStorm 中,我按下文件 run file.specs.ts 上的上下文菜单。

它开始测试,打开浏览器,然后什么都没有发生。这是日志

Waiting for a captured browser... To capture a browser open http://localhost:9876/
14 10 2018 13:04:17.500:WARN [launcher]: Chrome have not captured in 60000 ms, killing.
14 10 2018 13:04:17.799:INFO [launcher]: Trying to start Chrome again (1/2).
14 10 2018 13:05:17.808:WARN [launcher]: Chrome have not captured in 60000 ms, killing.
14 10 2018 13:05:18.055:INFO [launcher]: Trying to start Chrome again (2/2).
14 10 2018 13:06:18.062:WARN [launcher]: Chrome have not captured in 60000 ms, killing.
14 10 2018 13:06:18.199:ERROR [launcher]: Chrome failed 2 times (timeout). Giving up.

我如何找出这些测试有什么问题?我没有看到有关依赖项或其他内容的错误。有没有机会找到不捕获浏览器的原因?

在这个项目中,所有spec.tss 都丢失了(看起来有人删除了它们),所以我尝试运行那些在新组件/服务上创建的。

没有这样的选项来启动新项目。我必须解决这个问题。

任何帮助将不胜感激。

这是我的 src/karma.conf.js

// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html

module.exports = function (config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine', '@angular-devkit/build-angular'],
    plugins: [
      require('karma-jasmine'),
      require('karma-chrome-launcher'),
      require('karma-jasmine-html-reporter'),
      require('karma-coverage-istanbul-reporter'),
      require('@angular-devkit/build-angular/plugins/karma')
    ],
    client: {
      clearContext: false // leave Jasmine Spec Runner output visible in browser
    },
    coverageIstanbulReporter: {
      dir: require('path').join(__dirname, '../coverage'),
      reports: ['html', 'lcovonly'],
      fixWebpackSourcePaths: true
    },
    reporters: ['progress', 'kjhtml'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome'],
    singleRun: false
  });
};

【问题讨论】:

  • 你能不能写一个非常简单的(1=1) 测试并检查它是否运行。通过使用fdescribefit,您可以了解您的配置错误或您的测试有问题。
  • 你能扩展你的答案吗?我不确定你在说fdescribe 时的意思。我是测试新手。我正在使用角度生成的测试。
  • 另外,我还有另一个项目,测试工作得很好。依赖项和业力配置看起来都不错
  • it('should be one equal one') 在字符 f 前加上 it or describe 块将仅执行该特定代码块。例如:fit('should be one equal one')

标签: angular typescript karma-runner


【解决方案1】:

问题很简单,运行ng test 即可显示。有一些应用程序级错误破坏了 Jasmine 初始化(虽然我不明白为什么当我尝试在 PhpStorm 中对单个文件运行测试时它不起作用)。所以当我解决了这个问题时,我的测试和单一测试一样开始工作(在浏览器中它们显示为全部运行)

【讨论】:

  • 我想知道为什么这种错误没有冒泡。我的模块中缺少一个导致同样问题的模块。这个解决方案对我有用。
猜你喜欢
  • 2023-03-30
  • 1970-01-01
  • 1970-01-01
  • 2011-08-25
  • 2017-09-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-09-18
相关资源
最近更新 更多