Skip to content

Commit

Permalink
Moar unit tests, better code
Browse files Browse the repository at this point in the history
  • Loading branch information
felixge committed Nov 14, 2011
1 parent 4dd62f2 commit b3e479f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/FileRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,15 @@ FileRunner.prototype._capture = function(stream) {
FileRunner.prototype._errorFor = function(code, signal) {
if (!code && !signal) return;

var path = this._file;
if (path.indexOf(this._cwd) === 0) path = path.substr(this._cwd.length + 1);
var prefix = 'node ' + path + ' died with ';
var prefix = 'node ' + this.relativePath() + ' died with ';

if (code) return new Error(prefix + 'code: ' + code);
if (signal) return new Error(prefix + 'signal: ' + signal);
};

FileRunner.prototype.relativePath = function() {
var path = this._file;
return (path.indexOf(this._cwd) === 0)
? path = path.substr(this._cwd.length + 1)
: path;
};
10 changes: 10 additions & 0 deletions test/unit/test-FileRunner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
var test = require('utest');
var assert = require('assert');
var FileRunner = require('../../lib/FileRunner');

test('FileRunner', {
'relativePath': function() {
var runner = new FileRunner({file: '/a/b/c', cwd: '/a'});
assert.equal(runner.relativePath(), 'b/c');
},
});

0 comments on commit b3e479f

Please sign in to comment.