diff --git a/bin/mink-zombie-server.js b/bin/mink-zombie-server.js index 2a60bad..6eecdeb 100755 --- a/bin/mink-zombie-server.js +++ b/bin/mink-zombie-server.js @@ -6,6 +6,7 @@ var pointers = []; var buffer = ''; var host = process.env.HOST || '127.0.0.1'; var port = process.env.PORT || 8124; +var options = process.env.OPTIONS ? JSON.parse(process.env.OPTIONS) : {}; var zombieVersionCompare = function (v2, op) { var version_compare = function (v1, v2, operator) { @@ -108,7 +109,7 @@ net.createServer(function (stream) { stream.on('end', function () { if (browser == null) { - browser = new zombie(); + browser = new zombie(options); // Clean up old pointers pointers = []; diff --git a/src/NodeJS/Server.php b/src/NodeJS/Server.php index 8bd1881..5085710 100644 --- a/src/NodeJS/Server.php +++ b/src/NodeJS/Server.php @@ -45,6 +45,11 @@ abstract class Server */ protected $threshold; + /** + * @var array + */ + private $options; + /** * @var string The full path to the NodeJS modules directory. */ @@ -69,6 +74,7 @@ abstract class Server * @param string $serverPath Path to server script * @param int $threshold Threshold value in micro seconds * @param string $nodeModulesPath Path to node_modules directory + * @param array $options Options array for zombiejs */ public function __construct( $host = '127.0.0.1', @@ -76,7 +82,8 @@ public function __construct( $nodeBin = null, $serverPath = null, $threshold = 2000000, - $nodeModulesPath = '' + $nodeModulesPath = '', + $options = array() ) { if (null === $nodeBin) { $nodeBin = 'node'; @@ -97,6 +104,7 @@ public function __construct( $this->setServerPath($serverPath); $this->setThreshold($threshold); + $this->setOptions($options); } /** @@ -273,6 +281,32 @@ public function getThreshold() return $this->threshold; } + /** + * Setter options value + * + * @param array $options Options array + * + * @throws \LogicException When server is already running. + */ + public function setOptions(array $options) + { + if ($this->isRunning()) { + throw new \LogicException('Unable to change options of a running server.'); + } + + $this->options = $options; + } + + /** + * Getter options value + * + * @return array Options array + */ + public function getOptions() + { + return $this->options; + } + /** * Getter process object * @@ -323,6 +357,10 @@ public function start(Process $process = null) $processBuilder->setEnv('NODE_PATH', $this->nodeModulesPath); } + if (!empty($this->options)) { + $processBuilder->setEnv('OPTIONS', json_encode($this->options)); + } + $process = $processBuilder->getProcess(); } $this->process = $process; diff --git a/tests/Custom/NodeJS/ServerTest.php b/tests/Custom/NodeJS/ServerTest.php index 07c63ab..e4d112b 100644 --- a/tests/Custom/NodeJS/ServerTest.php +++ b/tests/Custom/NodeJS/ServerTest.php @@ -17,9 +17,10 @@ protected function doEvalJS(Connection $conn, $str, $returnType = 'js') protected function getServerScript() { return <<assertEquals('/path/to/server', $server->getServerPath()); $this->assertEquals(2000000, $server->getThreshold()); $this->assertEquals('', $server->getNodeModulesPath()); + $this->assertEquals(array(), $server->getOptions()); $expected = <<assertEquals($expected, $server->serverScript); } @@ -90,7 +93,8 @@ public function testCreateCustomServer() null, null, 5000000, - '../../' + '../../', + array('waitDuration' => '15s') ); $this->assertEquals('123.123.123.123', $server->getHost()); @@ -99,11 +103,13 @@ public function testCreateCustomServer() $this->assertEquals('/path/to/server', $server->getServerPath()); $this->assertEquals(5000000, $server->getThreshold()); $this->assertEquals('../../', $server->getNodeModulesPath()); + $this->assertEquals(array('waitDuration' => '15s'), $server->getOptions()); $expected = <<assertEquals($expected, $server->serverScript); } @@ -158,6 +164,16 @@ public function testSetThresholdOnRunningServer() $server->setThreshold('test'); } + /** + * @expectedException \LogicException + * @expectedExceptionMessage Unable to change options of a running server. + */ + public function testSetOptionsOnRunningServer() + { + $server = $this->getRunningServer(); + $server->setOptions(array('waitDuration' => '15s')); + } + /** * @group legacy */