Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
version 0.0.4
  • Loading branch information
leetreveil committed Apr 3, 2012
1 parent ee74ec8 commit 8dd0004
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 77 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
@@ -1,4 +1,4 @@
language: node_js
node_js:
- 0.4
language: node_js
node_js:
- 0.4
- 0.6
14 changes: 7 additions & 7 deletions TODO
@@ -1,8 +1,8 @@
IDEAS:

be able to manually invoke ranTests so it isn't a requirement that we use the custom assert object

should we disallow 'properties' and recommend that expected/timeout settings are passed
through the constructor?

IDEAS:
be able to manually invoke ranTests so it isn't a requirement that we use the custom assert object
should we disallow 'properties' and recommend that expected/timeout settings are passed
through the constructor?
MANTRA? everything is optional
41 changes: 20 additions & 21 deletions alltests.js
@@ -1,22 +1,21 @@
if (module == require.main) {

var spawn = require('child_process').spawn,
path = require('path');

var tests = ['test-fail.js', 'test-multinstance.js',
'test-namedtest.js', 'test-simple.js',
'test-timeout.js'];

for (var i=0; i < tests.length; i++) {
var test = tests[i];
var testProcess = spawn(process.execPath, [path.join(__dirname, test)]);

testProcess.stdout.on('data', function(data) {
process.stdout.write(data.toString());
});

testProcess.stderr.on('data', function(data) {
process.stderr.write(data.toString());
});
}
if (module == require.main) {

var spawn = require('child_process').spawn,
path = require('path');

var tests = ['test-fail.js', 'test-multinstance.js',
'test-namedtest.js', 'test-simple.js'];

for (var i=0; i < tests.length; i++) {
var test = tests[i];
var testProcess = spawn(process.execPath, [path.join(__dirname, test)]);

testProcess.stdout.on('data', function(data) {
process.stdout.write(data.toString());
});

testProcess.stderr.on('data', function(data) {
process.stderr.write(data.toString());
});
}
}
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{ "name": "testy",
"description": "Super simple testing framework",
"version": "0.0.3",
"version": "0.0.4",
"author": "Lee Treveil",
"main": "testy",
"scripts": {
Expand Down
4 changes: 1 addition & 3 deletions test-fail.js
@@ -1,6 +1,4 @@
var testy = require('./testy');

var test = new testy({ expected : 1, name : 'Failing test, is meant to be red!!!'});
var assert = test.assert;

test.finish();
var assert = test.assert;
4 changes: 1 addition & 3 deletions test-multinstance.js
Expand Up @@ -4,11 +4,9 @@ var testy1 = new testy({ expected : 1 });
var assert1 = testy1.assert;

assert1.strictEqual(1, 1);
testy1.finish();


var testy2 = new testy({ expected : 1 });
var assert2 = testy2.assert;

assert2.strictEqual(1, 1);
testy2.finish();
assert2.strictEqual(1, 1);
3 changes: 1 addition & 2 deletions test-namedtest.js
Expand Up @@ -3,5 +3,4 @@ var testy = require('./testy');
var test = new testy({ expected : 1, name : 'Some simple test' });
var assert = test.assert;

assert.strictEqual(1, 1);
test.finish();
assert.strictEqual(1, 1);
3 changes: 1 addition & 2 deletions test-simple.js
Expand Up @@ -3,5 +3,4 @@ var testy = require('./testy');
var test = new testy();
var assert = test.assert;

assert.strictEqual(1, 1);
test.finish();
assert.strictEqual(1, 1);
9 changes: 0 additions & 9 deletions test-timeout.js

This file was deleted.

37 changes: 11 additions & 26 deletions testy.js
Expand Up @@ -21,16 +21,16 @@ var AssertExt = function() {
});
}

util.inherits(AssertExt, events.EventEmitter);
util.inherits(AssertExt, events.EventEmitter);

var Testy = module.exports = function(options) {
if (!(this instanceof Testy)) return new Testy();

this.timeout = 500;
this.expected = 0;
this.name = '';
this.assert = new AssertExt();
this._testsRan = 0;
this._timer = Date.now();

options = options || {};

Expand All @@ -39,33 +39,18 @@ var Testy = module.exports = function(options) {
var key = keys[i];
this[key] = options[key];
}

var self = this;
this.assert.on('RANTEST', function() {
self.ranTests(1);
});

this.ranTests(0); //do a check now (incase no tests are ran)
}

Testy.prototype.finish = function() {
clearTimeout(this._timeout);
this.report();
}

Testy.prototype.ranTests = function(number) {
this._testsRan += number;
this._timer = this._timer || Date.now();
//everytime we run a test we reset the timeout
clearTimeout(this._timeout);

//either a timeout or an explicit
//call to finish() will end the test

var self = this;
this._timeout = setTimeout(function() {

// when the process exits report the results
process.on('exit', function () {
self.report();
}, this.timeout);
});

// everytime a test is ran update the test count
this.assert.on('RANTEST', function() {
self._testsRan += 1;
});
}

Testy.prototype.report = function() {
Expand Down

0 comments on commit 8dd0004

Please sign in to comment.