我有一些关于Angular 应用程序的测试.
All tests are passing, when I run ng test
and the browser launch here is the result:
当我跑ng test --browsers=ChromeHeadless --watch=false
米的时候,它仍然是成功的
Chrome Headless 108.0.5359.124 (Mac OS 10.15.7): Executed 136 of 136 SUCCESS (2.832 secs / 1.844 secs)
TOTAL: 136 SUCCESS
但当我查看日志(log)时,我看到一些错误,这似乎不会触发失败.下面是一个例子:
1. If 'p-skeleton' is an Angular component, then verify that it is a part of an @NgModule where this component is declared.
我知道要修复这个错误,我必须在SPEC文件中导入正确的模块.
但这里的问题是,如果我不查看日志(log),我就看不到错误,我认为修复这种错误将是一种很好的做法.因此,第一步将是警告存在错误.
我能想到的最好的方法是让测试因错误而失败,这样运行测试的任何人都被强制修复错误以使所有测试通过.
这是我的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'),
require('@angular-devkit/build-angular/plugins/karma')
],
client: {
jasmine: {
// you can add configuration options for Jasmine here
// the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
// for example, you can disable the random execution with `random: false`
// or set a specific seed with `seed: 4321`
random: false,
},
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
jasmineHtmlReporter: {
suppressAll: true // removes the duplicated traces
},
coverageReporter: {
dir: require('path').join(__dirname, './coverage/project'),
subdir: '.',
reporters: [
{type: 'html'},
{type: 'text-summary'}
]
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
restartOnFileChange: true
});
};
那么,有没有可能让测试因错误而失败呢?为什么它没有在默认情况下失败?