Jasmine test results not being picked up by teamcity

I've setup a jasmine test on teamcity using phantomjs.  While the build runs fine, teamcity isnt picking up the test results (success or failures).
When I run the test manually on the command line, I can see the results as expected. I've setup the job as a command line step, but teamcity just shows the build as Success and no tests tab
Is there anyway to track down why its not picking up the results? here is my build log:

[15:43:18]Checking for changes [15:43:26]Publishing internal artifacts [15:43:26][Publishing internal artifacts] Sending build.start.properties.gz file [15:43:26]Clearing temporary directory: D:\TeamCity\buildAgent\temp\buildTmp [15:43:26]Checkout directory: D:\TeamCity\buildAgent\work\6f113024b6b178f2 [15:43:26]Updating sources: server side checkout [15:43:26][Updating sources] Building incremental patch for VCS root: Master (1) [15:43:26][Updating sources] Repository sources transferred [15:43:26][Updating sources] Updating D:\TeamCity\buildAgent\work\6f113024b6b178f2 [15:43:26]Starting: d:\teamcity\lib\phantomjs.exe D:\TeamCity\buildAgent\work\6f113024b6b178f2\scripts\tests\testrunner.js D:\TeamCity\buildAgent\work\6f113024b6b178f2\scripts\tests\testrunner.html [15:43:26]in directory: D:\TeamCity\buildAgent\work\6f113024b6b178f2 [15:43:27]Loading D:\TeamCity\buildAgent\work\6f113024b6b178f2\scripts\tests\testrunner.html [15:43:27]Process exited with code 0 [15:43:27]Publishing internal artifacts [15:43:27][Publishing internal artifacts] Sending build.finish.properties.gz file [15:43:27]Build finished



the phantomjs script is:
 
var args = require("system").args;
if (args.length !== 2) {
   console.log('You must pass the jasmine test page as the 2nd argument');
   console.log('ie file:///D:/path_to_scripts_folder/Tests/testRunner.html');
   phantom.exit();
}
var url = args[1];
console.log('Loading ' + url);
var page = new WebPage();
phantom.viewportSize = {width: 800, height: 600};
//This is required because PhantomJS sandboxes the website and it does not show up the console messages form that page by default
page.onConsoleMessage = function (msg) {
    console.log(msg);
 
    if (msg && msg.indexOf("##jasmine.reportRunnerResults") !== -1) {
        phantom.exit();
    }
};
//Open the website
page.open(url, function (status) {
   //Page is loaded!
   if (status !== 'success') {
      console.log('Unable to load the address!');
      phantom.exit();
   } else {
      //Using a delay to make sure the JavaScript is executed in the browser
      window.setTimeout(function () {
         page.render("output.png");
         phantom.exit();
      }, 200);
   }
});


and the test runner.html
 
<html>
<body>
<script src="../jasmine/jasmine.js" ></script>
<script src="../jasmine/jasmine-html.js" ></script>
<script src="jasmine-teamcity.js"></script>
<script>
describe("Basic Suite", function() {
            it("Should pass a basic truthiness test.", function() {
                expect(true).toEqual(true);
            });
 
            it("Should fail when it hits an inequal statement.", function() {
                expect(1+1).toEqual(3);
            });
          });
 
   jasmine.getEnv().addReporter(new jasmine.TeamcityReporter());
   //jasmine.getEnv().addReporter(new jasmine.TrivialReporter());
   jasmine.getEnv().execute();
</script>
</body>
</html>
4 comments
Comment actions Permalink

Hi Steven,


Do you see TeamCity service messages when you run the script in console?
If you do not, you should probbaly double-check your configuration and search for the tool-specific cause.

If you do, I'd try to investigate why the build behaves in different manner inside TeamCity.

If you couldn't figure out the issue, please attach output of the tool when run manually in console and full build log (in Tree view/verbose mode or even raw log file downloadable in verbose mode).

0
Comment actions Permalink

Hi
Yes - I checked and I see the ##teamcity service messages
I'll run through the details on the invesigation link and post back - thanks

0
Comment actions Permalink

turns out it was due to the way I was passing in my test runner html file to phantomjs.  When I ran from the command line I had a slightly different syntax (forward slashes not back slashes) and that was the issue


In case anyone else needs a solution, I have this as my build command:
%teamcity.build.workingDir%\WebDir\scripts\tests\testrunner.js file:///%teamcity.build.workingDir%/WebDir/scripts/tests/testrunner.html

and testrunner.js, which loads the file and reports back results to teamcity.
var args = require("system").args;


if (args.length !== 2) {
   console.log('You must pass the jasmine test page as the 2nd argument');
   
console.log('ie file:///D:/path_to_scripts_folder/Tests/testRunner.html');
   phantom.exit();
}




console.log('Passed in ' + args[1]);


var url = args[1];
console.log('Loading ' + url);


var page = new WebPage();


phantom.viewportSize = {width: 800, height: 600};


//This is required because PhantomJS sandboxes the website and it does not show up the console messages form that page by default


page.onConsoleMessage = function (msg) {
    
console.log(msg);

    
if (msg && msg.indexOf("##jasmine.reportRunnerResults") !== -1) {
      console.log('all done');  phantom.exit();
    }


};


//Open the website


page.open(url, function (status) {
   
//Page is loaded!
   
if (status !== 'success') {
      
console.log('Unable to load the address!');
      
phantom.exit();
   }
else {
      
console.log('all ok - setting timeout to capture output');
//Using a delay to make sure the JavaScript is executed in the browser
     
window.setTimeout(function () {
    
console.log('capture');     
page.render("output.png");
         
phantom.exit();
      }, 200);
   
}


});



TestRunner.html just references jasmine, jasmine-teamcity, and my test files
0
Comment actions Permalink

We recently published an updated article which covers the setup of TeamCity for automated headless testing of Javascript code - both Jasmine and CasperJS - in detail.
If you should have similar problems with your TeamCity setup in future this article might help to solve them.

Check it out here: http://www.jrubyonrails.de/2013/03/continuous-integration-for-jasmine--and-casperjs-tests.html

0

Please sign in to leave a comment.