Code coverage and chrome extensions
I'm particularly interested in code coverage assessment in two situations:
- who has never refactored a functional extension to cope for growth and new features ? When I refactor, I do variable renaming, object restructuring, code cleaning etc .., and I become very concerned about regression issues. Changes can be spread,major and devastating. So, I need to validate 100% of them.
- having deployed tens of extensions, I very often start new projects from existing ones and carry over code I may not need at the end. Code coverage highlights very quickly candidate files and lines to prune off.
Since 59, chrome offers a very interesting code coverage feature available thru the devtools - of course -. Content script and background scripts (in fact all scripts!) can be studied for coverage.
So open the devtools, open the console and click the "coverage" tab:
- a "content scripts" checkbox next to the URL filter allows to include content scripts in the coverage assessment.
- the URL filter allows to select only content scripts of interest
- in 73 canary, an export button allows to export coverage data into a JSON file.
- if you open the source panel and select your content script, you'll have access to a very convenient graphic representation of the coverage.
Now, there are a few things to do:
- design tests to stimulate traversal of your code.
- make sure your build process has the ability to NOT package content scripts with third party libraries (use manifest file to include a list of files rather than a global content script). This way, you will be able to concentrate on "covering" what you have really written yourself.
- who has never refactored a functional extension to cope for growth and new features ? When I refactor, I do variable renaming, object restructuring, code cleaning etc .., and I become very concerned about regression issues. Changes can be spread,major and devastating. So, I need to validate 100% of them.
- having deployed tens of extensions, I very often start new projects from existing ones and carry over code I may not need at the end. Code coverage highlights very quickly candidate files and lines to prune off.
Since 59, chrome offers a very interesting code coverage feature available thru the devtools - of course -. Content script and background scripts (in fact all scripts!) can be studied for coverage.
So open the devtools, open the console and click the "coverage" tab:
- a "content scripts" checkbox next to the URL filter allows to include content scripts in the coverage assessment.
- the URL filter allows to select only content scripts of interest
- in 73 canary, an export button allows to export coverage data into a JSON file.
- if you open the source panel and select your content script, you'll have access to a very convenient graphic representation of the coverage.
Now, there are a few things to do:
- design tests to stimulate traversal of your code.
- make sure your build process has the ability to NOT package content scripts with third party libraries (use manifest file to include a list of files rather than a global content script). This way, you will be able to concentrate on "covering" what you have really written yourself.
Comments
Post a Comment