acvetkov / sinon-chrome

Testing chrome extensions with Node.js
ISC License
439 stars 48 forks source link

How to use with mozilla/webextension-polyfill ? #103

Open davestewart opened 4 years ago

davestewart commented 4 years ago

Hi,

Background: I'm a "fair weather" tester, but looks like I am going to have to up my game to start testing browser extensions.

Question: is it possible to use mozilla/webextension-polyfill with this library?

My extension is completely written with it, and I thought I would just be able to import the lib before importing my code, but this is not working.

When I attempt to use the polyfill in Jest, it fails with “This script should only be loaded in a browser extension.” because it can’t find chrome in the current context.

I’ve tried various ways to fix this (Jest globals, Jest setupFiles), but no luck so far.

My apologies that my testing skills are poor and this may even be off-topic!

I think Sinon Chrome is what I need, I just need a little help getting out of the starting blocks.

Thank you :)

nickserv commented 4 years ago

This fixed it for me https://github.com/mozilla/webextension-polyfill/issues/218#issuecomment-584936358