Skip to content

Commit

Permalink
fix(runner): send exit code as string
Browse files Browse the repository at this point in the history
Closes #403
  • Loading branch information
vojtajina committed Mar 20, 2013
1 parent bc4db54 commit ca75aaf
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ exports.CONSOLE_APPENDER = {
}
};

exports.EXIT_CODE_0 = '\x1FEXIT0';
exports.EXIT_CODE = '\x1FEXIT';
7 changes: 4 additions & 3 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ 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;
}

// 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;
Expand Down
2 changes: 1 addition & 1 deletion lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

Expand Down
11 changes: 8 additions & 3 deletions test/unit/runner.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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

0 comments on commit ca75aaf

Please sign in to comment.