在我的 gulp 构建中,如果我的服务器单元测试失败,我想“中止”构建过程,但我不确定如何完成此操作。
目前,我正在使用 Node 的 request 模块来运行一些服务器端单元测试,如下所示:
gulp.task("run-server-tests", function(){
var serverTestUrl = "http://myurl"; // returns test results in json format
request(serverTestUrl, function (error, response, body) {
var responseData = JSON.parse(body);
if(responseData.isSuccess){
console.log(responseData.message);
// nice! continue with rest of build (js, css tasks, etc.)
}
else {
open(serverTestUrl + "&render"); // show unit test failures
// err.... gulp.abortProcessing(); ????
}
});
});
============================================= ===============
**更新
在 Martin 和 Nick 的有益回应之后,我将我的构建简化为最基本的示例,我可以想出这些建议来尝试这两个建议,其中:
这是我更新的 gulpfile.js:
var gulp = require("gulp");
var plugins = require('gulp-load-plugins')();
var Q = require("q");
gulp.task("task-1-option-1", function(callback){
plugins.util.log("task 1 running");
callback("unit test failed, stop build"); // let's just assume the unit tests fail
});
gulp.task("task-1-option-2", function(callback){
plugins.util.log("task 1 running");
var deferred = Q.defer();
setTimeout(function(){
deferred.reject("unit test failed, stop build"); // again, let's assume the unit tests fail
}, 2000);
return deferred.promise;
});
gulp.task("task-2-option-1", ["task-1-option-1"], function(){
// if this runs, the build didn't abort as expected
plugins.util.log("task 2 running");
});
gulp.task("task-2-option-2", ["task-1-option-2"], function(){
// if this runs, the build didn't abort as expected
plugins.util.log("task 2 running");
});
// trigger option-1 (Nick's suggestion)
gulp.task("option-1", ["task-1-option-1", "task-2-option-1"]);
// trigger option-2 (Martin's suggestion)
gulp.task("option-2", ["task-1-option-2", "task-2-option-2"]);
============================================= =================
问题在于,虽然这两种方法似乎都“中止”了构建,但它们都会导致 gulp 在终端 (cygwin) 中抛出“硬错误”。我想知道这是否是因为我在 Windows 上运行这些测试,因为好吧,根据我有限的经验,node/gulp 似乎在 Windows 上对我来说一切都崩溃了。
这是我收到的每项任务的输出。一、回调选项:
$ gulp option-1
[10:45:32] Using gulpfile C:\users\bfitzgerald\desktop\gulp-test\gulpfile.js
[10:45:32] Starting 'task-1-option-1'...
[10:45:32] task 1 running
[10:45:32] 'task-1-option-1' errored after 79 ms
[10:45:32] Error: unit test failed, stop build
at formatError (C:\Users\bfitzgerald\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js:169:10)
at Gulp.<anonymous> (C:\Users\bfitzgerald\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js:195:15)
at Gulp.emit (events.js:107:17)
at Gulp.Orchestrator._emitTaskDone (C:\users\bfitzgerald\desktop\gulp-test\node_modules\gulp\node_modules\orchestrator\index.js:264:8)
at C:\users\bfitzgerald\desktop\gulp-test\node_modules\gulp\node_modules\orchestrator\index.js:275:23
at finish (C:\users\bfitzgerald\desktop\gulp-test\node_modules\gulp\node_modules\orchestrator\lib\runTask.js:21:8)
at cb (C:\users\bfitzgerald\desktop\gulp-test\node_modules\gulp\node_modules\orchestrator\lib\runTask.js:29:3)
at Gulp.<anonymous> (C:\users\bfitzgerald\desktop\gulp-test\gulpfile.js:9:2)
at module.exports (C:\users\bfitzgerald\desktop\gulp-test\node_modules\gulp\node_modules\orchestrator\lib\runTask.js:34:7)
at Gulp.Orchestrator._runTask (C:\users\bfitzgerald\desktop\gulp-test\node_modules\gulp\node_modules\orchestrator\index.js:273:3)
这是 promises 选项的输出:
$ gulp option-2
[10:46:50] Using gulpfile C:\users\bfitzgerald\desktop\gulp-test\gulpfile.js
[10:46:50] Starting 'task-1-option-2'...
[10:46:50] task 1 running
[10:46:52] 'task-1-option-2' errored after 2.08 s
[10:46:52] Error: unit test failed, stop build
at formatError (C:\Users\bfitzgerald\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js:169:10)
at Gulp.<anonymous> (C:\Users\bfitzgerald\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js:195:15)
at Gulp.emit (events.js:107:17)
at Gulp.Orchestrator._emitTaskDone (C:\users\bfitzgerald\desktop\gulp-test\node_modules\gulp\node_modules\orchestrator\index.js:264:8)
at C:\users\bfitzgerald\desktop\gulp-test\node_modules\gulp\node_modules\orchestrator\index.js:275:23
at finish (C:\users\bfitzgerald\desktop\gulp-test\node_modules\gulp\node_modules\orchestrator\lib\runTask.js:21:8)
at C:\users\bfitzgerald\desktop\gulp-test\node_modules\gulp\node_modules\orchestrator\lib\runTask.js:45:4
at _rejected (C:\users\bfitzgerald\desktop\gulp-test\node_modules\q\q.js:804:24)
at C:\users\bfitzgerald\desktop\gulp-test\node_modules\q\q.js:830:30
at Promise.when (C:\users\bfitzgerald\desktop\gulp-test\node_modules\q\q.js:1064:31)
所以这些建议似乎是正确的,因为它们阻止了第二个任务的运行,但是由于 gulp 正在引发某种硬错误,所以似乎仍然有问题。任何人都可以为我阐明这一点吗?
最佳答案
我不太确定我是否理解您要使用测试 url 完成的操作,但是您可以使用非 null 调用传递到任务中的回调,以使其通过通知中止任务:
gulp.task("run-server-tests", function(callback) {
var serverTestUrl = "http://myurl";
request(serverTestUrl, function (error, response, body) {
var responseData = JSON.parse(body);
if (responseData.isSuccess) {
// snip...
callback();
} else {
open(serverTestUrl + "&render"); // show unit test failures
callback('Unit test error');
}
});
});
关于javascript - 我怎么能 "abort"一口气构建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28534463/
我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou
我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-
为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar
我遵循MichaelHartl的“RubyonRails教程:学习Web开发”,并创建了检查用户名和电子邮件长度有效性的测试(名称最多50个字符,电子邮件最多255个字符)。test/helpers/application_helper_test.rb的内容是:require'test_helper'classApplicationHelperTest在运行bundleexecraketest时,所有测试都通过了,但我看到以下消息在最后被标记为错误:ERROR["test_full_title_helper",ApplicationHelperTest,1.820016791]test
我正在尝试从Postgresql表(table1)中获取数据,该表由另一个相关表(property)的字段(table2)过滤。在纯SQL中,我会这样编写查询:SELECT*FROMtable1JOINtable2USING(table2_id)WHEREtable2.propertyLIKE'query%'这工作正常:scope:my_scope,->(query){includes(:table2).where("table2.property":query)}但我真正需要的是使用LIKE运算符进行过滤,而不是严格相等。然而,这是行不通的:scope:my_scope,->(que
我正在尝试编写一个将文件上传到AWS并公开该文件的Ruby脚本。我做了以下事情:s3=Aws::S3::Resource.new(credentials:Aws::Credentials.new(KEY,SECRET),region:'us-west-2')obj=s3.bucket('stg-db').object('key')obj.upload_file(filename)这似乎工作正常,除了该文件不是公开可用的,而且我无法获得它的公共(public)URL。但是当我登录到S3时,我可以正常查看我的文件。为了使其公开可用,我将最后一行更改为obj.upload_file(file
当我尝试安装Ruby时遇到此错误。我试过查看this和this但无济于事➜~brewinstallrubyWarning:YouareusingOSX10.12.Wedonotprovidesupportforthispre-releaseversion.Youmayencounterbuildfailuresorotherbreakages.Pleasecreatepull-requestsinsteadoffilingissues.==>Installingdependenciesforruby:readline,libyaml,makedepend==>Installingrub
所以我开始关注ruby,很多东西看起来不错,但我对隐式return语句很反感。我理解默认情况下让所有内容返回self或nil但不是语句的最后一个值。对我来说,它看起来非常脆弱(尤其是)如果你正在使用一个不打算返回某些东西的方法(尤其是一个改变状态/破坏性方法的函数!),其他人可能最终依赖于一个返回对方法的目的并不重要,并且有很大的改变机会。隐式返回有什么意义?有没有办法让事情变得更简单?总是有返回以防止隐含返回被认为是好的做法吗?我是不是太担心这个了?附言当人们想要从方法中返回特定的东西时,他们是否经常使用隐式返回,这不是让你组中的其他人更容易破坏彼此的代码吗?当然,记录一切并给出
给定以下方法:defsome_method:valueend以下语句按我的预期工作:some_method||:other#=>:valuex=some_method||:other#=>:value但是下面语句的行为让我感到困惑:some_method=some_method||:other#=>:other它按预期创建了一个名为some_method的局部变量,随后对some_method的调用返回该局部变量的值。但为什么它分配:other而不是:value呢?我知道这可能不是一件明智的事情,并且可以看出它可能有多么模棱两可,但我认为应该在考虑作业之前评估作业的右侧...我已经在R
我在我的Rails3示例应用程序上使用CarrierWave。我想验证远程位置上传,因此当用户提交无效URL(空白或非图像)时,我不会收到标准错误异常:CarrierWave::DownloadErrorinImageController#createtryingtodownloadafilewhichisnotservedoverHTTP这是我的模型:classPaintingtrue,:length=>{:minimum=>5,:maximum=>100}validates:image,:presence=>trueend这是我的Controller:classPaintingsC