-
-
Notifications
You must be signed in to change notification settings - Fork 87
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
Gulp-Mocha fails to exit, but Mocha does #54
Comments
+1, the task never finishes...it has to be |
I'm experiencing this as well. I'm using |
You did not call describe('add a entry into the index', function(){
it('should add Dave as a person to the database', function(done){
assert.equal(1,1);
done();
});
}); Or like this: describe('add a entry into the index', function(){
it('should add Dave as a person to the database', function(){
assert.equal(1,1);
});
}); |
I'm having the same problem. Checked through my tests and none of them have an uncalled Also if it was an issue of |
@davejlong gist with hanging test and gulp file would be nice. |
@drundle second guess, that you should close client in |
@floatdrop It's not a hanging test. When I run gulp, it outputs that the task finishes, but then gulp doesn't exit. |
@davejlong it can be caused by hanging sockets or setIntervals - elastic/elasticsearch-js#40 Could you share your gulpfile and test that causing gulp to hang? |
Ahh I found it. There was a setTimeout in my code that was being tested that caused the tests to hang. |
@davejlong @floatdrop it's still an issue in general. My tests exit when running mocha, but they don't exit when running mocha through gulp-mocha. @sindresorhus do you have any idea what's happening with this? UPDATE: 1.1.0 doesn't fix this by the way. |
@ilanbiala could you post a gulp task, that we can reproduce bug? |
|
@ilanbiala this code is working for me and gulp is exiting fine. Can you replace |
Doesn't work for me if I put in only one test. However, if the tests fail, then gulp-mocha properly exits. |
@ilanbiala good. It means, that |
That file is used to start up the server and connect to the test database. Is there a good way to have my server and database running prior to running the tests? |
@ilanbiala start server before tests and tear it down after - I think that what |
The server is started just by requiring or running the file. What can I do to kill the server after all the tests have finished? |
@ilanbiala either you call |
Right now I'm trying to set it up that way, but it seems that the console.log happens before the tests in the required files are run. Any thoughts on a good way to set this up..? I'm pretty lost. |
@ilanbiala it is pretty hard to help without knowing, what inside In your place I'd rather running new server for bunch of tests instead of sharing one server for all kind of tests (it is good practice to run test on fresh prepared server/database). I created example repository to demonstrate work with server - https://github.com/floatdrop/gulp-mocha-example (it exits after running all tests successfully). |
|
Are any of you guys using loopback at all? Im having the same issue with the above referenced ticket, and I think they are related to your issues as well even if you are not using loopback, as i think its something conceptually wrong with node applications. |
@floatdrop, yes we called done() on in (I forgot to put in the example, applogies) The issue is I can run identical code in both Mocha directly and via gulp-mocha, but get different behaviour |
Same issue in about same environment. Never get exited from gulp. it 'should respond with JSON array', (done) ->
data.save ->
request app
.get '/api/data'
.expect 200
.expect 'Content-Type', /json/
.end (err, res) ->
return done err if err
res.body.should.be.instanceof Array
res.body.should.have.length 1
done() |
Had same issue. The cause was a mongoose connection that was opened but not properly caused on tests. Adding
fixed this for me. |
Saw this trick in another issue. gulp.task('default', function () {
return gulp.src('test/**/*_test.js')
.pipe(mocha())
.once('end', function () {
process.exit();
});
}); |
+1 |
@futurechan I have the same problem and I close the db connections with
I use node 0.10.33, some have the problem with node 0.11.0 ? In a supertest issue , I read this
|
+1 same issue. So what's the consensus? should gulp-mocha terminate these connections or is it the responsibility of the developer? If the latter then gulp-mocha has the responsibility of mentioning it in the docs @sindresorhus |
Developer responsibility. Maybe a note on the docs could help... |
Sovled by #73 |
If, I use I try with this test code (without database connections) : https://gist.github.com/juanpabloaj/f1ea60417f47897c940f describe('app test', function(){
it('app return json message', function(done){
request(app)
.get('/')
.expect(200)
.end(function(err, res){
res.body.message.should.match(/test/);
done();
});
});
}); when I use $ mocha -w test_app.js
app test
✓ app return json message
1 passing (49ms)
app test
✓ app return json message
1 passing (13ms) but, If I use $ gulp
[13:04:22] Using gulpfile ~/code/nodejs/gupl-mocha/fail_to_exit/gulpfile.js
[13:04:22] Starting 'watch'...
[13:04:22] Finished 'watch' after 8.98 ms
[13:04:22] Starting 'default'...
[13:04:22] Finished 'default' after 8.52 μs
[13:04:25] Starting 'tests'...
app test
✓ app return json message
1 passing (23ms)
[13:04:26] Finished 'tests' after 358 ms
[13:04:28] Starting 'tests'...
[13:04:28] 'tests' errored after 154 ms
[13:04:28] Error in plugin 'gulp-mocha'
Message:
listen EADDRINUSE
Details:
code: EADDRINUSE
errno: EADDRINUSE
syscall: listen
domainEmitter: [object Object]
domain: [object Object]
domainThrown: false
Stack:
Error: listen EADDRINUSE
at errnoException (net.js:904:11)
at Server._listen2 (net.js:1042:14)
at listen (net.js:1064:10)
at Server.listen (net.js:1138:5)
at EventEmitter.app.listen (/Users/pablo/code/nodejs/gupl-mocha/fail_to_exit/node_modules/express/lib/application.js:559:24)
at Object.<anonymous> (/Users/pablo/code/nodejs/gupl-mocha/fail_to_exit/server.js:15:5)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
app test
✓ app return json message
1 passing (13ms) |
@juanpabloaj I'm no expert on testing. But it sounds like you could recreate the mocha object for every test. This would also help isolate issues. Could you try that? |
In my case I create a child process on server.js (a simple scheduler), added |
I tried the The problem with |
How do you run your tests? You might do something like
|
Hmm, that's an interesting idea. Ultimately, I'm using Coveralls for Travis, so I placed an extra command in the
That did the trick alright. Still, something doesn't seem right with me about needing a workaround like that. I wish I could figure out the root problem. |
…ic testing as it doesn't close gulp-mocha properly. tried https://github.com/sindresorhus/gulp-mocha#test-suite-not-exiting and solutions from sindresorhus/gulp-mocha#54 but without success
Using gulp-spawn-mocha fixes the problem for me. |
I was having a similar issue, i.e. my test run and all pass, all done callback called but mocha was not exiting as I'd expect it to. The solution was that I had an unexpected option defined in my global mocha.opts file. --no-exit removing the above solved my issue. |
Fixed for me: https://github.com/dreame4/gulp-exit |
@juanpabloaj I have the same problem as you with asynchronous tests (in my case I used request to test a Rest API). By rewriting the test as
the test passed for both single-run and gulp-mocha (watching mode) |
This issue still persists. Valid workarounds are gulp-spawn-mocha by @richardschneider and gulp-exit by @justinr1234. Unfortunately, neither works well with istanbul. |
Based on the comment in this same issue this is my mocha task:
|
Add build status to README gulp test hangs - sindresorhus/gulp-mocha#54
Add build status to README gulp test hangs - sindresorhus/gulp-mocha#54
Add build status to README gulp test hangs - sindresorhus/gulp-mocha#54
Add build status to README gulp test hangs - sindresorhus/gulp-mocha#54
Personally I need mongoose to connect on begin and disconnect when all tests are finished. So in every test I require:
|
Hi,
I am running a simple test (its failing, but that a separate issue).
Using:
When I run this using Gulp-Mocha (it happens on Travis as well), it does not exit the testing execution, but when I run this using Mocha, it fails, and exits back to the command prompt.
The text was updated successfully, but these errors were encountered: