ps-find
Version:
Find processes with ease
67 lines (53 loc) • 1.76 kB
JavaScript
var expect = require('chai').expect;
var noopProcess = require('noop-process');
var psFind = require('./index.js');
describe('ps-find', function () {
describe('#find', function () {
var options;
beforeEach(function () {
options = {
title: 'test',
persistent: false
};
});
afterEach(function () {
noopProcess.cleanup();
});
it('should match a process by its name', function (done) {
noopProcess(options, function (error, pid) {
if (error) throw error;
psFind.find(options.title, function (error, result) {
if (error) throw error;
expect(result).to.have.length(1);
expect(result[0].pid).to.be.equal(pid);
expect(result[0]).to.have.property('name');
done();
});
});
});
it('should work if process arguments are provided', function (done) {
options.title = "test --args";
noopProcess(options, function (error, pid) {
if (error) throw error;
psFind.find(options.title, function (error, result) {
expect(!!error).to.be.false;
expect(result).to.have.length(1);
expect(result[0].pid).to.be.equal(pid, true);
expect(result[0]).to.have.property('name');
done();
});
});
});
it('should return an empty array if nothing is found', function (done) {
noopProcess(options, function (error, pid) {
if (error) throw error;
psFind.find('myawesomeprocess', function (error, result) {
expect(!!error).to.be.true;
expect(error.message).to.be.equal('No process found.')
expect(result).to.have.length(0);
done();
});
});
});
});
});