Angular Karma not capturing browser

落爺英雄遲暮 提交于 2020-06-28 05:14:11

问题


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
  });
};

回答1:


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)



来源:https://stackoverflow.com/questions/52801608/angular-karma-not-capturing-browser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!