forked from mozilla/webextension-polyfill
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: library wrapped as an UMD module
This addresses [issue 7] by making it possible for users to run: ```sh npm install webextension-polyfill ``` and download a module that they can use with a bundler as follows: ```js import browser from 'webextension-polyfill'; ``` Also, add a [prepublish script] so that users who clone the repo don't need to run `grunt` manually. In addition, specify [files] in package.json so that this module can be published to npm without including miscellanea. This can be verified by running: ```sh npm pack && tar -tvf webextension-polyfill-0.1.0.tgz ``` [issue 7]: mozilla#7 [files]: https://docs.npmjs.com/files/package.json#files [prepublish script]: https://docs.npmjs.com/misc/scripts
- Loading branch information
1 parent
52791c8
commit f9248e6
Showing
7 changed files
with
113 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
"use strict"; | ||
|
||
const {deepEqual, equal, ok} = require("chai").assert; | ||
|
||
module.exports.testCustomProperties = window => { | ||
Object.defineProperty(window.browser, "myns", { | ||
enumerable: true, | ||
configurable: true, | ||
value: {mykey: true}, | ||
}); | ||
|
||
ok("myns" in window.browser, "The custom property exists"); | ||
ok("mykey" in window.browser.myns, | ||
"The content of the custom property exists"); | ||
|
||
deepEqual(window.browser.myns, {mykey: true}, | ||
"The custom property has the expected content"); | ||
|
||
delete window.browser.myns; | ||
|
||
ok(!("myns" in window.browser), | ||
"The deleted custom defined property has been removed"); | ||
}; | ||
|
||
module.exports.testUndefinedProperties = window => { | ||
equal(window.browser.myns.mykey, true, | ||
"Got the expected result from a wrapped property"); | ||
equal(window.browser.myns.nonexistent, undefined, | ||
"Got undefined for non existent property"); | ||
equal(window.browser.nonexistent, undefined, | ||
"Got undefined for non existent namespaces"); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
"use strict"; | ||
|
||
const {deepEqual, strictEqual, notStrictEqual, throws} = require("chai").assert; | ||
const {testCustomProperties, testUndefinedProperties} = require("./helpers"); | ||
|
||
describe("node-export", () => { | ||
beforeEach(() => { | ||
delete global.browser; | ||
delete global.chrome; | ||
delete require.cache[require.resolve("../")]; | ||
}); | ||
|
||
it("exports the global browser namespace if it already exists", () => { | ||
global.browser = {key: "value"}; | ||
|
||
const exported = require("../"); | ||
|
||
strictEqual(exported, browser); | ||
}); | ||
|
||
it("exports a wrapper around the global chrome namespace", () => { | ||
global.chrome = {key: "value"}; | ||
|
||
const exported = require("../"); | ||
|
||
deepEqual(exported, chrome); | ||
notStrictEqual(exported, chrome); | ||
}); | ||
|
||
it("throws an error if the global chrome namespace is missing", () => { | ||
throws(() => require("../"), ReferenceError, /chrome is not defined/); | ||
}); | ||
|
||
describe("browser wrapper", () => { | ||
it("supports custom properties defined using Object.defineProperty", () => { | ||
global.chrome = {}; | ||
global.browser = require("../"); | ||
testCustomProperties(global); | ||
}); | ||
|
||
it("returns undefined for property undefined in the target", () => { | ||
global.chrome = {myns: {mykey: true}}; | ||
global.browser = require("../"); | ||
testUndefinedProperties(global); | ||
}); | ||
}); | ||
}); |