-
-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Return exit code 1 when incomplete tasks are detected #145
Return exit code 1 when incomplete tasks are detected #145
Conversation
Please add tests and make sure you aren't breaking old versions. |
Sure! Anything that is easily backported should be. |
@barbogast Could you also implement for gulp v3? Regarding tests on v3, since we will address them in the issue #139, you may write only a unit test for |
I just added a test and removed the require('process') call. I'd try to backport the change to gulp v3 but to me it looks like gulp v3 doesn't detect incomplete tasks but just exits the process. The integration tests fail for nodejs 0.10 as expected (see gulpjs/gulp#2081 (comment)). Is there a way to skip the test for nodejs 0.10? |
if (!('exitCode' in process)) {
this.skip();
} Should work??? |
I'm pretty sure that this wouldn't solve the problem. The code didn't crash. Only the test failed because the process didn't exit with an error code (as is expected for nodejs 0.10). We need a way to disable this test case for nodejs 0.10. We could parse |
That goes in the test to skip it. The property won't exist in old node |
Oh, sorry, I didn't understand. I just checked, and We could detect the node version using https://github.com/phated/sver-compat |
test/lib/sync-task.js
Outdated
|
||
describe('sync-task', function() { | ||
it('should return error code 1 if any tasks did not complete', function(done) { | ||
var this_ = this; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@barbogast It's not necessary to use the new package. As @phated said, this test case can be skipped by the following code at this point:
it('should return error code 1 if any tasks did not complete', function(done) {
if (!('exitCode' in process)) { // On v0.10 only, this condition is true because process doesn't have .exitCode.
this.skip();
return; // This is not necessary because skip() throws an exception, but is recommened to avoid confusing.
}
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure this will work? I just rechecked and
> 'exitCode' in process
false
for
node -v
v8.9.3
So even on nodejs > 0.11.0 the exitCode
property is not set by default.
Or am I misunderstanding completely?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I think I understood. Do you mean that exitCode
was set already by process.exitCode = 1
in sync-task.js
? This would work, but only if require('gulp-test-tools').gulpRunner
which is used by the test doesn't spawn a new process, right? I guess that it does but I'll try when I get home.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@barbogast I'm sorry, I really misunderstood. You are right. I did only checked process.exitCode is undefined on v0.10 and I completely thought process.exitCode is zero initially on other versions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@barbogast Since these test cases in test/lib/sync-task.js
are not unit test, please move this file to test/
and rename it to another like exit-code.js
.
In addition, I think it's better that these two cases can be put into one case and then nodeDoesNotNodeSupportExitCode()
is used not for this.skip()
but for unchecking exit code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move the file like sttk mentioned and remove that utility (using my other recommendation above).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few things
package.json
Outdated
@@ -64,7 +64,8 @@ | |||
"marked-man": "^0.1.3", | |||
"mocha": "^3.2.0", | |||
"nyc": "^10.0.0", | |||
"rimraf": "^2.6.1" | |||
"rimraf": "^2.6.1", | |||
"sver-compat": "^1.5.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't bring in this dep.
test/lib/sync-task.js
Outdated
return currentVersion.lt(minimalVersion); | ||
} | ||
|
||
describe('sync-task', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use this instead:
beforeEach(function(cb) {
if (process.version.slice(5) === 'v0.10') {
this.skip();
}
cb();
});
test/lib/sync-task.js
Outdated
|
||
describe('sync-task', function() { | ||
it('should return error code 1 if any tasks did not complete', function(done) { | ||
var this_ = this; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move the file like sttk mentioned and remove that utility (using my other recommendation above).
@@ -20,6 +20,15 @@ function errorFunction() { | |||
function anon(cb) { | |||
cb(); | |||
} | |||
|
|||
function notCompleting1() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need 2 non-completing tasks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created 2 tasks to also test that the log message is rendered correctly with multiple non-completing tasks. Should I remove the second task?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fine. I'm not partial either way.
Thank you for your review. 👍 The new dependency and the utility function are removed. Note that in addition to a test for the exit code I added a test for the log message about the non-completing tests. I couldn't find any tests for The reason I created 2 test cases is that test case for the log message can run under nodejs 0.10 and should be reported as successful while the second test case is then reported as skipped. Should I join them anyway? The test file is moved to the |
non-completing-tasks.js sounds great! |
all right, I'll rename it |
This PR looks great @barbogast - I'm just going to wait until the CI complete then merge and publish |
Nah, I'll do that in the merge. |
@barbogast Great! Thank you for your contribution. |
Published as 2.0.1 - Thanks again @barbogast!! |
Looks like this could be a fix for gulpjs/gulp#2081