Skip to content

Commit

Permalink
Convert to tape/faucet/istanbul for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pfmooney committed Aug 6, 2014
1 parent 2df8348 commit 01d7375
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 62 deletions.
3 changes: 2 additions & 1 deletion .gitignore
@@ -1,9 +1,10 @@
/node_modules
/coverage
/tmp
build
docs/*.json
docs/*.html
cscope.in.out
cscope.po.out
cscope.out
smf/manifests/bapi.xml
.DS_Store
13 changes: 7 additions & 6 deletions Makefile
Expand Up @@ -4,7 +4,8 @@
#
# Tools
#
NODEUNIT := ./node_modules/.bin/nodeunit
ISTANBUL := ./node_modules/.bin/istanbul
FAUCET := ./node_modules/.bin/faucet
NPM := npm

#
Expand All @@ -23,17 +24,17 @@ include ./tools/mk/Makefile.defs
# Repo-specific targets
#
.PHONY: all
all: $(NODEUNIT) $(REPO_DEPS)
all: $(ISTANBUL) $(REPO_DEPS)
$(NPM) rebuild

$(NODEUNIT): | $(NPM_EXEC)
$(ISTANBUL): | $(NPM_EXEC)
$(NPM) install

CLEAN_FILES += $(NODEUNIT) ./node_modules/nodeunit
CLEAN_FILES += ./node_modules ./coverage

.PHONY: test
test: $(NODEUNIT)
$(NODEUNIT) test/*.test.js
test: $(ISTANBUL)
$(ISTANBUL) cover --print none test/test.js | $(FAUCET)

include ./tools/mk/Makefile.deps
include ./tools/mk/Makefile.targ
10 changes: 7 additions & 3 deletions package.json
Expand Up @@ -3,7 +3,8 @@
"contributors": [
"Mike Harsch",
"Nate Fitche",
"Yunong Xiao"
"Yunong Xiao",
"Patrick Mooney"
],
"name": "fast",
"homepage": "http://mcavage.github.com/node-fast",
Expand All @@ -27,9 +28,12 @@
"verror": "1.3.6"
},
"devDependencies": {
"nodeunit": "0.8.2"
"tape": "2.14.0",
"faucet": "0.0.1",
"istanbul": "0.3.0"
},
"scripts": {
"test": "./node_modules/.bin/nodeunit test/*.test.js"
"report": "./node_modules/.bin/istanbul report html && open ./coverage/lcov-report/index.html",
"test": "./node_modules/.bin/istanbul cover --print none test/test.js | ./node_modules/.bin/faucet"
}
}
15 changes: 6 additions & 9 deletions test/client.test.js
@@ -1,18 +1,15 @@
// Copyright 2014 Joyent, Inc. All rights reserved.

var fast = require('../lib');

if (require.cache[__dirname + '/helper.js'])
delete require.cache[__dirname + '/helper.js'];
var test = require('./helper.js').test;
var test = require('tape').test;


///--- Globals

var HOST = process.env.TEST_HOST || "127.0.0.1";
var HOST = process.env.TEST_HOST || '127.0.0.1';
var PORT = process.env.TEST_PORT || 12345;
// a bogus loopback address should work for testing connect timeout
var TIMEOUT_HOST = process.env.TEST_TIMEOUT_HOST || "127.1.1.1";
var TIMEOUT_HOST = process.env.TEST_TIMEOUT_HOST || '127.1.1.1';
var TIMEOUT_MS = 1000;

var client;
Expand All @@ -26,7 +23,7 @@ test('connect timeout', function (t) {
function done() {
client.removeAllListeners();
client.close();
t.done();
t.end();
}

client = fast.createClient({
Expand Down Expand Up @@ -58,7 +55,7 @@ test('close suppress connectErrors', function (t) {
client.close();
setTimeout(function () {
t.ok(true);
t.done();
t.end();
}, TIMEOUT_MS);
});
});
Expand All @@ -81,6 +78,6 @@ test('connect retry limit', function (t) {
// The first failure is not a retry
t.equal(realCount, targetCount+1, 'retry count');
client.close();
t.done();
t.end();
});
});
24 changes: 0 additions & 24 deletions test/helper.js

This file was deleted.

9 changes: 3 additions & 6 deletions test/message.test.js
@@ -1,10 +1,7 @@
// Copyright 2012 Mark Cavage. All rights reserved.

var fast = require('../lib');

if (require.cache[__dirname + '/helper.js'])
delete require.cache[__dirname + '/helper.js'];
var test = require('./helper.js').test;
var test = require('tape').test;



Expand All @@ -25,7 +22,7 @@ test('serialize ok', function (t) {
t.deepEqual(JSON.parse(buf.slice(15, 32).toString()), {
hello: 'world'
});
t.done();
t.end();
});
encoder.send({
msgid: 123,
Expand Down Expand Up @@ -61,7 +58,7 @@ test('deserialize ok', function (t) {
t.equal(msg2.type, msg1.type);
t.equal(msg2.version, msg1.version);
t.deepEqual(msg2.data, msg1.data);
t.done();
t.end();
});

encoder.pipe(decoder);
Expand Down
23 changes: 10 additions & 13 deletions test/rpc.test.js
@@ -1,10 +1,7 @@
// Copyright 2012 Mark Cavage. All rights reserved.

var fast = require('../lib');

if (require.cache[__dirname + '/helper.js'])
delete require.cache[__dirname + '/helper.js'];
var test = require('./helper.js').test;
var test = require('tape').test;



Expand All @@ -22,13 +19,13 @@ var server;
test('createServer', function (t) {
server = fast.createServer();
t.ok(server);
t.done();
t.end();
});


test('listen', function (t) {
server.listen(PORT, function () {
t.done();
t.end();
});
});

Expand All @@ -39,7 +36,7 @@ test('createClient', function (t) {
port: PORT
});
client.on('connect', function () {
t.done();
t.end();
});
});

Expand All @@ -54,7 +51,7 @@ test('echo RPC handler', function (t) {
t.equal(msg, 'hello world');
});
req.on('end', function () {
t.done();
t.end();
});
});

Expand All @@ -75,7 +72,7 @@ test('error RPC handler', function (t) {
t.ok(err.context);
if (err.context)
t.equal(err.context.foo, 'bar');
t.done();
t.end();
});
});

Expand All @@ -96,7 +93,7 @@ test('streaming RPC handler', function (t) {
});
req.on('end', function () {
t.equal(seen, 10);
t.done();
t.end();
});
});

Expand All @@ -117,7 +114,7 @@ test('RPC handler with thrown error #1', function (t) {

client.rpc('echo2', 'foo').once('error', function (err) {
t.ok(err);
t.done();
t.end();
});

});
Expand All @@ -140,7 +137,7 @@ test('RPC handler with thrown error #2', function (t) {

client.rpc('echo3', 'foo').once('error', function (err) {
t.ok(err);
t.done();
t.end();
});
});

Expand All @@ -150,7 +147,7 @@ test('teardown', function (t) {
var clientClosed = false;
function tryEnd() {
if (serverClosed && clientClosed) {
t.done();
t.end();
}
}
server.on('close', function () {
Expand Down
21 changes: 21 additions & 0 deletions test/test.js
@@ -0,0 +1,21 @@
// Copyright 2014 Joyent, Inc. All rights reserved.


var fs = require('fs');
var path = require('path');

function runTests(directory) {
fs.readdir(directory, function (err, files) {
files.filter(function (f) {
return (/\.test\.js$/.test(f));
}).map(function (f) {
return (path.join(directory, f));
}).forEach(require);
});
}

///--- Run All Tests

(function main() {
runTests(__dirname);
})();

0 comments on commit 01d7375

Please sign in to comment.