How can we run JavaScript jasmine tests from Jenkins (Hudson) without loading a JSP?

22,842

Solution 1

Sounds like you're in a Java environment. My jasmine-maven-plugin might be a good fit.

Solution 2

Jasmine Reporters would also be a solution. It has instructions for running headlessly via PhantomJS for example, and it can generate JUnit XML so Jenkins can understand the test results natively, graphing test count, duration, and failure over time.

Also, the "xvfb-run" wrapper often provided with xvfb is a great help here, so you can do "xvfb-run phantomjs.runner.sh ..." in a truly headless environment.

Solution 3

I've previously solved this problem by running the tests with a node.js plugin called jasmine-node

This solution of course requires node.js and a few node modules to properly run the jasmine tests. There is no real browser running the tests, but an emulated one using a module called jsdom, which basically creates a headless browser, and more specifically, a DOM, which the tests can interact with.

There's node modules for jQuery, underscore and propably other too, so these can be tested too. You can even skip the whole browser emulation if you'd rather run the tests in a browser, though I find it too cumbersome compared to automated Jenkins testing.

jasmine-node generates jUnit test reports, which Jenkins can interpret just fine.

I just realized there is some jenkins-jasmine-node plugin that might ease this process.

Solution 4

Grunt is your friend

got this setup and it's really nice, plus this gives you a place to start making your build server do other nice things such as deployment, unit testing, etc you know, other nice things

Share:
22,842

Related videos on Youtube

finneycanhelp
Author by

finneycanhelp

I love people, creating solutions, and technology.

Updated on July 12, 2022

Comments

  • finneycanhelp
    finneycanhelp almost 2 years

    We have a rich web client. Our controllers and service facades are written in coffeescript (JavaScript) and jquery. In the past they would have been java.

    To run our JavaScript jasmine tests from Jenkins/Hudson, we use java's junit and htmlunit to load a test oriented jsp page which includes the jasmine specs.

    When the Htmlunit tries to run, it blows up trying to getPage() probably because of an XML parser class path which is extremely challenging to track down in our world.

    We just want to be able to run our JavaScript tests from Jenkins and have it report failure if a JavaScript test does not pass. We are just using jsp and htmlunit in order to run JavaScript tests. Can we load the JavaScript tests and javascript code into a JavaScript engine with Jenkins as the thing that kicks it off? If so, how?

  • finneycanhelp
    finneycanhelp over 12 years
    Thank you for your reply. It's a fair question. I am back to the question of how to get Jenkins to kick off selenium, to run Jasmine tests, to see results.
  • finneycanhelp
    finneycanhelp over 12 years
    Thank you. Your code is awesome and I appreciate your contribution. Yes, I'm in a Java environment and your code inspired a solution in it. I would prefer to skip using Java to run Jasmine and have something in jenkins just kick off the jasmine tests. Sounds like I should make a jenkins plugin request.
  • Chris R
    Chris R almost 9 years
    "start making your build server do other nice things such as"...?
  • aqm
    aqm almost 9 years
    deployment, unit testing, etc you know, other nice things
  • Andrew Gray
    Andrew Gray over 8 years
    @sarel-botha: Take a look at: 1. SauceLabs, 2. Sauce OnDemand plugin and Saucery2 or Saucery3 NuGet packages to make your automated testing with Jenkins and SauceLabs easy