Dojo FAQ: How can I run Dojo tests locally with Intern?

By on April 23, 2014 1:35 pm


Intern provides great tools for testing your application on multiple browsers and OSes. Running tests can sometimes be tricky, though. In particular, testing Dojo-based projects often trips up new users because Intern contains its own copy of Dojo, and the boundaries between this and your project’s Dojo can become blurry. Another area that can be confusing is how to run Intern tests locally rather than on Sauce Labs.

Testing Dojo projects

The main idea to keep in mind when testing Dojo projects is that your tests, and your application code, should be using your own copy of Dojo, not Intern’s. Say your project has the following layout:


Your tests will be loaded by Intern’s copy of Dojo, but they should use your project’s copy. You tell Intern where to find your application and support packages by configuring the loader property in your Intern test config file:

loader: {
    pacakges: [
        { name: 'app', location: 'app' },
        { name: 'dojo', location: 'lib/dojo' }

Check out the dojo-example in the intern-examples project on GitHub for a more in-depth example of how to test a Dojo-based project.

Testing locally

Intern’s default config file is setup to run tests on the Sauce Labs cloud-based testing service. Sauce is great for testing your application on many OS/browser combinations, but it’s time consuming, even for a single OS and browser. Running tests locally is much faster, and gives you the ability to debug your tests. Intern actually provides several ways to run tests locally:

  1. Use client.html in a browser
  2. Use the Node.js test client
  3. Run tests on a local WebDriver server

The first option is good for quickly checking that unit tests are running properly. Start a web server rooted in your project directory, open a browser and its development console, and browse to Intern’s client.html file (assuming your test config file is tests/intern.js):


The second option uses the lightning-fast Node.js client to run unit tests that don’t use the DOM. Run the client command in a terminal and results will display as tests run:

node node_modules/.bin/intern-client config=tests/intern

The third option is best for running unit tests in multiple browsers, and is the only option for running functional tests. The hardest part (and it’s not that hard) is setting up a WebDriver server:

  1. Download the Selenium standalone server
  2. Install any required web drivers
    • Firefox and Safari work out-of-the-box
    • Separate drivers are available for Chrome (chromedriver) and IE (InternetExplorerDriver))
    • Any added drivers need to be in a directory that’s in your PATH for
      Selenium to see them
  3. Update your test config
    • Set useSauceConnect to false
    • Prune the list of environments; you only need entries for the browser(s) on
      your system
  4. Start Selenium
    • java -jar /path/to/selenium-server-standalone.jar -port 4444

Once the WebDriver server is up, actually running the tests is simple:

node node_modules/.bin/intern-runner config=tests/intern

Test results will be displayed in the terminal after the tests have run. If you need to keep the browser window open after tests have completed, you can use the leaveRemoteOpen option:

node node_modules/.bin/intern-runner config=tests/intern leaveRemoteOpen

Learning more

More information about running Intern is available in the Intern wiki.

If you have any issues, we are using the popular Stack Overflow service to answer questions, and we of course cover Intern as part of our JavaScript support and Dojo workshops. We also offer assistance in helping organizations implement and refine their process for JavaScript testing. Let us know if you would like more information on how we can help your organization.