Commit 6656a63f authored by Robert Knight's avatar Robert Knight Committed by Nick Stenning

Remove PhantomJS-specific polyfills (#45)

PhantomJS supports ES5 fully and does not require specific polyfills for
it. This means that we can use exactly the same polyfill script in both
our unit tests and the actual app, which reduces the chances of breakage
due to mismatches.

Additionally, the broken URL constructor could potentially affect other
browsers, so it makes sense to include it in the main polyfill script.
parent 514f211c
'use strict';
// Minimal set of polyfills for PhantomJS 1.x under Karma.
// this Polyfills:
//
// - ES5
// - ES6 Promises
// - the DOM URL API
// Basic polyfills for APIs which are supported natively
// by all browsers we support (IE >= 10)
require('core-js/es5');
// PhantomJS 1.x does not support rAF.
require('raf').polyfill();
// Additional polyfills for newer features.
// Be careful that any polyfills used here match what is used in the
// app itself.
require('./polyfills');
// PhantomJS 2.x includes a `URL` constructor so `new URL` works
// but it appears to be broken.
require('js-polyfills/url');
......@@ -18,7 +18,7 @@ module.exports = function(config) {
// list of files / patterns to load in the browser
files: [
// Polyfills for PhantomJS
'./karma-phantomjs-polyfill.js',
'./polyfills.js',
// Test setup
'./test/bootstrap.js',
......@@ -45,7 +45,7 @@ module.exports = function(config) {
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'./karma-phantomjs-polyfill.js': ['browserify'],
'./polyfills.js': ['browserify'],
'./test/bootstrap.js': ['browserify'],
'**/*-test.js': ['browserify'],
'**/*-test.coffee': ['browserify'],
......
......@@ -10,7 +10,13 @@ require('core-js/fn/object/assign');
// URL constructor, required by IE 10/11,
// early versions of Microsoft Edge.
try {
new window.URL('https://hypothes.is');
var url = new window.URL('https://hypothes.is');
// Some browsers (eg. PhantomJS 2.x) include a `URL` constructor which works
// but is broken.
if (url.hostname !== 'hypothes.is') {
throw new Error('Broken URL constructor');
}
} catch (err) {
require('js-polyfills/url');
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment