Search code examples
javascriptmocha.jssaucelabs

mocha tests time out on Saucelabs


I'm just learning to use mocha and Saucelabs so I'm likely making a noob mistake here.

My tests run fine in my browser. They also run fine in a manual session at Saucelabs. But when I run them using the REST interface they time out. Looking at the screen capture I can see that the tests all succeeded. Sauce just didn't notice.

I sent the command to the REST interface like this:

curl https://saucelabs.com/rest/v1/gbthr/js-tests \ -X POST \ -u gbthr:00000000-0000-0000-0000-000000000000 \ -H 'Content-Type: application/json' \ --data '{ "platforms": [ ["Linux", "googlechrome", ""]], "url": "http://gbserver3.cs.unc.edu/theme/tests/testStore.html", "framework": "mocha"}'

with those 0000's replaced by my id.

Is there some additional step I have to do in my test to notify saucelabs?


Solution

  • I discovered the answer here: https://github.com/axemclion/grunt-saucelabs

    On test end you add the results to window.mochaResults.

    var runner = mocha.run();
    
    var failedTests = [];
    runner.on('end', function(){
      window.mochaResults = runner.stats;
      window.mochaResults.reports = failedTests;
    });
    
    runner.on('fail', logFailure);
    
    function logFailure(test, err){
    
      var flattenTitles = function(test){
        var titles = [];
        while (test.parent.title){
          titles.push(test.parent.title);
          test = test.parent;
        }
        return titles.reverse();
      };
    
      failedTests.push({name: test.title, result: false, message: err.message, stack: err.stack, titles: flattenTitles(test) });
    };