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

fix: karma doesn't kill PhantomJS on windows when using singleRun:true #29

Merged
merged 1 commit into from
Apr 1, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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