From ca75aafdf6b7b425ee151c2ae4ede37933befe1f Mon Sep 17 00:00:00 2001 From: Vojta Jina Date: Tue, 19 Mar 2013 18:36:38 -0700 Subject: [PATCH] fix(runner): send exit code as string Closes #403 --- lib/constants.js | 2 +- lib/runner.js | 7 ++++--- lib/server.js | 2 +- test/unit/runner.spec.coffee | 11 ++++++++--- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/constants.js b/lib/constants.js index 2e23b4013..04584faac 100644 --- a/lib/constants.js +++ b/lib/constants.js @@ -28,4 +28,4 @@ exports.CONSOLE_APPENDER = { } }; -exports.EXIT_CODE_0 = '\x1FEXIT0'; +exports.EXIT_CODE = '\x1FEXIT'; diff --git a/lib/runner.js b/lib/runner.js index b65fcdc7d..d816e5a88 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -4,7 +4,7 @@ var constant = require('./constants'); var helper = require('./helper'); var parseExitCode = function(buffer, defaultCode) { - var tailPos = buffer.length - Buffer.byteLength(constant.EXIT_CODE_0); + var tailPos = buffer.length - Buffer.byteLength(constant.EXIT_CODE) - 1; if (tailPos < 0) { return defaultCode; @@ -12,9 +12,10 @@ var parseExitCode = function(buffer, defaultCode) { // tail buffer which might contain the message var tail = buffer.slice(tailPos); - if (tail.toString() === constant.EXIT_CODE_0) { + var tailStr = tail.toString(); + if (tailStr.substr(0, tailStr.length - 1) === constant.EXIT_CODE) { tail.fill('\x00'); - return 0; + return parseInt(tailStr.substr(-1), 10); } return defaultCode; diff --git a/lib/server.js b/lib/server.js index 4ee6ed996..76362d412 100644 --- a/lib/server.js +++ b/lib/server.js @@ -162,7 +162,7 @@ var start = function(injector, config, launcher, globalEmitter, preprocess, file // clean up, close runner socket globalEmitter.once('run_complete', function(browsers, results) { resultReporter.removeAdapter(socketWrite); - socket.end(!results.exitCode && constant.EXIT_CODE_0); + socket.end(constant.EXIT_CODE + results.exitCode); }); }); diff --git a/test/unit/runner.spec.coffee b/test/unit/runner.spec.coffee index 416f05ab8..97a3ad855 100644 --- a/test/unit/runner.spec.coffee +++ b/test/unit/runner.spec.coffee @@ -13,14 +13,14 @@ describe 'runner', -> # runner.parseExitCode #============================================================================ describe 'parseExitCode', -> - EXIT0 = constant.EXIT_CODE_0 + EXIT = constant.EXIT_CODE it 'should return 0 exit code if present in the buffer', -> - expect(m.parseExitCode new Buffer 'something\nfake' + EXIT0).to.equal 0 + expect(m.parseExitCode new Buffer 'something\nfake' + EXIT + '0').to.equal 0 it 'should null the exit code part of the buffer', -> - buffer = new Buffer 'some' + EXIT0 + buffer = new Buffer 'some' + EXIT + '1' m.parseExitCode buffer expect(buffer.toString()).to.equal 'some\0\0\0\0\0\0' @@ -42,3 +42,8 @@ describe 'runner', -> code = m.parseExitCode fakeBuffer, 10 expect(fakeBuffer.slice).not.to.have.been.called + + + it 'should parse any single digit exit code', -> + expect(m.parseExitCode new Buffer 'something\nfake' + EXIT + '1').to.equal 1 + expect(m.parseExitCode new Buffer 'something\nfake' + EXIT + '7').to.equal 7