From 052cf5cad815300f86afa896c9b4295d7adc1541 Mon Sep 17 00:00:00 2001 From: sylvain-hamel Date: Thu, 13 Mar 2014 10:54:30 -0400 Subject: [PATCH] feat: allow multiple IE versions in emulation modes Closes https://github.com/karma-runner/karma/issues/936, https://github.com/karma-runner/karma/issues/631 --- README.md | 18 +++++++++++++++++- index.js | 38 ++++++++++++++++++++++++++++++++++---- 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 56036c3..420f037 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ The easiest way is to keep `karma-ie-launcher` as a devDependency in your `packa } ``` -You can simple do it by: +You can simply do it by: ```bash npm install karma-ie-launcher --save-dev ``` @@ -34,9 +34,25 @@ You can pass list of browsers as a CLI argument too: karma start --browsers IE ``` +You can run IE in emulation mode by setting the 'x-ua-compatible' option: +```js +customLaunchers: { + IE9: { + base: 'IE', + 'x-ua-compatible': 'IE=EmulateIE9' + }, + IE8: { + base: 'IE', + 'x-ua-compatible': 'IE=EmulateIE8' + } +} +``` +See [Specifying legacy document modes] on MSDN. + ---- For more information on Karma see the [homepage]. [homepage]: http://karma-runner.github.com +[Specifying legacy document modes]: http://msdn.microsoft.com/en-us/library/ie/jj676915(v=vs.85).aspx \ No newline at end of file diff --git a/index.js b/index.js index 86f07c6..8e2f6eb 100644 --- a/index.js +++ b/index.js @@ -1,18 +1,48 @@ var fs = require('fs'); +var util = require('util'); +var urlparse = require('url').parse; +var urlformat = require('url').format; var IEBrowser = function(baseBrowserDecorator, args) { baseBrowserDecorator(this); - args = args || {}; var flags = args.flags || []; - this._getOptions = function(url) { + this._getOptions = function (url) { + var urlObj = urlparse(url, true); + + handleXUaCompatible(args, urlObj); + + delete urlObj.search; //url.format does not want search attribute + url = urlformat(urlObj); + return [ '-extoff' ].concat(flags, [url]); - } + }; }; +/** + * Handle x-ua-compatible option: + * + * Usage : + * customLaunchers: { + * IE9: { + * base: 'IE', + * 'x-ua-compatible': 'IE=EmulateIE9' + * } + * } + * + * This is done by passing the option on the url, in response the Karma server will + * set the following meta in the page. + * + */ +function handleXUaCompatible(args, urlObj) { + if (args['x-ua-compatible']) { + urlObj.query['x-ua-compatible'] = args['x-ua-compatible']; + } +} + function getInternetExplorerExe() { var suffix = '\\Internet Explorer\\iexplore.exe', prefixes = [process.env['PROGRAMW6432'], process.env['PROGRAMFILES(X86)'], process.env['PROGRAMFILES']], @@ -36,7 +66,7 @@ IEBrowser.prototype = { ENV_CMD: 'IE_BIN' }; -IEBrowser.$inject = ['baseBrowserDecorator']; +IEBrowser.$inject = ['baseBrowserDecorator', 'args']; // PUBLISH DI MODULE