量角器以代码0退出,即使测试失败 [英] Protractor Exits with code 0 even though tests are failing
问题描述
我正在通过npm运行量角器v4.0.9,并且注意到即使在报告测试失败的情况下,我在Visual Studio Team Services上的构建也不会失败.进一步调查,我引入了一个错误,因此测试将失败,然后在本地运行它们.如下面的屏幕快照所示,我有17/17个失败的测试,但是退出代码仍然为0,据我了解是成功的.它甚至说chrome #01 passed
,我认为这是错误的.
I am running protractor v4.0.9 via npm, and noticed that my build on Visual Studio Team Services does not fail even when tests are reported as failing. Looking into this further, I introduced an error so that tests would fail and then ran them locally. As the screenshot below shows, I have 17/17 failing tests, but the exit code is still 0, which I understand is a success. It even says chrome #01 passed
, which I assume is wrong.
这是我的量角器配置:
"use strict";
exports.config = {
baseUrl: process.env.npm_package_config_baseUrl,
framework: 'jasmine',
capabilities: {
browserName: 'chrome'
},
specs: ['test/*.spec.js'],
rootElement: 'se-app',
directConnect: true,
ignoreUncaughtExceptions: false,
onPrepare: function () {
var globals = require('protractor');
var browser = globals.browser;
browser.ignoreSynchronization = true;
browser.manage().window().maximize();
var specReporter = require('jasmine-spec-reporter');
// add jasmine spec reporter
jasmine.getEnv().clearReporters();
jasmine.getEnv().addReporter(new specReporter({
displayStacktrace: false
}));
var reporters = require('jasmine-reporters');
jasmine.getEnv().addReporter(new reporters.JUnitXmlReporter({
savePath: 'junit/'
}));
},
};
我检查了有关量角器配置的文档,但是看不到任何明显的设置,可能会导致这种情况发生.我什至添加了ignoreUncaughtExceptions:false
(如上所示)以明确表示,但没有区别.
I checked the documentation for the Protractor config but could not see any obvious settings that would cause this to happen. I even added in ignoreUncaughtExceptions:false
(shown above) to be explicit but it made no difference.
推荐答案
好的,我发现了问题.默认情况下,Jasmine包括控制台Reporter
和CompletionReporter
.如果测试失败,后者将退出流程.通过清除记者,我正在删除此记者.
Ok, I found the problem. By default, Jasmine includes the console Reporter
and the CompletionReporter
. The latter is what exits the process if the tests fail. By clearing the reporters, I was removing this reporter.
我可以删除该行,但是我想删除控制台报告器,以便规范报告器和控制台报告器不会同时执行同一工作.
I could just remove that line, but I want to remove the console reporter so that the spec reporter and console reporter aren't both doing the same job.
因此,我不得不重新添加完成报告器.我不确定这是否是正确"的方法,但是它可以工作.这是我的新onPrepare函数:
So I had to add the completion reporter back in. I'm not sure if this is the "correct" way to do it, but it works. Here is my new onPrepare function:
onPrepare: function() {
let globals = require('protractor');
let reporters = require('jasmine-reporters');
let CompletionReporter = require('jasmine/lib/reporters/completion_reporter');
let SpecReporter = require('jasmine-spec-reporter');
let browser: ProtractorBrowser = globals.browser;
browser.ignoreSynchronization = true;
browser.manage().window().maximize();
let specReporter = new SpecReporter({
displayStacktrace: false
});
let junitReporter = new reporters.JUnitXmlReporter({
savePath: 'junit/'
});
let completionReporter = new CompletionReporter();
completionReporter.onComplete((success: boolean) => {
if (!success) {
process.exit(1);
}
});
// Now clear all existing reporters and add the ones I want in the order I want
jasmine.getEnv().clearReporters();
jasmine.getEnv().addReporter(specReporter);
jasmine.getEnv().addReporter(junitReporter);
jasmine.getEnv().addReporter(completionReporter);
}
这篇关于量角器以代码0退出,即使测试失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!