开发者

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

开发者 https://www.devze.com 2023-04-10 05:56 出处:网络
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.

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 java开发者_运维知识库script code into a JavaScript engine with Jenkins as the thing that kicks it off? If so, how?


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


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.


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.


Grunt is your friend

  • use grunt http://gruntjs.com/
  • with grunt jasimine https://github.com/gruntjs/grunt-contrib-jasmine
  • with nodejs http://nodejs.org/
  • on jenkins using https://wiki.jenkins-ci.org/display/JENKINS/NodeJS+Plugin

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


Can you use selenium? That would actually use a real browser then and get as close to the real environment as possible.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号