Skip to content
This repository has been archived by the owner on Sep 7, 2022. It is now read-only.

Commit

Permalink
Merge pull request #29 from sylvain-hamel/fix-27
Browse files Browse the repository at this point in the history
fix: karma doesn't kill PhantomJS on windows when using singleRun:true
  • Loading branch information
sylvain-hamel committed Apr 1, 2014
2 parents 4b75b78 + 0b8efdf commit 5670fc5
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var fs = require('fs');
var path = require('path');


function serializeOption(value) {
Expand All @@ -8,6 +9,19 @@ function serializeOption(value) {
return JSON.stringify(value);
}

var win32PhantomJSPath = function () {
// get the path stored in phantomjs\lib\location.js, someting like
// "C:\\Users\\user-name\\AppData\\Roaming\\npm\\phantomjs.CMD"
var cmd = require('phantomjs').path;

// get the global npm install directory by removing the filename from cmd variable
var npmGlobalRoot = path.dirname(cmd);

// add known path
var phantom = npmGlobalRoot + '\\node_modules\\phantomjs\\bin\\phantomjs';

return phantom;
};

var PhantomJSBrowser = function(baseBrowserDecorator, config, args) {
baseBrowserDecorator(this);
Expand All @@ -34,8 +48,15 @@ var PhantomJSBrowser = function(baseBrowserDecorator, config, args) {
optionsCode.join('\n') + '\npage.open("' + url + '");\n';
fs.writeFileSync(captureFile, captureCode);

var isWin = /^win/.test(process.platform);
if (isWin) {
flags = flags.concat(win32PhantomJSPath(), captureFile);
} else {
flags = flags.concat(captureFile);
}

// and start phantomjs
this._execCommand(this._getCommand(), flags.concat(captureFile));
this._execCommand(this._getCommand(), flags);
};
};

Expand All @@ -45,7 +66,7 @@ PhantomJSBrowser.prototype = {
DEFAULT_CMD: {
linux: require('phantomjs').path,
darwin: require('phantomjs').path,
win32: require('phantomjs').path
win32: process.execPath //path to node.exe, see flags in _start()
},
ENV_CMD: 'PHANTOMJS_BIN'
};
Expand Down

0 comments on commit 5670fc5

Please sign in to comment.