pghalliday/grunt-mocha-test

Exits with exit code 0 after failing tests

adomasven opened this issue · 3 comments

After running tests with the plugin, the exit code is 0, which means that CI tools like Codeship and Travis assume the tests passed, when they actually failed:

--------------------- (develop) Sat Nov  8 15:35:05 GMT 2014
adomas@paprika:~/some_repo
→ NODE_ENV=test grunt mochaTest:models
Running "mochaTest:models" (mochaTest) task


  NOpenListAuthor
    #_sendEmail
      ✓ should send email and notification 
      ✓ should not send email if disabled by user 
      ✓ should throw error when idx out of bounds 
    #event
      ✓ should not notify if date is earlier than threshold 
      1) should notify if not notified yet
      2) should notify if notified once and subCount > 9 than initial
      3) should notify if notified twice and subCount > 49 than initial
      ✓ shouldn't notify if subCount < 10 and notified once 
      ✓ shouldn't notify if subCount < 50 and notified twice 
      ✓ shouldn't notify if notified three times 
    #notify
      ✓ has correct tokens on idx === 0 
      ✓ has correct tokens on idx === 1 
      ✓ has correct tokens on idx === 2 


  10 passing (50ms)
  3 failing

  1) NOpenListAuthor #event should notify if not notified yet:
     Uncaught AssertionError: expected false to be true


  2) NOpenListAuthor #event should notify if notified once and subCount > 9 than initial:
     Uncaught AssertionError: expected false to be true


  3) NOpenListAuthor #event should notify if notified twice and subCount > 49 than initial:
     Uncaught AssertionError: expected false to be true




Warning: Task "mochaTest:models" failed. Used --force, continuing.

Done, but with warnings.
--------------------- (develop) Sat Nov  8 15:35:27 GMT 2014
adomas@paprika:~/some_repo
→ echo $?
0

I see that you used the --force flag with grunt.

Warning: Task "mochaTest:models" failed. Used --force, continuing. 

This overrides the default grunt behaviour of stopping on failed tasks and exiting with a non zero code. If you think this is wrong then you need to raise an issue on the grunt project. However I can't see any other tasks running after the tests, so why use --force?

If it is an earlier task that you needed to force then you might be interested in another grunt plugin I created that allows you to turn force on and off during a grunt run.

https://www.npmjs.org/package/grunt-continue

Just remember to turn continue off before running the tests.

Yep, that makes sense. I stitched the Gruntfile from a couple different ones and did not realize it included
grunt.option('force', true);. Changing that fixes it, thanks!

Cool, no problem