Intern 3 is here!

By on July 30, 2015 11:00 am

Today, we’re very happy to announce the release of Intern 3! This newest version of Intern is a culmination of several months of effort to overhaul the primary portions of the test system in order to provide a more stable and robust platform for building future features and enhancements.

Overhauling the testing lifecycle

The biggest blind spot for Intern’s self-tests in Intern 2 was the code in client.js and runner.js that actually set up the environment and kicked off testing. Because this code was fully procedural, we were not able to run unit tests to verify that it worked correctly without side-effects. The inability to easily extend from a common base type also lead to some code duplication across the client & runner, and made it more difficult than it should have been to enable new execution mechanisms that users have requested (like a continuous reload mode).

As a result, one of the biggest changes in Intern 3 has been to move all of this code into properly designed, reusable object types called executors. Making this change enables the core lifecycle mechanisms of Intern to be fully tested, which should over time reduce problems in the test system itself and enable more rapid release cycles. It also lays the foundation for some exciting new execution modes in future minor releases, and improves early error detection and reporting. For most users, the most immediate improvements from these changes will be increased test reliability and the ability to specify any configuration option override from the command-line.

Improving test reporting

One of our other goals for Intern for a while has been to add configurability to Intern’s test reporters. Luckily, overhauling the testing lifecycle gave us an excellent opportunity to also introduce a new reporter API and event hub that enables fully configurable reporters, plus adds support for safe asynchronous reporter operations. (For example, if you want to have a reporter take a screenshot of the browser before and after tests, this is now possible!)

To configure a reporter, provide an object instead of a string in the reporters array. For instance, to use the JUnit reporter and redirect its output to a different target file, configure your reporters configuration in this way:

{
	reporters: [
		{ id: 'JUnit', filename: 'report.xml' }
	]
}

High/low watermarks for the code coverage reporters can be configured using the watermarks property for a reporter:

{
	reporters: [
		{
			id: 'LcovHtml',
			watermarks: {
				statements: [ 80, 90 ],
				lines: [ 80, 90 ],
				functions: [ 80, 90 ],
				branches: [ 80, 90 ]				
			}
		}
	]
}

All built-in reporters that support code coverage also support the watermarks property; reporters that output to files accept the filename property, and reporters that output multiple files to a directory accept the directory property. You can find a full list of the reporters and their supported configuration values in the reporters documentation in the user guide.

QUnit-compatible interface

As part of our work to help support several jQuery project teams that are transitioning their projects from TestSwarm & QUnit to Intern, we’ve added a new QUnit test interface that is a drop-in compatible replacement for QUnit 1 test cases.

The QUnit interface doesn’t use QUnit, but rather provides the same API, so your existing tests written in QUnit can be quickly and easily ported to Intern. If you’re an existing QUnit user, this let you gain all the extra benefits of Intern (code coverage analysis, custom reporters, functional testing, etc.) without rewriting all of your tests!

Converting an existing test suite is simple. After creating an Intern configuration file, wrap the existing test files to convert them to modules that expose the Intern QUnit API:

define(function (require) {
	var QUnit = require('intern!qunit');

	// … existing test code here …
});

Then, just load each of the test suites using the suites configuration option instead of using script tags, and you’re using Intern!

TypeScript definitions

Intern 3 includes new TypeScript definitions for users that author tests in TypeScript. Due to limitations in TypeScript, we’re not able to offer fully inferred typing information to test and suite functions, but you can add the extra type information yourself where necessary. For example, to get a typed version of the remote Command:

import Command = require('leadfoot/Command');
import tdd = require('intern!tdd');

tdd.suite('suite', function () {
  tdd.test('test', function () {
    var remote: Command = this.remote;
    return remote.get('http://example.com') // …
  });
});

Adios Geezer

As our tooling continues to improve and upstream libraries are modernised, supporting pre-ES5 environments becomes a greater drag on development and takes time away that we could be spending adding amazing new features to Intern. According to npm analytics, only about 7% of Intern downloaders use the Geezer edition, but it would take about 40% of our development time for this release cycle to continue to support this separate branch. The primary reason for the increase in development time is primarily due to the replacement of the obsolete dojo2-core dependency with the official Dojo 2 library, which includes some significant API changes to harmonise with the upcoming EcmaScript 6 specification. These changes are not backwards-compatible with the Dojo 1 library used by Geezer.

As a result, unit testing is no longer supported in non-ES5 environments (IE8 and earlier). If you still need to support IE8 and earlier, Intern 2 will continue to be available, but with no new planned enhancements. Given the current browser landscape and feedback from some of our corporate users about their browser upgrade plans this year, we think that now is the right time to end support for these very outdated browsers.

However, if you anticipate still needing legacy browser support for unit testing in Intern 3 and might be interested in sponsoring development of a Geezer edition of Intern 3, please get in touch with us so we can coordinate this work.

More new stuff

In addition to the major features above, Intern 3 also includes over 30 other enhancements and bug fixes designed to make testing easier and faster. Some of the most requested new enhancements include:

  • beforeEach and afterEach functions are now given a reference to the test that is being executed
  • beforeEach and afterEach no longer run at all when a test is skipped with grep
  • All configuration options can now be specified from the command-line, and all formerly command-line-only options can now be specified from a configuration file
  • A default timeout for all tests can be specified using the defaultTimeout configuration property
  • The base path used by the test system can now be configured independently from the baseUrl of the loader

Additionally, these commonly reported problems have been fixed:

  • Early test failures in the unit test client are now reported more visibly
  • Sauce Labs and TestingBot tunnels now start properly in Node 0.12

A complete list of bug fixes and enhancements are available in the release notes.

Get involved

We’ve recently added easy, medium, and hard difficulty labels to all Intern tickets where we’re looking for community contributions (Leadfoot tickets too!), so take a look and get involved if you use Intern and want to help make it better!

Comments