I'm extremely pleased to be able to write this post for you. Running Javascript tests as part of your Jenkins build with Jasmine 2.2.0 is actually, and refreshingly, pretty easy.
- Download and install PhantomJS (currently v2.0) from here.
- Copy the contents of the zip file to C:\Program Files (x86)
- Create an environment variable called PHANTOMJS_HOME with value C:\Program Files (x86)\phantomjs-2.0.0-windows.
- Add %PHANTOMJS_HOME%\bin; to the beginning of the Path environment variable.
- At this point we want to test that PhantomJS is installed properly. Open a Command Prompt and execute phantomjs -h. You should see the PhantomJS help output. If you saw that, we're good to continue.
- Create a new Freestyle job in Jenkins, setting the Git Repository URL to https://github.com/detro/phantomjs-jasminexml-example
- Add a Windows batch command build step with the following two commands:
- Add a Publish xUnit test result report post-build action
- In this post-build action click the Add button and select JUnit
- Set the JUnit Pattern to jasmineTestResults/*.xml
- In the Failed Tests section set all 4 Build Status Thresholds to 1
- Save the build configuration
- Run the build
- Pat yourself on the back, because 7 tests ran!
del jasmineTestResults /s /q
phantomjs test/phantomjs_jasminexml_runner.js test/test_runner.html jasmineTestResults/
No need to include exit %%ERRORLEVEL%% as phantomjs_jasminexml_runner.js takes care of this for you internally.
I'll leave it as an exercise for you to take a look at the example code to see how it is structured. Should be easy for you to transpose to your own project.
The key files to look at when considering how to transpose to your own project:
- src/tv.js
- test/test_runner.html
- test/test_spec.js
test/phantomjs_jasminexml_runner.js does not have to be altered at all.
Till next time...
No comments:
New comments are not allowed.