Skip to content

Commit

Permalink
feat: allow multiple IE versions in emulation modes
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvain-hamel committed Mar 31, 2014
1 parent c20733a commit 052cf5c
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 5 deletions.
18 changes: 17 additions & 1 deletion README.md
Expand Up @@ -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
```
Expand All @@ -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
38 changes: 34 additions & 4 deletions 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.
* <meta http-equiv="X-UA-Compatible" content="[VALUE]"/>
*/
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']],
Expand All @@ -36,7 +66,7 @@ IEBrowser.prototype = {
ENV_CMD: 'IE_BIN'
};

IEBrowser.$inject = ['baseBrowserDecorator'];
IEBrowser.$inject = ['baseBrowserDecorator', 'args'];


// PUBLISH DI MODULE
Expand Down

0 comments on commit 052cf5c

Please sign in to comment.