118 |
which is used to execute the instrumented code. |
which is used to execute the instrumented code. |
119 |
</p> |
</p> |
120 |
|
|
121 |
<h3>2. Executing instrumented code</h3> |
<h3>2. Running instrumented code in the web application</h3> |
122 |
|
|
123 |
<p> |
<p> |
124 |
Open <code>jscoverage.html</code> in your web browser. |
Open <code>jscoverage.html</code> in your web browser. |
215 |
<h3>3. Generating the coverage report</h3> |
<h3>3. Generating the coverage report</h3> |
216 |
|
|
217 |
<p> |
<p> |
218 |
Once you have executed the JavaScript code, you will be instructed to click on the |
Once you have executed the JavaScript code, you are instructed to click on the |
219 |
"Summary" tab. |
"Summary" tab. |
220 |
</p> |
</p> |
221 |
|
|
227 |
|
|
228 |
<img src="screenshot5.png" alt="Screenshot"> |
<img src="screenshot5.png" alt="Screenshot"> |
229 |
|
|
230 |
|
<h2>Inverted mode</h2> |
231 |
|
|
232 |
|
<p> |
233 |
|
In some circumstances it may be difficult to execute your code within the |
234 |
|
JSCoverage "Browser" tab. For example, the code may assume that it is running in |
235 |
|
the top-level browser window, generating errors if it is executed from within a |
236 |
|
frame. JSCoverage has an alternative mode of operation, called <dfn>inverted |
237 |
|
mode</dfn>, which may be useful in this situation. |
238 |
|
</p> |
239 |
|
|
240 |
|
<p> |
241 |
|
Normally you load <code>jscoverage.html</code> in your web browser, and in its |
242 |
|
"Browser" tab you launch your test code. In inverted mode, you do the |
243 |
|
opposite: you load your test page directly in your web browser, and from there |
244 |
|
you launch JSCoverage. To do this you need to add some code to your test page: |
245 |
|
</p> |
246 |
|
|
247 |
|
<pre> |
248 |
|
window.open("path/to/jscoverage.html"); |
249 |
|
</pre> |
250 |
|
|
251 |
|
<p> |
252 |
|
The <code>"path/to/jscoverage.html"</code> should be a URL pointing to the |
253 |
|
location of the <code>jscoverage.html</code> file (remember, this will be in the |
254 |
|
top level of the <var>DESTINATION-DIRECTORY</var> you specified when running |
255 |
|
the <code>jscoverage</code> executable). |
256 |
|
</p> |
257 |
|
|
258 |
|
<p> |
259 |
|
You can place this code wherever you like in your page: for example, you could |
260 |
|
attach it to a button: |
261 |
|
</p> |
262 |
|
|
263 |
|
<pre> |
264 |
|
<button onclick='window.open("path/to/jscoverage.html");'>Coverage report</button> |
265 |
|
</pre> |
266 |
|
|
267 |
|
<p> |
268 |
|
An example is located in the <code>doc/example-inverted</code> directory. |
269 |
|
You can instrument the code and launch the <code>index.html</code> page: |
270 |
|
</p> |
271 |
|
|
272 |
|
<pre> |
273 |
|
jscoverage doc/example-inverted doc/instrumented-inverted |
274 |
|
firefox "doc/instrumented-inverted/index.html" |
275 |
|
</pre> |
276 |
|
|
277 |
|
<p> |
278 |
|
From this page, you select one of the radio buttons and then click the "Coverage |
279 |
|
report" button to launch the JSCoverage report. |
280 |
|
</p> |
281 |
|
|
282 |
<h2>Caveats</h2> |
<h2>Caveats</h2> |
283 |
|
|
284 |
<ul> |
<ul> |