Permalink
Browse files

V0.1.1 - use node-child-killer if installed & add test

  • Loading branch information...
1 parent 3d9ba9b commit 39ebda21b7f8fa5ad95b0287380cf125930f59d0 @kesla committed Sep 26, 2012
Showing with 24 additions and 4 deletions.
  1. +3 −1 README.md
  2. +8 −2 index.js
  3. +4 −1 package.json
  4. +9 −0 test/test.js
View
@@ -36,4 +36,6 @@ install
With [npm](http://npmjs.org), do:
- npm install headless
+ npm install headless
+
+If you're having problems with Xvfb-instances not getting killed correctly, and is running on a platform that the posix-module supports, install [child-killer](https://npmjs.org/package/child-killer) (`npm install child-killer`) and headless will automatically use it.
View
@@ -1,5 +1,11 @@
var path = require('path');
-var spawn = require('child_process').spawn;
+var spawn;
+
+try {
+ spawn = require('child-killer').spawn;
+} catch(e) {
+ spawn = require('child_process').spawn;
+}
function findFreeServernum(servernum, callback) {
path.exists('/tmp/.X' + servernum + '-lock', function(exists) {
@@ -28,7 +34,7 @@ module.exports = function headless(startnum, callback) {
// if Xvfb exits prematurely the servernum wasn't valid.
// Happens if there's already an X-server running on @servernum but no file was created in /tmp
- childProcess.on('exit', function() {
+ childProcess.once('exit', function() {
clearTimeout(timeout);
servernum++;
headless(servernum, callback);
View
@@ -2,7 +2,10 @@
"author": "David Björklund <david@admaze.ly>",
"name": "headless",
"description": "Headless is a Node.js wrapper for Xvfb, the virtual framebuffer",
- "version": "0.1.0",
+ "version": "0.1.1",
+ "scripts": {
+ "test": "node test/test.js"
+ },
"repository": {
"type": "git",
"url": "git://github.com/kesla/node-headless.git"
View
@@ -0,0 +1,9 @@
+var assert = require('assert');
+var headless = require('../index');
+
+headless(function(err, child, servernum) {
+ assert.equal(err, null);
+ assert.equal(typeof(child), 'object');
+ assert.equal(typeof(child.kill), 'function');
+ assert.equal(typeof(servernum), 'number');
+});

0 comments on commit 39ebda2

Please sign in to comment.