diff --git a/.eslintrc b/.eslintrc index 13ed046..c786328 100644 --- a/.eslintrc +++ b/.eslintrc @@ -10,6 +10,7 @@ "env": { "browser": true, "es6": true, + "node": true, "webextensions": true, }, diff --git a/.travis.yml b/.travis.yml index dd3550f..33e9ce5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,11 +10,11 @@ script: - 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 webpack-cli && - ./test/run-module-bundlers-smoketests.sh + node ./scripts/run-module-bundlers-smoketests.js - export DISPLAY=:99.0 - sh -e /etc/init.d/xvfb start - echo "RUN integration tests on real browsers" && - TRAVIS_CI=true ./test/run-browsers-smoketests.sh + TRAVIS_CI=true node ./scripts/run-browsers-smoketests.js ## See https://docs.travis-ci.com/user/chrome sudo: required diff --git a/Gruntfile.js b/Gruntfile.js index 7b8f808..c21e55d 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -2,13 +2,11 @@ /* vim: set sts=2 sw=2 et tw=80: */ "use strict"; -/* eslint-env commonjs */ - const LICENSE = `/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */`; -const MINIFIED_FILE_FOOTER = `\n\n// <%= pkg.name %> v.<%= pkg.version %> (<%= pkg.homepage %>)\n\n${LICENSE}`; +const MINIFIED_FILE_FOOTER = `\n// <%= pkg.name %> v.<%= pkg.version %> (<%= pkg.homepage %>)\n\n${LICENSE}\n`; module.exports = function(grunt) { grunt.initConfig({ @@ -22,7 +20,7 @@ module.exports = function(grunt) { eslint: { src: ["src/browser-polyfill.js", "Gruntfile.js"], - test: ["test/**/*.js"], + test: ["test/**/*.js", "scripts/**/*.js"], }, replace: { diff --git a/package.json b/package.json index 8eed18c..f436aa5 100644 --- a/package.json +++ b/package.json @@ -26,9 +26,10 @@ "browserify": "^16.2.2", "chai": "^3.5.0", "chromedriver": "^2.38.3", + "cross-env": "^5.2.0", "eslint": "^3.9.1", "finalhandler": "^1.1.0", - "geckodriver": "^1.11.0", + "geckodriver": "^1.11.2", "global-replaceify": "^1.0.0", "grunt": "^1.0.1", "grunt-babel": "^6.0.0", @@ -62,8 +63,10 @@ "prepublish": "npm run build && npm run test", "publish-coverage": "grunt coveralls", "test": "mocha", - "test-coverage": "COVERAGE=y nyc mocha", - "test-minified": "TEST_MINIFIED_POLYFILL=1 mocha", - "test-integration": "tape test/integration/test-*" + "test-coverage": "cross-env COVERAGE=y nyc mocha", + "test-minified": "cross-env TEST_MINIFIED_POLYFILL=1 mocha", + "test-integration": "tape test/integration/test-*", + "test-integration:chrome": "cross-env TEST_BROWSER_TYPE=chrome npm run test-integration | tap-nirvana", + "test-integration:firefox": "cross-env TEST_BROWSER_TYPE=firefox npm run test-integration | tap-nirvana" } } diff --git a/scripts/run-browsers-smoketests.js b/scripts/run-browsers-smoketests.js new file mode 100755 index 0000000..277cd7f --- /dev/null +++ b/scripts/run-browsers-smoketests.js @@ -0,0 +1,28 @@ +#!/usr/bin/env node +"use strict"; +const shell = require("shelljs"); + +/** + * This is to make sure that even if the tests fail on Chrome, + * the tests still run on Firefox, so that it can be seen whether + * Firefox broke too or is unaffected. + */ +let result = 0; + +console.log(` +Test webextension-polyfill on real browsers +===========================================`); + +// Enable headless mode (currently only used when running on Firefox +// because Chrome doesn't currently support the extensions in headless mode) +process.env.HEADLESS = 1; + +console.log("\nRunning smoketests on Chrome"); +process.env.TEST_BROWSER_TYPE = "chrome"; +result = shell.exec("npm run test-integration:chrome").code || result; + +console.log("\nRunning smoketests on Firefox"); +process.env.TEST_BROWSER_TYPE = "firefox"; +result = shell.exec("npm run test-integration:firefox").code || result; + +process.exit(result); diff --git a/scripts/run-module-bundlers-smoketests.js b/scripts/run-module-bundlers-smoketests.js new file mode 100755 index 0000000..9a68824 --- /dev/null +++ b/scripts/run-module-bundlers-smoketests.js @@ -0,0 +1,22 @@ +#!/usr/bin/env node +const shell = require("shelljs"); + +let result = 0; + +console.log(` +Test webextension-polyfill bundled with webpack +===============================================`); + +process.env.TEST_BUNDLED_POLYFILL = "/tmp/webpack-bundle.js"; +result = shell.exec(`webpack --mode production --entry ./test/fixtures/bundle-entrypoint.js --output ${process.env.TEST_BUNDLED_POLYFILL}`).code || + shell.exec("npm run test").code || result; + +console.log(` +Test webextension-polyfill bundled with browserify +==================================================`); + +process.env.TEST_BUNDLED_POLYFILL = "/tmp/browserify-bundle.js"; +result = shell.exec(`browserify test/fixtures/bundle-entrypoint.js > ${process.env.TEST_BUNDLED_POLYFILL}`).code || + shell.exec("npm run test").code || result; + +process.exit(result); diff --git a/src/.eslintrc b/src/.eslintrc new file mode 100644 index 0000000..e76e457 --- /dev/null +++ b/src/.eslintrc @@ -0,0 +1,9 @@ +{ + "env": { + "node": false, + }, + "globals": { + // Allow the `module` global, but not the `require(…)` function + "module": false, + }, +} \ No newline at end of file diff --git a/src/browser-polyfill.js b/src/browser-polyfill.js index f4b6dec..fbbcc49 100644 --- a/src/browser-polyfill.js +++ b/src/browser-polyfill.js @@ -509,7 +509,7 @@ if (typeof browser === "undefined" || Object.getPrototypeOf(browser) !== Object. // The build process adds a UMD wrapper around this file, which makes the // `module` variable available. - module.exports = wrapAPIs(chrome); // eslint-disable-line no-undef + module.exports = wrapAPIs(chrome); } else { - module.exports = browser; // eslint-disable-line no-undef + module.exports = browser; } diff --git a/test/.eslintrc b/test/.eslintrc index 70b013e..688def0 100644 --- a/test/.eslintrc +++ b/test/.eslintrc @@ -1,11 +1,7 @@ { "env": { "mocha": true, - "node": true, - "browser": true, - "webextensions": true }, - "globals": {}, "rules": { "max-nested-callbacks": ["warn", 6] } diff --git a/test/fixtures/index.html b/test/fixtures/index.html index 4066e38..896d985 100644 --- a/test/fixtures/index.html +++ b/test/fixtures/index.html @@ -1,4 +1,4 @@ - +