Access Intern Command Line Arguments

By  on  

SitePen's excellent client side testing tool, Intern, comes with an excellent command line utility to run tests and customize how those tests are run.  The options provided are great but what if I want to make the command line more dynamic?  What if I want to add custom command line arguments, available to tests, to pass along important information like sensitive credentials (which you don't want hard-coded in config files) or you simply want to allow overwriting of values within the static config file?  It's actually quite easy:

define(['intern'], function(intern) {
	
	if(intern.args.someCustomArg != undefined) {

		/* use the custom command line arg */

	}
});

The intern module provides you the provided arguments via the args property.  From there you can pick off the argument values as you wish.  So what do I pass in via the command line?

  • Login credentials for the test to use
  • The domain I want to test (local dev, staging, production)
  • Select browsers I want to test (i.e. I don't want to run all of them cited in the config)

What you could add is specific to your app, but be glad it's so easy to do!

Recent Features

  • By
    Interview with a Pornhub Web Developer

    Regardless of your stance on pornography, it would be impossible to deny the massive impact the adult website industry has had on pushing the web forward. From pushing the browser's video limits to pushing ads through WebSocket so ad blockers don't detect them, you have...

  • By
    7 Essential JavaScript Functions

    I remember the early days of JavaScript where you needed a simple function for just about everything because the browser vendors implemented features differently, and not just edge features, basic features, like addEventListener and attachEvent.  Times have changed but there are still a few functions each developer should...

Incredible Demos

  • By
    Making the Firefox Logo from HTML

    When each new t-shirt means staving off laundry for yet another day, swag quickly becomes the most coveted perk at any tech company. Mozilla WebDev had pretty much everything going for it: brilliant people, interesting problems, awesome office. Everything except a t-shirt. That had to change. The basic...

  • By
    CSS Scoped Styles

    There are plenty of awesome new attributes we've gotten during the HTML5 revolution:  placeholder, download, hidden, and more.  Each of these attributes provides us a different level of control over an element on the page, but there's a new element attribute that allows...

Discussion

    Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!