Skip to content

Instantly share code, notes, and snippets.

@gregglind
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
Save gregglind/3900355 to your computer and use it in GitHub Desktop.
Code Coverage in Mozilla Code

Code Coverage in Mozilla Addon-SDK Code

Author: Gregg Lind glind@mozilla.com

example coverage report: http://gregglind.github.com/micropilot/coverreport.html

Quick Recipe:

# install node
# patch your addon-sdk to have coverObject in the globals.
curl https://github.com/gregglind/addon-sdk/commit/coverage.patch | git am --reject


cd youraddondir
npm install git://github.com/gregglind/CoverJS.git#moz
curl -o coverreport.js https://gist.github.com/raw/4455415/405fc842bdd813470b95611b2776bf2ab06695ed/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

Approach:

  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.

Needed:

  1. esprima-moz https://github.com/gregglind/esprima#moz (npm install esprima-moz)
  2. escodegen is slowly landing moz specific patches https://github.com/Constellation/escodegen/pulls
  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 https://bugzilla.mozilla.org/show_bug.cgi?id=789401)
  3. Please, someone from Moz should be maintaining our forks!
@gregglind
Copy link
Author

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