Last active

Code Coverage in Mozilla Code

  • Download Gist

Code Coverage in Mozilla Addon-SDK Code

Author: Gregg Lind

example coverage report:

Quick Recipe:

# install node
# patch your addon-sdk to have coverObject in the globals.
curl | git am --reject

cd youraddondir
npm install git://
curl -o coverreport.js
rm -rf fakey && mkdir -p fakey/lib && cp -r data doc test package.json fakey && \
    ./node_modules/coverjs-moz/bin/coverjs \
    -o fakey/lib \
    --escodegen-options '{"moz":{"starlessGenerator":true,"parenthesizedComprehensionBlock":true}}' \
    `find lib -name '*js'`
cfx test --pkgdir=fakey 
node coverreport.js  < coverstats-*.json  > coverreport.html
open coverreport.html


  1. parse moz js into AST
  2. add 'incrementor' nodes to a __$coverObject using CoverJS
  3. generate new code using escodegen
  4. run tests, which dumps the cover object:

    cfx test --pkgdir=fakey

  5. turn cover object into an html or other report, using CoverJS or other mechanism.


  1. esprima-moz (npm install esprima-moz)
  2. escodegen is slowly landing moz specific patches
  3. npm install CoverJS

Specific Requests / WIP:

  1. Where does the 'coverObject' live? Should loader during test have window or global?
  2. Should all of this be included in CFX as a --coverage option (see
  3. Please, someone from Moz should be maintaining our forks!

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.