Using JSCoverage with the YUI test suite

This is the fifth in a series of articles about using the JSCoverage tool with various JavaScript testing frameworks:

  1. Using JSCoverage with the test suite
  2. Using JSCoverage with the MochiKit test suite
  3. Using JSCoverage with the jQuery test suite
  4. Using JSCoverage with the MooTools test suite
  5. Using JSCoverage with the YUI test suite (this article)

First, we need to download YUI. We will use the latest release in the YUI 2 series, version 2.8.0r4. The YUI test suite requires a web server to run in some browsers, so we will install it in the document root of a local Apache server, running on port 8080. Also, the file yui/tests/common/tests/YUI.html has a typo that needs to be corrected; we need to change this:


to this:


Once that is done, we just open the URL in a web browser to run the tests:

The YUI test suite

To obtain code coverage data, we will have to make one more modification to the file yui/tests/common/tests/YUI.html. The YUI test framework does not work inside a frame, so we will use JSCoverage “inverted mode” to run the tests. This entails adding a button to the page to launch the jscoverage.html file:

<div id="out"></div>
<button onclick="'../../../jscoverage.html');">Coverage report</button>

Once that addition is made, we can instrument the code:

jscoverage --no-instrument=tests yui instrumented-yui

Note that the YUI distribution is fairly large, so this command may take a while to run. We can speed things up a bit by using the --exclude option to skip some directories that are not needed:

jscoverage --no-instrument=tests --exclude=as-docs --exclude=docs --exclude=examples yui instrumented-yui

Then we open up the URL in our web browser:

The instrumented YUI test suite, with "Coverage report" button

We can then click the “Coverage report” button to launch the jscoverage.html file:

The JSCoverage "Summary" tab

Tomorrow we will look at using JSCoverage with the Dojo test suite.