From 4d2f9c21d48f8370a16af9e0b890cd0ce137b158 Mon Sep 17 00:00:00 2001 From: Matt Zabriskie Date: Wed, 9 Mar 2016 16:17:10 -0700 Subject: [PATCH] Gettings tests passing for IE9 --- karma.conf.js | 9 ++++++++- lib/adapters/xhr.js | 3 ++- package.json | 2 +- webpack.config.js | 10 ++++++++-- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/karma.conf.js b/karma.conf.js index 98f7485..ac0286f 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -1,6 +1,8 @@ // Karma configuration // Generated on Fri Aug 15 2014 23:11:13 GMT-0500 (CDT) +var webpack = require('webpack'); + function createCustomLauncher(browser, version, platform) { return { base: 'SauceLabs', @@ -70,7 +72,7 @@ module.exports = function(config) { if (runAll || process.env.SAUCE_IE) { // TODO These need to be fixed // customLaunchers.SL_IE8 = createCustomLauncher('internet explorer', 8, 'Windows 7'); - // customLaunchers.SL_IE9 = createCustomLauncher('internet explorer', 9, 'Windows 2008'); + customLaunchers.SL_IE9 = createCustomLauncher('internet explorer', 9, 'Windows 2008'); customLaunchers.SL_IE10 = createCustomLauncher('internet explorer', 10, 'Windows 2012'); customLaunchers.SL_IE11 = createCustomLauncher('internet explorer', 11, 'Windows 8.1'); } @@ -183,6 +185,11 @@ module.exports = function(config) { { './adapters/http': 'var undefined' } + ], + plugins: [ + new webpack.DefinePlugin({ + 'process.env.NODE_ENV': JSON.stringify('test') + }) ] }, diff --git a/lib/adapters/xhr.js b/lib/adapters/xhr.js index 6721d62..0105f52 100644 --- a/lib/adapters/xhr.js +++ b/lib/adapters/xhr.js @@ -21,7 +21,8 @@ module.exports = function xhrAdapter(resolve, reject, config) { // For IE 8/9 CORS support // Only supports POST and GET calls and doesn't returns the response headers. - if (window.XDomainRequest && !('withCredentials' in request) && !isURLSameOrigin(config.url)) { + // DON'T do this for testing b/c XMLHttpRequest is mocked, not XDomainRequest. + if (process.env.NODE_ENV !== 'test' && window.XDomainRequest && !('withCredentials' in request) && !isURLSameOrigin(config.url)) { request = new window.XDomainRequest(); loadEvent = 'onload'; xDomain = true; diff --git a/package.json b/package.json index 829af8e..f62babf 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "Promise based HTTP client for the browser and node.js", "main": "index.js", "scripts": { - "build": "./node_modules/.bin/grunt build", + "build": "NODE_ENV=production ./node_modules/.bin/grunt build", "test": "./node_modules/.bin/grunt test", "start": "node ./sandbox/server.js", "examples": "node ./examples/server.js", diff --git a/webpack.config.js b/webpack.config.js index 2afd0f5..c8a2741 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -22,15 +22,21 @@ function generateConfig(name) { ], devtool: 'source-map' }; + + config.plugins = [ + new webpack.DefinePlugin({ + 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV) + }) + ]; if (uglify) { - config.plugins = [ + config.plugins.push( new webpack.optimize.UglifyJsPlugin({ compressor: { warnings: false } }) - ]; + ); } return config;