Skip to content

Using Bender with Jenkins

Grzegorz Pabian edited this page Aug 13, 2014 · 2 revisions

You can run your tests in Bender using Jenkins CI!

Configure Jenkins

In order to test your code in Bender and Jenkins, you'll have to configure Jenkins server properly.

Jenkins Plugins

Following Jenkins plugins will be required to run the tests in Bender:

  • NodeJS Plugin - this one is necessary to install and execute Bender.js and its modules
  • (Optional) Xvfb Plugin - might be needed to configure a virtual screen when running tests in a real browser
  • (Optional) Github Plugin - could be used to download your project from Github and/or run the tests when a change in the repository is made

For specific plugins' configurations check out their wiki pages.

Job configuration

We'll focus on three sections of Jenkins job's configuration:

Build environment

First of all, mark a checkbox next to Provide Node & npm bin/ folder to PATH and select one of the available installations.

Additionally, if you plan to use a real browser and have Xvfb plugin installed, mark a checkbox next to Start Xvfb before the build, and shut it down after.

Build

Add a new build step and choose Execute shell.

In the Command box type:

npm install && npm test

This will install all the NPM dependencies and execute NPM test script.

Post-build Actions

To get a better insight into the tests results, we can ask Jenkins to publish a JUnit report generated with benderjs-reporter-junit plugin.

To do this, press Add post-build action and select Publish JUNIT test result report.

In the Test report XMLs box type in a path to the report file. By default benderjs-reporter-junit puts the report file called bender-result.xml in the root directory. See the next section to find out how to change that.

Configure Bender

By default bender run command (used while integrating with CI tools) is executed headlessly in PhantomJS. However it is possible to change it to a real browser in the bender.js configuration file.

bender.js

var config = {
	applications: {...},

	framework: 'jasmine',

	plugins: [...],

    // override the default browser with Firefox
	startBrowser: 'firefox',

	tests: {...}
};

module.exports = config;

In case you want to generate a JUnit test result report, you'll have to add benderjs-reporter-junit plugin to your configuration file and configure it:

bender.js

var config = {
	applications: {...},

	framework: 'jasmine',

	plugins: ['benderjs-reporter-junit'], // add the plugin here
	
    jUnitReporter: {
        outputFile: 'test-results/result.xml' // custom path to the output XML file
    },

	startBrowser: 'firefox',

	tests: {...}
};

module.exports = config;

Configure a test script

Finally, we have to configure npm test command that will be called by Jenkins after running npm install:

package.json

{
    "name": "...",
    "description": "...",
    "dependencies": {...},
    "scripts": {
        "test": "bender run" // here we add our test command
    }
}

Please make sure that Bender.js and all of its required plugins are added to dependencies or devDependencies in package.json and Jenkins will install them with NPM before running the tests.

Clone this wiki locally