Passing arguments to Intern tests

theinternWe have started to use Intern to test MAGICapp, a medical guideline authoring application we are currently working on. I wanted the flexibility to run a test against any of our environments and didn't want to hard code the server host name into the test. After looking through the Intern wiki and related blog posts I found nothing to explain how to pass an arguments into a test.

Digging in the source of the Intern I found 'intern/lib/args' which has the following comment in the top of the file:

/**
 * A hash map of arguments passed to the application.
 * This code expects that arguments are passed as key=value
 * pairs, either in the query string (if in browser) or on
 * the command line (if in Node.js). Arguments passed
 * with a key but no value are assumed to be boolean flags.
 * Keys with - or -- prefixes will have the prefix stripped.
 */

So if you include 'intern/lib/args' into your tests you'll be able to pass the host you want to test against. You could pass other things like if the test should be 'read' or 'write' as you may not want to run tests that change data again your production application.

define([
  'intern!object',
  'intern/chai!assert',
  'require',
  'intern/lib/args'
], 
function (registerSuite, assert, require, args) {

    registerSuite({
        name: 'login',

        'login': function() {
            return this.remote.get('http://'+args.appHost+'/login');
        }
    })
})

You can then pass arguments via the command line when you start you tests.

$./intern/bin/intern-runner.js config=tests/intern-local appHost=localhost:8080

Feel free to reach out to us with your web application automation questions or needs.