Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to unittest Firefox 57 WebExtensions?

The older Firefox "Add-ons" API had a built-in unittest layer sdk/test that allowed testing. This doesn't seem to be available any more.

Additionally the use of "package/require" allowed code to be separated into "js code-only" packages that were testable using node.js. The new, highly structured javascript doesn't share this.

My priorities are (highest to lowest):

  1. Algorithms, "business logic", e.g. parsing input data - no APIs needed - just JavaScript
  2. Internal logic - e.g. background scripts interacting with settings, etc.
  3. UI interactions - I can live without this, but would be nice to test

So how do people test their WebExtensions?

like image 577
Greg Avatar asked Nov 08 '22 14:11

Greg


1 Answers

Check out webextension-geckodriver for a worked example of functional testing.

If you want to test interaction with the webextension API you can either do it live (have a test page for your extension and get geckodriver to visit it, for example) or use a fake like sinon-webextension through webextension-jsdom.

To unit test algorithms, just import the functions using jest, mocha, or whatever node unit testing framework you prefer or add them to a test page that you can visit in the browser.

A complete, but old, worked example of webext testing is here: example-webextension.

An example of tests in a real webextension using another fake: vim-vixen

like image 89
cmc Avatar answered Nov 15 '22 12:11

cmc