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 when using the built-in runners; 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:
$ npx intern
It can also be run using the "test" script property from a package.json
:
{
scripts: {
test: 'intern'
}
}
$ npm test
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,
$ npx 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.
💡 Intern decides what environments to run tests in based on the value of the environments config property. If
environments
isn’t set, Intern adds 'node' to it, so that tests will be run in Node. Ifenvironments
is set, Intern will only run tests in the specified environments.
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/
Intern also has its own static server that can be started with the serveOnly
config argument:
npx intern serveOnly
This command will cause Intern to start a static server on the port set by
serverPort
(9000 by default).
💡Intern’s server must be used with the browser client when using glob expressions to specify suites.
Similar to the Node runner script, the browser runner will accept a config argument, or any other config properties, as query args.
http://localhost:9000/node_modules/intern/?suites=tests/foo.js&grep=feature1
💡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',
plugins: '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',
plugins: '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 'intern' package. This will instantiate a Node executor
and assign it to the
intern
global. - Configure the executor. Include at
least one suite and a reporter.
intern.configure({ suites: 'tests/unit/a.js', reporters: 'runner' });
- Call
intern.run()
A very simple run script might look like:
import intern from 'intern';
intern.configure({ suites: 'tests/unit/**/*.js' });
intern.run();
See Intern’s own run script for a more complex example.
Intern may be configured and run in a browser with a custom HTML page. The basic steps are similar to those for a custom Node script:
- 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 and 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, set
port
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 not manage WebDriver binaries individually, 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 Intern
⚠️ Note that the library Intern uses to manage Selenium and WebDrivers tracks the current versions of those applications; this allows new installs of Intern to work with current browser versions. However, this can also cause Intern to stop being able to drive older versions of browsers. If you need Intern to work with a specific version of a browser, pin your config to specific versions of Selenium and the WebDrivers:
{
tunnelOptions: {
// Selenium version
version: '3.4.1',
drivers: [
// WebDriver verisons
{ name: 'chrome', version: '2.33' },
{ name: 'firefox', version: '0.17.0' }
]
}
}
Intern comes with built-in support for four 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 your tunnelOptions 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 your tunnelOptions 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 your tunnelOptions 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 your tunnelOptions configuration option
- Define
- Run Intern