test: run tests for the webpack and browserify bundled files on travis
This commit is contained in:
parent
46b8f7e583
commit
a34f9c71f8
|
@ -7,7 +7,10 @@ node_js:
|
|||
script:
|
||||
- npm run build
|
||||
- npm run test-coverage
|
||||
- echo "RE-RUN all tests on the minified file" && npm run test-minified
|
||||
- echo "RE-RUN tests on the minified file" && npm run test-minified
|
||||
- echo "RE-RUN tests on the webpack and browserify bundled files" &&
|
||||
npm install -g browserify webpack &&
|
||||
./test/run-module-bundlers-smoketests.sh
|
||||
|
||||
after_script: npm run publish-coverage
|
||||
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
"use strict";
|
||||
|
||||
window.browser = require("../../");
|
|
@ -1,32 +0,0 @@
|
|||
"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");
|
||||
};
|
|
@ -0,0 +1,11 @@
|
|||
echo "\nTest webextension-polyfill bundled with webpack"
|
||||
echo "==============================================="
|
||||
|
||||
webpack test/fixtures/bundle-entrypoint.js /tmp/webpack-bundle.js
|
||||
TEST_BUNDLED_POLYFILL=/tmp/webpack-bundle.js npm run test
|
||||
|
||||
echo "\nTest webextension-polyfill bundled with browserify"
|
||||
echo "=================================================="
|
||||
|
||||
browserify test/fixtures/bundle-entrypoint.js > /tmp/browserify-bundle.js
|
||||
TEST_BUNDLED_POLYFILL=/tmp/browserify-bundle.js npm run test
|
|
@ -13,8 +13,13 @@ if (process.env.ENABLE_JSDOM_CONSOLE == "y") {
|
|||
|
||||
// Path to the browser-polyfill script, relative to the current work dir
|
||||
// where mocha is executed.
|
||||
const BROWSER_POLYFILL_PATH = process.env.TEST_MINIFIED_POLYFILL ?
|
||||
"./dist/browser-polyfill.min.js" : "./dist/browser-polyfill.js";
|
||||
let BROWSER_POLYFILL_PATH = "./dist/browser-polyfill.js";
|
||||
|
||||
if (process.env.TEST_MINIFIED_POLYFILL) {
|
||||
BROWSER_POLYFILL_PATH = "./dist/browser-polyfill.min.js";
|
||||
} else if (process.env.TEST_BUNDLED_POLYFILL) {
|
||||
BROWSER_POLYFILL_PATH = process.env.TEST_BUNDLED_POLYFILL;
|
||||
}
|
||||
|
||||
// Create the jsdom window used to run the tests
|
||||
const testDOMWindow = jsdom("", {virtualConsole}).defaultView;
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
"use strict";
|
||||
|
||||
const {deepEqual, equal} = require("chai").assert;
|
||||
const {deepEqual, equal, ok} = require("chai").assert;
|
||||
|
||||
const {setupTestDOMWindow} = require("./setup");
|
||||
|
||||
const {testCustomProperties, testUndefinedProperties} = require("./helpers");
|
||||
|
||||
describe("browser-polyfill", () => {
|
||||
it("wraps the global chrome namespace with a global browser namespace", () => {
|
||||
const fakeChrome = {};
|
||||
|
@ -19,7 +17,7 @@ describe("browser-polyfill", () => {
|
|||
runtime: {lastError: null},
|
||||
};
|
||||
const fakeBrowser = {
|
||||
mycustomns: {mykey: true},
|
||||
mycustomns: {mybrowserkey: true},
|
||||
};
|
||||
|
||||
return setupTestDOMWindow(fakeChrome, fakeBrowser).then(window => {
|
||||
|
@ -31,12 +29,37 @@ describe("browser-polyfill", () => {
|
|||
describe("browser wrapper", () => {
|
||||
it("supports custom properties defined using Object.defineProperty", () => {
|
||||
const fakeChrome = {};
|
||||
return setupTestDOMWindow(fakeChrome).then(testCustomProperties);
|
||||
return setupTestDOMWindow(fakeChrome).then(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");
|
||||
});
|
||||
});
|
||||
|
||||
it("returns undefined for property undefined in the target", () => {
|
||||
const fakeChrome = {myns: {mykey: true}};
|
||||
return setupTestDOMWindow(fakeChrome).then(testUndefinedProperties);
|
||||
const fakeChrome = {myns: {mychromekey: true}};
|
||||
return setupTestDOMWindow(fakeChrome).then(window => {
|
||||
equal(window.browser.myns.mychromekey, 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");
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,47 +0,0 @@
|
|||
"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);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue