webextensions-api-fake icon indicating copy to clipboard operation
webextensions-api-fake copied to clipboard

Provide script than can be used in a browser

Open lieser opened this issue 4 years ago • 2 comments

I run my tests not just in node, but also in the browser. So it would be nice if the build could generate a script that can be directly included in a browser.

lieser avatar May 21 '20 18:05 lieser

Are you hitting this problem: https://github.com/stoically/webextensions-api-mock/issues/7?

stoically avatar Jun 08 '20 11:06 stoically

No, for me it fails earlier. Could be that Karma runner already did run browserify or something similar.

What I'm trying to do, is directly include what is packed inside the node package in an html page, that I open in a Browser (Firefox). For chai/mocha/sinon, this works:

<script src="https://unpkg.com/chai/chai.js"></script>
<script src="https://unpkg.com/mocha/mocha.js"></script>
<script src="https://unpkg.com/sinon/pkg/sinon.js"></script>

For webextensions-api-fake, with

<script src="https://unpkg.com/webextensions-api-fake/dist/index.js"></script>

I get the following error :

ReferenceError: exports is not defined - index.js:15:1
    <anonym> https://unpkg.com/webextensions-api-fake/dist/index.js:15

An then I try to load it as a module with

<script type="module" src="https://unpkg.com/webextensions-api-fake/dist/index.js"></script>

I get:

ReferenceError: exports is not defined - index.js:15:1
    <anonym> https://unpkg.com/webextensions-api-fake/dist/index.js:15
    InnerModuleEvaluation self-hosted:1572
    evaluation self-hosted:1543

Similar results with webextensions-api-mock.

For my use case to work, the build process would probably needed to be updated to include browserify or some different bundler.

lieser avatar Jun 08 '20 19:06 lieser