Fullstack

Your partners in developing agile software and great customer experiences

  • Projects
  • About Us
  • Blog

Passing arguments to Intern tests

July 15, 2014 by Deno Vichas

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:

1
2
3
4
5
6
7
8
/**
* 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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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.

1
$./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.

Filed Under: Blog, Tips and Tricks Tagged With: javascript, testing, web applications

Recent Blog Posts

  • Simplify SSH access to your AWS ec2 instances
  • A new github project – pubmed_j
  • FullStack gets a shout-out in a BMJ article
  • Stylish, and accessible, ordered lists with LESS CSS
  • Passing arguments to Intern tests
  • Email
  • Linkedin
  • Twitter

© 2015

Recent Blog Posts

  • Simplify SSH access to your AWS ec2 instances
  • A new github project – pubmed_j
  • FullStack gets a shout-out in a BMJ article
  • Stylish, and accessible, ordered lists with LESS CSS
  • Passing arguments to Intern tests
  • Email
  • Linkedin
  • Twitter

Copyright © 2019 · Epik Theme on Genesis Framework · WordPress · Log in