Skip to content

Instantly share code, notes, and snippets.

Last active April 17, 2017 15:36
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Code Coverage in Mozilla Code

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!
Copy link

This is deprecated, and will not work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment