Fatal error causes Mocha to exit #16

Open
itsjamie opened this Issue Jan 23, 2013 · 9 comments

Projects

None yet

5 participants

@itsjamie

Hello! I believe the issue is in the grunt task itself upon further inspection..

Example

@yaymukund yaymukund was assigned Jan 26, 2013
@yaymukund
Owner

Hmm, I can't replicate this, and I'm inclined to think it's a bug with the Mocha API interface.

But I'll take a closer look when I get a chance. I'd love to build on the Mocha API interface when I get some time..

@itsjamie

Yea.. I didn't run into this error until I started adding in Webdriver tests via GhostDriver on phantomJS, so maybe there needs to be something additional added, I'll also be looking and see if I can get a solution. As it would be great to not have to use a hacked together solution with alerts and AJAX bridges etc to get front-end testing now that we have a proper selenium driver for PhantomJS.

Thanks for any effort you put in ๐Ÿ‘

Hopefully the magic ๐ŸŽฑ will help me in my quest :)

@yaymukund
Owner

Thanks for the issue! Are you already aware of the wildly popular grunt-mocha? It's designed for tests using PhantomJS, and there seems to be a lot of code dedicated to printing the results correctly.

I mainly didn't like its dependency on PhantomJS, but you're already using PhantomJS so maybe that won't be an issue for you.. :)

@itsjamie

The only reason I haven't hopped over to grunt-mocha is that the project was to support testing on PhantomJS before it was supported. Now, PhantomJS provides a native WebDriver called GhostDriver. So the way that grunt-mocha communicates is neat, but unneeded now. I haven't looked deeply at the source for it but I know older similar types of libraries used iframe + alerts to provide communication, I'd rather be able to use the JSONWireProtocol. I may just use grunt exec or shell and run mocha directly to get the results.. Hm.

@gregrperkins

This is a pretty gnarly issue and has been bugging me for a while... Mocha needs uncaughtExceptions to be ignored when running under node, and grunt really doesn't like that (it exits grunt.fail.fatal hard on any of them: https://github.com/gruntjs/grunt/blob/master/lib/grunt.js#L58-60). Ben didn't want to modify that handler (gruntjs/grunt#592), so... https://github.com/gregrperkins/grunt-mocha-hack was my attempt, but it's really rather disgusting. Hopefully the domain solution will be less disgusting in the near future, once uncaughtExceptions don't propagate up (per nodejs/node-v0.x-archive#4375). I didn't want to use grunt-mocha since I expect node.js file interfaces and such in a lot of tests and code under test, and my impression is that those aren't replicated in phantom.

@gregrperkins

#29 if you think this is worth it

@Bartvds
Bartvds commented May 16, 2013

So it looks like 3 out of 3 serverside grunt + mocha modules on npm have this issue. Maybe you guy's should team up? :)

@Bochenski Bochenski referenced this issue in Gintellect/grunt-gint May 17, 2013
Open

mocha task explodes on first error #2

@searls
searls commented Sep 9, 2013

๐Ÿ‘ this appears to be an issue with how Mocha#run works. AFAIK it's exiting as soon as the first error is encountered.

Here's my own custom grunt task that also demonstrates this:

Mocha = require('mocha')

module.exports = (grunt) ->
  _ = grunt.util._

  grunt.registerMultiTask "spec", "run specs (under mocha)", ->
    done = @async()
    mocha = new Mocha(@options())
    @filesSrc.forEach(mocha.addFile.bind(mocha))


    grunt.file.expand("#{process.cwd()}/spec/helpers/**/*").forEach (f) -> require(f)

    mocha.run (errorCount) -> done(errorCount == 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment