JamesMGreene / qunit-reporter-junit

A QUnit plugin for producing JUnit-style XML test reports.
Other
42 stars 33 forks source link

Patch for when QUnit.start can't be intercepted #8

Closed dexygen closed 7 years ago

dexygen commented 11 years ago

I need to be able to use both Qunit's normal html output and xml output (when running a number of tests all from phantomjs). So I am unable to easily hook into QUnit.start because of how the existing code for html-output is structured, and therefore I was getting errors when QUnit.done tried to access currentRun which never got initialized.

My solution is not unlike some code you have at the top of QUnit.testStart ("// Setup default module if no module was specified"), but at the top of QUnit.done instead:

QUnit.done(function(data) {
    // Setup currentRun if unable to intercept QUnit.start
    if (!currentRun) {
        currentRun = {
                modules: [],
                total: 0,
                passed: 0,
                failed: 0,
                start: new Date(),
                time: 0
            };          
    }

Hope this helps

dexygen commented 11 years ago

I've added the same block of code to the top of QUnit.moduleStart since after assigning to currentModule it references currentRun i.e.: currentRun.modules.push(currentModule);

JamesMGreene commented 7 years ago

Is there a reason why you cannot add the "qunit-reporter-junit.js" script before QUnit begin executing tests? Given that you filed this issue over 3 years ago, I'm thinking you may have just been running into an old bug in QUnit core that has since been fixed (by me, if memory serves) for quite some time now where the QUnit.begin logging callbacks were being called way too early.

JamesMGreene commented 7 years ago

If this is still a problem for you with the latest QUnit 1.x or 2.x, please let me know and we can reopen the issue. Thanks!