travisjeffery / mocha-teamcity-reporter

MIT License
40 stars 48 forks source link

options object missing causes "Cannot read property 'reporterOptions' of undefined" #39

Closed angelseye closed 6 years ago

angelseye commented 6 years ago

https://github.com/travisjeffery/mocha-teamcity-reporter/blob/df012a22a34d61b9d4588840f1197fce0cd0725c/lib/teamcity.js#L77

var reporterOptions = options.reporterOptions || {} works if options object is defined. When it's not defined, then it tries to read reporterOptions from undefined object.

jamie-sherriff commented 6 years ago

How do you reproduce this with test running? As mocha passes the reporter with its options that defaults to {} if undefined

angelseye commented 6 years ago

This is used in combination with grunt-mocha-blanket running tests using grunt in a command line. I don’t have the exact organization of the code on hand at the moment, but I can set up a temp project and get back to you with it. I have fallen back to 1.1.0 in the meantime for our project.

jamie-sherriff commented 6 years ago

Ah yep, i had a quick look at grunt-mocha-blanket and think i can see how it gets set to undefined, if i create a branch here will you be able to give it a test?

angelseye commented 6 years ago

Sure thing. Let me know when you have something to look at. I’d love to hear more about what you found, as if I need to make a setting change on our end to make sure it isn’t undefined, I am happy to do that. Just part of the whole upgrading process.

jamie-sherriff commented 6 years ago

@angelseye Sorry for the delay, please take a look at the branch undefined options

Or you can simply install with npm install travisjeffery/mocha-teamcity-reporter#undefined-options

Just stole the logic from the xunit reporter https://github.com/mochajs/mocha/blob/master/lib/reporters/progress.js

jaredreynolds commented 6 years ago

That works for me and is similar to the fix in @angelseye's fork. Is there anything holding this up?

jamie-sherriff commented 6 years ago

@jaredreynolds nope, more just waiting if grunt-mocha-blanket needed more changes to work. Are you using the same package or something different that causes this?

Can publish a new version with the current addition in the meantime.

jaredreynolds commented 6 years ago

Thank you! No, we aren't using grunt-mocha-blanket, just grunt. It could be a config thing since I'm just upgrading a very old test suite. Relevant grunt config fwiw:

grunt.initConfig({
...
    mochaTest: {
        test: {
            options: {
                reporter: process.env.TEST_REPORTER || 'spec',
                timeout: grunt.option('timeout') || 240000
            },
            src: ['<%= mocha.src %>']
        }
    },
...
});
angelseye commented 6 years ago

I've upgraded and tested our environment and it is working as expected. Thanks so much for an awesome quick fix. Lets hope the rest of my upgrades go as smoothly.