Skip to content
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

Merged

Conversation

barbogast
Copy link
Contributor

@barbogast barbogast commented Jan 13, 2018

Looks like this could be a fix for gulpjs/gulp#2081

@phated
Copy link
Member

phated commented Jan 13, 2018

Please add tests and make sure you aren't breaking old versions. process isn't a module and is just a global.

@sttk
Copy link
Contributor

sttk commented Jan 14, 2018

@phated Should we treat this for gulp v3? It is possible by modifying events.js.

@phated
Copy link
Member

phated commented Jan 14, 2018

Sure! Anything that is easily backported should be.

@sttk
Copy link
Contributor

sttk commented Jan 14, 2018

@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 logEvents in events.js.

@barbogast
Copy link
Contributor Author

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?

@phated
Copy link
Member

phated commented Jan 17, 2018

if (!('exitCode' in process)) {
  this.skip();
}

Should work???

@barbogast
Copy link
Contributor Author

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 process.version and skip the test for nodejs < 0.11. Kind of hacky, bit it should work...

@phated
Copy link
Member

phated commented Jan 18, 2018

That goes in the test to skip it. The property won't exist in old node

@barbogast
Copy link
Contributor Author

Oh, sorry, I didn't understand. I just checked, and exitCode is not present on process (except when it's set explicitly).

We could detect the node version using https://github.com/phated/sver-compat


describe('sync-task', function() {
it('should return error code 1 if any tasks did not complete', function(done) {
var this_ = this;
Copy link
Contributor

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.
    }
    ...

Copy link
Contributor Author

@barbogast barbogast Jan 19, 2018

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?

Copy link
Contributor Author

@barbogast barbogast Jan 19, 2018

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.

Copy link
Contributor

@sttk sttk Jan 19, 2018

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.

Copy link
Contributor

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.

Copy link
Member

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).

Copy link
Member

@phated phated left a 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"
Copy link
Member

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.

return currentVersion.lt(minimalVersion);
}

describe('sync-task', function() {
Copy link
Member

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();
});


describe('sync-task', function() {
it('should return error code 1 if any tasks did not complete', function(done) {
var this_ = this;
Copy link
Member

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() {
Copy link
Member

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?

Copy link
Contributor Author

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?

Copy link
Member

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.

@barbogast
Copy link
Contributor Author

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 sync-tasks.js so I went ahead and added a second test case.

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 test-directory. I have not yet renamed the test file since it not only tests the exit code but also the log message for non-completing tests. So I think the name exit-code.js is not fitting. Maybe non-completing-tasks.js?

@phated
Copy link
Member

phated commented Jan 22, 2018

non-completing-tasks.js sounds great!

@barbogast
Copy link
Contributor Author

all right, I'll rename it

@phated
Copy link
Member

phated commented Jan 22, 2018

This PR looks great @barbogast - I'm just going to wait until the CI complete then merge and publish

@barbogast
Copy link
Contributor Author

Great, thanks a lot for your reviews, @phated @sttk

Should I sqash the commits before merging?

@phated
Copy link
Member

phated commented Jan 22, 2018

Should I squash the commits before merging?

Nah, I'll do that in the merge.

@sttk
Copy link
Contributor

sttk commented Jan 22, 2018

@barbogast Great! Thank you for your contribution.

@phated phated merged commit f57134a into gulpjs:master Jan 22, 2018
@phated
Copy link
Member

phated commented Jan 22, 2018

Published as 2.0.1 - Thanks again @barbogast!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants