【发布时间】: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) 测试并检查它是否运行。通过使用
fdescribe或fit,您可以了解您的配置错误或您的测试有问题。 -
你能扩展你的答案吗?我不确定你在说
fdescribe时的意思。我是测试新手。我正在使用角度生成的测试。 -
另外,我还有另一个项目,测试工作得很好。依赖项和业力配置看起来都不错
-
it('should be one equal one')在字符 f 前加上it or describe块将仅执行该特定代码块。例如:fit('should be one equal one')
标签: angular typescript karma-runner