Skip to content
Browse files

Add kill method.

  • Loading branch information...
1 parent a7cc014 commit e6eee3e4158d3145810e7bdca809853f5e5acc5d @vesln committed
Showing with 50 additions and 1 deletion.
  1. +2 −0 Makefile
  2. +11 −0 lib/runner.js
  3. +24 −1 test/runner.test.js
  4. +13 −0 test/support/term.js
View
2 Makefile
@@ -3,6 +3,8 @@ REPORTER = dot
test:
@NODE_ENV=test ./node_modules/.bin/mocha \
+ --slow 1000 \
+ --timeout 1500 \
--reporter $(REPORTER) \
$(TESTS)
View
11 lib/runner.js
@@ -58,6 +58,17 @@ Runner.prototype.run = function(program) {
};
/**
+ * Send kill signal to the spawned process.
+ *
+ * @returns {Object} `this`.
+ * @api public
+ */
+Runner.prototype.kill = function() {
+ this.child.kill();
+ return this;
+};
+
+/**
* Expose `Runner`.
*/
module.exports = Runner;
View
25 test/runner.test.js
@@ -41,7 +41,7 @@ describe('Runner', function() {
}).to.throw();
});
- describe('spawn process', function() {
+ describe('when spawn process', function() {
it('should emit out event when the child program prints something', function(done) {
var program = new Program('test/support/whiny.js');
var runner = new Runner;
@@ -58,6 +58,29 @@ describe('Runner', function() {
runner.run(program);
});
+
+ describe('and the kill is called', function() {
+ it('should send kill signal', function(done) {
+ var program = new Program('test/support/term.js');
+ var runner = new Runner;
+ var out = '';
+
+ runner.on('out', function(text) {
+ out += text.toString();
+ });
+
+ runner.on('end', function() {
+ out.should.eql('SIGTERM\n');
+ done();
+ });
+
+ runner.run(program);
+
+ setTimeout(function() {
+ runner.kill();
+ }, 100);
+ });
+ });
});
});
});
View
13 test/support/term.js
@@ -0,0 +1,13 @@
+/*!
+ * let - Force timeouts.
+ *
+ * Veselin Todorov <hi@vesln.com>
+ * MIT License.
+ */
+
+process.on('SIGTERM', function() {
+ console.log('SIGTERM');
+ process.exit(0);
+});
+
+setInterval(function() {}, 2000);

0 comments on commit e6eee3e

Please sign in to comment.
Something went wrong with that request. Please try again.