17

We have been writing specifications for our JavaScript business logic using Jasmine. We're able to run our test suite within a browser, but how would we integrate this within TeamCity? Preferrably we do not want to use NodeJS, rather something as simple as possible.

1 Answer 1

17

I have created a modified version of run-jasmine.js that is found in the PhantomJS sources (original version is here. This version can be used within TeamCity (it will automatically detect that it is running in TeamCity). This updated version is using TeamCity service messages which allows for a nice integration.

You will need PhantomJS. You'll also need one of the following:

Add a build step in your TeamCity build configuration that can run this step:

phantomjs.exe run-jasmine.js index.html

index.html is your Jasmine runner page. If the build agents do not include PhantomJS, you can commit it to your repository along with your sources (this is what we do).

The result will look like this:

Tests Overview

Test details: Test Details

The above is from a Tasks sample ASP.NET MVC project with this setup. It can be run in TeamCity using a Visual Studio (sln) build step. It will also run the tests within Visual Studio, as a pre-build step.

7
  • 1
    Daniel - thank you for the script and the explanation. Worked for me almost instantly. 2 quirks I had: Jasmine runs files from a different folder with "/folder/file.js" syntax, while Phantom apparently requires "../folder/file.js". And it wasn't clear that Team City needs command line build step. Jan 27, 2014 at 14:06
  • @IliaBarahovski Yes, the current working directory could be different from one solution to another, depending on how you setup your directories. Anyway, nice to hear you got it working! Jan 27, 2014 at 15:26
  • @DanielLidström - Thanks for your clarification. But I could not able to run the jasmine tests in teamcity. Added the phantomjs.exe and run-jasmine.js from the link which is provided there. If possible provide a link ,if you are having any sample source or GIT link. Jun 11, 2014 at 14:58
  • @PandiyanCool Here is a complete sample: github.com/dlidstrom/Tasks. I am able to build it continuously using a Solution build step within TeamCity, and the tests are run automatically as a pre-build step. Let me know how this works out for you. Jun 12, 2014 at 5:41
  • @DanielLidström - Thanks once again. I was able to run jasmine tests for sample application in teamcity.But in my application, I am using knockout.js, require,js, So that I was getting "Reference Error: Can't find variable: jasmine". Error: Mismatched anonymous define() module TypeError: 'null' is not an object (evaluating 'document.body.querySelector('.alert > .passingAlert.bar').innerText') phantomjs://webpage.evaluate():58 phantomjs://webpage.evaluate():61 phantomjs://webpage.evaluate():61 Could you help me out with that please? Jun 13, 2014 at 6:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.