The Node and browser built-in runners load configuration information from the command line / query args and/or a config file. There are no special command line flags; in both cases, command line options are config properties.
The node runner is a built in script for running Node-based unit tests and WebDriver tests. Usage can be very simple:
$ node_modules/.bin/intern
Of course, it can be called from a package.json
file even more simply:
{
"scripts": {
"test": "intern"
}
}
By default, the runner looks for an intern.json
config file in the project root. This can be changed by providing a config
property on the command line, like config=tests/myconfig.json
. The runner will also accept any other config properties as command line arguments. For example,
$ node_modules/.bin/intern suites=tests/foo.js grep=feature1
would only load the suite in tests/foo.js
, and would only run tests containing the string ‘feature1’ in their IDs.
The browser runner is a built-in HTML page for running browser-based unit tests. To use it, serve the project root directory using a static webserver and browse to (assuming the server is running on port 8080):
http://localhost:8080/node_modules/intern/
Similar to the Node runner script, the browser runner will accept a config argument, or any other config properties, as query args.
http://localhost:8080/node_modules/intern/?suites=tests/foo.js&grep=feature1
Note that the browser runner can only be used to run unit tests, not functional (i.e., WebDriver) tests.
Intern includes a Grunt task that can be loaded with
grunt.loadNpmTasks('intern');
The task may be configured using the same options as are used in an intern.json
file. For example, consider the following intern.json
file:
{
"suites": "tests/unit/**/*.js",
"require": "tests/pre.js",
"loader": {
"script": "dojo",
"config": {
"packages": [{"name": "app", "location": "."}]
}
}
An equivalent Grunt config that used the Node executor would look like:
module.exports = function (grunt) {
grunt.initConfig({
intern: {
node: {
options: {
suites: "tests/unit/**/*.js",
require: "tests/pre.js"
"loader": {
"script": "dojo",
"config": {
"packages": [{"name": "app", "location": "."}]
}
}
}
}
}
});
// Loading using a local git copy
grunt.loadNpmTasks('intern');
};
Note that the Grunt task runner doesn’t use the config file loading logic employed by the Node and browser runners. The assumption is that Grunt will be used to construct the desired config.
Intern may also be configured and run with a custom script. The basic steps this script must perform are:
- Import/require the Node executor
- Construct a new instance of Node and assign it to the
intern
global. The config should include at least one suite and a reporter.global.intern = new Node({ suites: 'tests/unit/a.js', reporters: 'runner' });
- Call
intern.run()
Intern may be configured and run in a browser with a custom HTML page. The basic steps are:
- Load the Browser executor (
<script src="node_modules/intern/browser/intern.js"></script>
). Theintern.js
script will automatically initialize a Browser executor and assign it to anintern
global. - Configure the executor. Include at least one suite at a reporter.
intern.configure({ suites: 'tests/unit/a.js', reporters: 'html' });
- Call
intern.run()
When running functional tests, Intern communicates with remote browsers using WebDriver. To do this, it either uses a browser-specific WebDriver server, generally managed by Selenium, or a remote testing service such as BrowserStack.
To use a bare WebDriver, such as chromedriver, use the following steps:
- Download the latest version of the WebDriver
- Set the
tunnel
config property to'null'
- Run the WebDriver on port 4444 with a base URL of 'wd/hub'. Alternatively, using the
tunnelOptions
config property, setport
to a particular port andpathname
to the WebDriver’s base URL). - Set the
environments
config property to 'chrome'. - Run Intern
💡 To verify that the WebDriver is running on the proper port and path, open a browser to
http://localhost:4444/wd/hub/status. It should return a JSON response with a
status` field of 0.
If you’d rather let Intern manage WebDrivers, you can use Selenium. Intern defaults to using the 'selenium' tunnel, so configuration is simpler than for a bare WebDriver.
- Set the
environments
config property to the name of the desired browser ('chrome', 'firefox', etc.) - If using 'firefox' or 'internet explorer', also provide the driver name in the
tunnelOptions
config property:{ "tunnelOptions": { "drivers": [ "firefox" ] } }
- Run Itnern
Intern comes with built-in support for 4 cloud testing services via the digdug library: BrowserStack, CrossBrowserTesting, Sauce Labs, and TestingBot. Basic usage for each of these is provided in the following sections.
💡 Cloud hosts typically have their own unique capabilities options, so be sure to read the capabilities documentation for the provider you’re using.
- Sign up for BrowserStack Automate
- Get your Automate username and password from the Automate account settings page
- Set the
tunnel
config property to'browserstack'
- Set your username and access key in one of these ways:
- Define
BROWSERSTACK_USERNAME
andBROWSERSTACK_ACCESS_KEY
environment variables - Set
browserstackUsername
andbrowserstackAccessKey
in your Gruntfile’s intern task options - Set
username
andaccessKey
on yourtunnelOptions
configuration option
- Define
- Run Intern
- Sign up for a trial account
- Get your authkey from your account settings page
- Set the
tunnel
config property to'cbt'
- Set your username and access key in one of these ways:
- Define
CBT_USERNAME
andCBT_APIKEY
environment variables - Set
cbtUsername
andcbtApikey
in your Gruntfile’s intern task options - Set
username
andaccessKey
on yourtunnelOptions
configuration option
- Define
- Run Intern
- Sign up for a Sauce Labs account
- Get your master account access key from the sidebar of the Account settings page, or create a separate sub-account on the sub-accounts page and get a username and access key from there
- Set the
tunnel
config property to'saucelabs'
- Set your username and access key in one of these ways:
- Define
SAUCE_USERNAME
andSAUCE_ACCESS_KEY
environment variables - Set
sauceUsername
andsauceAccessKey
in your Gruntfile’s intern task options - Set
username
andaccessKey
on yourtunnelOptions
configuration option
- Define
- Run Intern
- Sign up for a TestingBot account
- Get your API key and secret from the Account settings page
- Set the
tunnel
config property to'testingbot'
- Set your API key and secret in one of these ways:
- Define
TESTINGBOT_KEY
andTESTINGBOT_SECRET
environment variables - Set
testingbotKey
andtestingbotSecret
in your Gruntfile’s intern task options - Set
username
andaccessKey
on yourtunnelOptions
configuration option
- Define
- Run Intern