Angular Karma无法捕获浏览器 [英] Angular Karma not capturing browser

查看:120
本文介绍了Angular Karma无法捕获浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在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.ts都丢失了(看起来好像有人删除了它们),因此我尝试运行在新组件/服务上创建的那些.

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

任何帮助将不胜感激.

这是我的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
  });
};

解决方案

问题非常简单,通过运行ng test可以看到.有一些应用程序级别的错误破坏了Jasmine的初始化(尽管我不明白为什么当我尝试在PhpStorm中对单文件进行测试时它为什么不起作用).因此,当我解决了这个问题后,我的测试开始运行,并且测试也和单个测试一样(在浏览器中显示为全部运行)

I've an existing project on Angular 6 where tests not running. How it happens: in PhpStorm I press in context menu on file run file.specs.ts.

It starts test, opens the browser and nothing is happening then. Here is the log

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.

How do I figure out what's wrong with these tests? I see no errors about dependencies or something else. Is there a chance to find what causes not capturing browser?

In this project all spec.tss are missing (looks like someone's deleted them), so I try to run those which've been created on new components/services.

There is no such an option to start new project. I have to fix this one.

Any help will be very appreciated.

This is my 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
  });
};

解决方案

The problem was pretty simple and was shown by running ng test. There were some app-level errors which broke the Jasmine init (although I don't understand why it wasn't working when I tried to run test for a singe file in PhpStorm). So when I solved that problem my tests started working as well as singular tests (in browser they are shown to be run all)

这篇关于Angular Karma无法捕获浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆