Check the npm scripts on package.json
for what gets actually called behind each command.
- Folder. All tests are in the
/__tests__/
folder. - Entrypoints.
npm run test
ornpm test
. The main one. Will runnpm run lint
and then the actual test suite usingjest
.npm run test:watch
. Will watch your files for changes and auto runnpm run test
when a file is changed.
npm run lint
. Will lint your javascript files.npm run lint:fix
. Will lint your javascript files and auto-fix whatever it can. Automatically called before any commit. Details below.
Here's an example of how an execution looks like (as of v1.6.0
):
By running npm run develop
, behind the scenes it will:
- Call
web-ext
which in its turn will open a browser for you with our latest extension code preloaded in it. - Will open out sample test file which has two
iframes
: one loading an allowed URL, one loading a denied URL (simulating a tracker request!). - Watch for file changes and regenerate the extension and reload it on the browser.
Go nuts and click around to test the extension.
As documented in #38 and INTERVIEW.md, it's unfortunately not possible to run automated (headless or not) ent-to-end tests.
In summary:
-
Since a recent change from Mozilla, we can't sideload extensions anymore (putting them in a specific folder and Firefox would load it up).
-
So we need
web-ext
to auto-load our last extension code in a browser for us. -
So far so good. The problem is integrating other test tools with that browser in order to run automated tests in it:
jest
usesjsdom
by default, which merely reimplements some browser APIs in Javascript. It doesn't support extensions.puppeteer
orplaywright
can't connect toweb-ext
's browser instance properly and test would always disconnect and throw errors.- For more details check the links above.
-
A possible path forward that I didn't have time to explore (see my odyssey in the links above) would be using in-browser tests (like
karma
). It's not ideal and would still require some manual checking (karma
is not designed for end-to-end tests and wouldn't be able to report back to the command line the execution results). So we developers would still need to baby-sit the test run and it would not be possible to run such tests in a CI environment. Still not ideal but better than not having those tests at all.