cross-port-killer
Version:
Kill the process running on a given TCP port on Windows, Linux and Mac
32 lines (31 loc) • 1.3 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var child_process_1 = require("child_process");
var expect = require("expect.js");
var psList = require("ps-list");
var port_killer_1 = require("../source/port-killer");
describe('Assassin', function () {
it('should terminate process running on a given port', function (done) {
var server = (0, child_process_1.spawn)('node', [require.resolve('http-server/bin/http-server'), '-p', '7070'], {
stdio: 'ignore',
detached: true,
});
server.unref();
var instance = new port_killer_1.Killer(process.platform);
var loop = function (limit) {
if (limit === void 0) { limit = 50; }
instance
.kill(7070)
.then(function (pid) { return expect(server.pid.toString()).to.be(pid.pop()) && psList(); })
.then(function (data) {
for (var _i = 0, data_1 = data; _i < data_1.length; _i++) {
var pid = data_1[_i].pid;
expect(pid).not.to.be(server.pid);
}
})
.then(done)
.catch(function () { return (limit > 0 ? loop(--limit) : null); });
};
setTimeout(loop, 500);
});
});