Skip to content

Instantly share code, notes, and snippets.

@logicalparadox
Created July 11, 2012 06:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save logicalparadox/3088389 to your computer and use it in GitHub Desktop.
Save logicalparadox/3088389 to your computer and use it in GitHub Desktop.
Chai helper to check if a pid is running.

.alive

Used to determine if a process pid is running from node.js.

expect(1234).to.be.alive;
chai.Assertion.addProperty('alive', function () {
new chai.Assertion(this._obj).to.be.a('number');
var alive = true
, pid = this._obj;
try { process.kill(pid, 0); }
catch (ex) { if (ex.code == 'ESRCH') alive = false; }
this.assert(
alive === true
, 'expected pid #{this} to be alive'
, 'expected pid #{this} to not be alive'
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment