pghalliday / grunt-mocha-test

https://www.npmjs.com/package/grunt-mocha-test
MIT License
362 stars 61 forks source link

Multiple reporters #105

Closed fcaraujo closed 9 years ago

fcaraujo commented 9 years ago

Hi, How about change options.reporter for an array?

Thanks

pghalliday commented 9 years ago

i don't think mocha supports multiple reporters. I have used the mocha-multi module to add this functionality in the past

https://www.npmjs.com/package/mocha-multi

fcaraujo commented 9 years ago

In fact, I did a little research and it's came up before create this, but the ideia is we find a way to workaround while it's not supported. I read here that's a day we'll have it in production: http://www.juliengilli.com/2013/12/14/Using-multiple-reporters-with-Mocha/ What do you think?

pghalliday commented 9 years ago

tbh, I think the workaround is to use mocha-multi, I haven't tried it in a config of my own. But I think it will work if you add your task like this:

    // Configure a mochaTest task
    mochaTest: {
      test: {
        options: {
          reporter: 'mocha-multi',
          reporterOptions: {
            Progress:{ 
              stdout:"/tmp/mocha-multi.Progress.out",
              options: {
                verbose: true
              }
           },
           spec: {
              stdout:"-"
           }
        },
        src: ['test/**/*.js']
      }
    }

Derived from the programatic example on the mocha-multi README. It should work because the options block here will be passed directly to the mocha constructor

fcaraujo commented 9 years ago

Great! I'll try it when possible and return a feedback soon. Thanks!

fcaraujo commented 9 years ago

I believe that was close, although I don't know all the workflow behind the scenes and didn't work exactly as expected, my config:

mochaTest: {
    test: {
        src: watchFiles.mochaTests
        , options: {
            require: 'server.js'
            //, reporter: 'spec' // doc
            //, captureFile: 'report/mocha.txt' // html
            , reporter: 'mocha-multi'
            , reporterOptions: {
                Progress:{
                    stdout: 'report/mocha.txt',
                    //stdout:"-",
                    options: {
                        verbose: true
                    }
                },
                spec: {
                    stdout:"-"
                }
            }
        }
    }
    , coverage: {
        options: {
            reporter: 'html-cov',
            quiet: true,
            captureFile: 'report/coverage/back/mocha_result.html'
        },
        src: [
            //'app/**/*.js'
            'app/tests/*.js'
            //'app/controllers/**/*.js'
            //, 'app/models/**/*.js'
            //, 'app/modules/**/*.js'
            //, 'app/routes/**/*.js'
        ]
    }
}

If I use reporter: 'mocha-multi' the task is not finished, I run my grunt but the console doesn't return (even failing a test or not). With reporter: 'spec'it's ok.

Thanks

pghalliday commented 9 years ago

I just tested with this project

https://github.com/pghalliday/grunt-mocha-multi

Worked fine for me

pghalliday commented 9 years ago

Closing as not reproducible