简体   繁体   English

无法在 Windows 10 上运行角度规范测试

[英]Unable to run angular spec tests on Windows 10

I am trying to run unit tests for an angular component in a Windows machine.我正在尝试为 Windows 机器中的角度组件运行单元测试。 What I observe is that there are no test launches.我观察到的是没有测试发布。 There is no error trace on console either.控制台上也没有错误跟踪。 Following is what I get:以下是我得到的:

>ng test my-component >ng 测试我的组件

0% compiling(node:6420) DeprecationWarning: Tapable.plugin is deprecated. 0% 编译(节点:6420)弃用警告:不推荐使用 Tapable.plugin。 Use new API on .hooks instead改用.hooks上的新 API

29 07 2019 16:52:05.121:INFO [karma]: Karma v1.7.1 server started at http://0.0.0.0:9876/ 29 07 2019 16:52:05.121:INFO [karma]:Karma v1.7.1 服务器启动于http://0.0.0.0:9876/

29 07 2019 16:52:05.124:INFO [launcher]: Launching browser Chrome with unlimited concurrency 29 07 2019 16:52:05.124:INFO [启动器]:以无限并发启动浏览器 Chrome

29 07 2019 16:52:05.129:INFO [launcher]: Starting browser Chrome 29 07 2019 16:52:05.129:INFO [启动器]:启动浏览器 Chrome

29 07 2019 16:53:05.132:WARN [launcher]: Chrome have not captured in 60000 ms, killing. 29 07 2019 16:53:05.132:WARN [launcher]:Chrome 没有在 60000 毫秒内捕获,杀死。

29 07 2019 16:53:07.135:WARN [launcher]: Chrome was not killed in 2000 ms, sending SIGKILL. 29 07 2019 16:53:07.135:WARN [launcher]:Chrome 没有在 2000 毫秒内被杀死,发送 SIGKILL。

29 07 2019 16:53:09.138:WARN [launcher]: Chrome was not killed by SIGKILL in 2000 ms, continuing. 29 07 2019 16:53:09.138:WARN [launcher]:Chrome 在 2000 毫秒内没有被 SIGKILL 杀死,继续。

How to get tests running?如何让测试运行?

Cannot tell, without looking into your configuration, however try following karma configuration, do npm install with including the dependencies, post this, remove any unnecessary dependencies for you like "puppeteer" etc如果不查看您的配置就无法判断,但是请尝试遵循 karma 配置,使用包含依赖项的 npm install 进行安装,发布此信息,为您删除任何不必要的依赖项,例如“puppeteer”等

const puppeteer = require('puppeteer');
process.env.CHROME_BIN = puppeteer.executablePath();

module.exports = function (config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine', '@angular-devkit/build-angular'],
    files: [
      './assets/content-and-assets/mock-google-api.js'
    ],

    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'),
      require('karma-junit-reporter')
    ],
    client: {
      jasmine: {
        random: false
      },
      clearContext: false // leave Jasmine Spec Runner output visible in browser
    },
    coverageIstanbulReporter: {
      dir: require('path').join(__dirname, '../coverage'),
      reports: ['html', 'lcovonly', 'cobertura', 'text', 'text-summary'],
      fixWebpackSourcePaths: true
    },
    reporters: ['progress', 'kjhtml', 'junit'],
    junitReporter: {
      outputFile: '../../junitreport/credit-check-tests.xml'
    },
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    customLaunchers: {
      ChromeHeadless: {
        base: 'Chrome',
        flags: [
          '--headless',
          '--disable-gpu',
          '--no-sandbox',
          '--remote-debugging-port=9222',
        ]
      },
      Chrome1: {
        base: 'Chrome',
        flags: ['--disable-web-security',
          '--enable-gpu']
      },
      ChromeDebugging: {
        base: 'Chrome',
        flags: ['--remote-debugging-port=9333']
      },

    },
     browsers: ['ChromeDebugging'],
     singleRun: false
    //browsers: ['ChromeHeadless'],
    //singleRun: true
  });
};

Works for me in Win10 as per my requirement.根据我的要求在 Win10 中为我工作。

PS : You can run chrome in headless mode, toggle-comment last two lines. PS:您可以在无头模式下运行 chrome,切换注释最后两行。

EDIT编辑

I assume you have already installed chrome browser in your machine.( suggested )我假设你已经在你的机器上安装了 chrome 浏览器。(建议)

In case, you intent not to use browser you can go for PhantomJS, however that is not performance efficient.如果您打算不使用浏览器,您可以选择 PhantomJS,但这不是性能有效的。

Benchmark for reference 基准参考

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

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