Four years of Intern
When we first introduced Intern, our assessment of the testing landscape was “It’s a mess”.
- Support for modular AMD code in Node.js and web browsers
- Integrated code coverage analysis and reporting via Istanbul
- Ability to run both unit tests and functional (WebDriver) tests
- Rich assertions via the Chai library
The changing landscape
With these advances, particularly the increased use of transpires, source maps have become much more important. A few years ago source maps were mostly needed to map errors in minified code back to source, which often was not applicable in testing scenarios. However, with source code now often using ES6+ syntax that isn’t natively supported by all browsers, not to mention language extensions such as TypeScript, testing tools need to support source maps to be able to map assertion failures in running tests back to the source being tested, and to provide code coverage analysis against the original rather than transpiled source.
It is clear that several of these changes present new challenges in the present and near future.
In 2014 Jasmine gained Node.js support, and significantly improved its support for asynchronous code, and it remains one of the most commonly used unit testing frameworks. Mocha has become increasingly popular over the last few years as well, adding numerous features such as support for Promises. Newer frameworks have come along, too, like Jest and AVA. Jest is a unit testing framework developed and used by Facebook with a focus on easy setup and good support for React projects. Like Jasmine, Jest includes a number of support tools like mocking and assertions, and Jest also includes code coverage support. AVA is an opinionated, lightweight testing framework that focuses on speed. It concurrently runs test files, each in a separate process, improving both execution isolation and throughput.
Functional testing with WebDriver has improved significantly in the last few years. Version 3 of Selenium was released in 2016, and the WebDriver protocol reached W3C candidate recommendation status in 2017. Nightwatch and Webdriver.io are two newer frameworks that leverage WebDriver for functional testing. Both of these tools include their own testing interfaces and test runners, and both can also use the reporters and interfaces of some popular unit testing frameworks like Mocha. Intern’s Leadfoot also continues to be a viable option for functional testing, with its unique feature testing approach to help prevent WebDriver failures due to inconsistent implementations of WebDriver.
Tools that support the testing process have also continued to advance. Istanbul, the code coverage instrumentation and reporting library, has undergone a complete rewrite. It leverages the nyc command-line tool and also works with non-transpiled ES2015 code. Testing tools can once again generate stack traces for transpiled code that point back to the original sources, with the features of remap-istanbul built into the new version of Istanbul. Headless testing of browser APIs using either more recent versions of PhantomJS or jsdom have improved but still do not replace the efficacy of testing against the real browsers in which your applications will be run.
Intern has evolved significantly over the last several years, continually adding new features to make writing (and running) tests simpler, from small improvements like glob support for listing suites, to more significant features like the ability to efficiently manage a local Selenium server, as well as automated accessibility, performance, and visual regression testing. These improvements and the hundreds of others were very welcome for improving how we test our applications, but did not address some of the major changes in testing that are possible and needed with the introduction of ES2015+.
- Intern has been completely rewritten in TypeScript and provides a thoroughly typed public API. The typings also make contributing to Intern easier by helping to ensure that changes properly use internal APIs!
- Intern is now module loader agnostic, allowing tests, and application code, to use any module format (or no module format), including AMD and ESM.
- Source map support has been significantly improved, allowing Intern to track locations through instrumented and transpiled code.
- Code coverage support has likewise been upgraded to handle transpiled code.
- The configuration process is simpler and more consistent, and less configuration is required to get up and running.