diff --git a/CHANGES.md b/CHANGES.md index 24a94ca..37cf235 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,7 +8,8 @@ Known issues: ## bunyan 0.17.1 (not yet released) -(nothing yet) +- Switch test suite to nodeunit (still using a node-tap'ish API via + a helper). ## bunyan 0.17.0 diff --git a/Makefile b/Makefile index 06f0d0f..1a1d91b 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ #---- Tools -TAP := ./node_modules/.bin/tap +NODEUNIT := ./node_modules/.bin/nodeunit SUDO := sudo ifeq ($(shell uname -s),SunOS) # On SunOS (e.g. SmartOS) we expect to run the test suite as the @@ -16,7 +16,7 @@ endif JSSTYLE_FILES := $(shell find lib test tools examples -name "*.js") bin/bunyan # All test files *except* dtrace.test.js. -TEST_FILES := $(shell ls -1 test/*.test.js | grep -v dtrace | xargs) +NON_DTRACE_TEST_FILES := $(shell ls -1 test/*.test.js | grep -v dtrace | xargs) @@ -66,11 +66,11 @@ distclean: #---- test .PHONY: test -test: $(TAP) +test: $(NODEUNIT) [[ -n "$(SKIP_DTRACE)" ]] || \ node -e 'require("dtrace-provider").createDTraceProvider("isthisthingon")' && \ - $(SUDO) $(TAP) --tap test/dtrace.test.js - $(TAP) --tap $(TEST_FILES) + $(SUDO) $(NODEUNIT) test/dtrace.test.js + $(NODEUNIT) $(NON_DTRACE_TEST_FILES) # Test will all node supported versions (presumes install locations I use on # my machine). diff --git a/bin/bunyan b/bin/bunyan index d5daa63..16e0dd3 100755 --- a/bin/bunyan +++ b/bin/bunyan @@ -601,7 +601,7 @@ function handleLogLine(file, line, opts, stylize) { } if (!isValidRecord(rec)) { - if (!opts.strict) emitRecord(rec, line, opts, stylize); + if (!opts.strict) emit(line + '\n'); return; } diff --git a/package.json b/package.json index f88276d..c8a202e 100644 --- a/package.json +++ b/package.json @@ -23,12 +23,12 @@ "mv": "0.0.4" }, "devDependencies": { - "tap": "0.3.3", + "nodeunit": "0.7.4", "ben": "0.0.0", "verror": "1.3.3" }, "scripts": { - "test": "tap test/*.js" + "test": "make test" } } diff --git a/test/buffer.test.js b/test/buffer.test.js index 13c374a..5f3f419 100644 --- a/test/buffer.test.js +++ b/test/buffer.test.js @@ -8,9 +8,17 @@ var util = require('util'), inspect = util.inspect, format = util.format; -var test = require('tap').test; var bunyan = require('../lib/bunyan'); +// node-tap API +if (require.cache[__dirname + '/tap4nodeunit.js']) + delete require.cache[__dirname + '/tap4nodeunit.js']; +var tap4nodeunit = require('./tap4nodeunit.js'); +var after = tap4nodeunit.after; +var before = tap4nodeunit.before; +var test = tap4nodeunit.test; + + function Catcher() { this.records = []; diff --git a/test/child-behaviour.test.js b/test/child-behaviour.test.js index a59e8ad..0689b26 100644 --- a/test/child-behaviour.test.js +++ b/test/child-behaviour.test.js @@ -4,9 +4,18 @@ * Test some `.child(...)` behaviour. */ -var test = require('tap').test; var bunyan = require('../lib/bunyan'); +// node-tap API +if (require.cache[__dirname + '/tap4nodeunit.js']) + delete require.cache[__dirname + '/tap4nodeunit.js']; +var tap4nodeunit = require('./tap4nodeunit.js'); +var after = tap4nodeunit.after; +var before = tap4nodeunit.before; +var test = tap4nodeunit.test; + + + function CapturingStream(recs) { this.recs = recs || []; } diff --git a/test/cli.test.js b/test/cli.test.js index bb91bcb..42f6a6f 100644 --- a/test/cli.test.js +++ b/test/cli.test.js @@ -6,10 +6,19 @@ var path = require('path'); var exec = require('child_process').exec; -var format = require('util').format; -var test = require('tap').test; +var _ = require('util').format; var debug = console.warn; +// node-tap API +if (require.cache[__dirname + '/tap4nodeunit.js']) + delete require.cache[__dirname + '/tap4nodeunit.js']; +var tap4nodeunit = require('./tap4nodeunit.js'); +var after = tap4nodeunit.after; +var before = tap4nodeunit.before; +var test = tap4nodeunit.test; + + + var BUNYAN = path.resolve(__dirname, '../bin/bunyan'); //child = exec('cat *.js bad_file | wc -l', @@ -24,7 +33,7 @@ var BUNYAN = path.resolve(__dirname, '../bin/bunyan'); test('--version', function (t) { var version = require('../package.json').version; exec(BUNYAN + ' --version', function (err, stdout, stderr) { - t.error(err) + t.ifError(err) t.equal(stdout, 'bunyan ' + version + '\n'); t.end(); }); @@ -32,7 +41,7 @@ test('--version', function (t) { test('--help', function (t) { exec(BUNYAN + ' --help', function (err, stdout, stderr) { - t.error(err) + t.ifError(err) t.ok(stdout.indexOf('General options:') !== -1); t.end(); }); @@ -40,7 +49,7 @@ test('--help', function (t) { test('-h', function (t) { exec(BUNYAN + ' -h', function (err, stdout, stderr) { - t.error(err) + t.ifError(err) t.ok(stdout.indexOf('General options:') !== -1); t.end(); }); @@ -55,8 +64,9 @@ test('--bogus', function (t) { }); test('simple.log', function (t) { - exec(BUNYAN + ' corpus/simple.log', function (err, stdout, stderr) { - t.error(err) + exec(_('%s %s/corpus/simple.log', BUNYAN, __dirname), + function (err, stdout, stderr) { + t.ifError(err) t.equal(stdout, '[2012-02-08T22:56:52.856Z] INFO: myservice/123 on example.com: ' + 'My message\n'); @@ -64,9 +74,9 @@ test('simple.log', function (t) { }); }); test('cat simple.log', function (t) { - exec(format('cat corpus/simple.log | %s', BUNYAN), + exec(_('cat %s/corpus/simple.log | %s', __dirname, BUNYAN), function (err, stdout, stderr) { - t.error(err) + t.ifError(err) t.equal(stdout, '[2012-02-08T22:56:52.856Z] INFO: myservice/123 on example.com: ' + 'My message\n'); @@ -75,8 +85,9 @@ test('cat simple.log', function (t) { ); }); test('simple.log with color', function (t) { - exec(BUNYAN + ' --color corpus/simple.log', function (err, stdout, stderr) { - t.error(err) + exec(_('%s --color %s/corpus/simple.log', BUNYAN, __dirname), + function (err, stdout, stderr) { + t.ifError(err) t.equal(stdout, '[2012-02-08T22:56:52.856Z] \u001b[36m INFO\u001b[39m: myservice/123 ' + 'on example.com: \u001b[36mMy message\u001b[39m\n'); @@ -85,8 +96,9 @@ test('simple.log with color', function (t) { }); test('extrafield.log', function (t) { - exec(BUNYAN + ' corpus/extrafield.log', function (err, stdout, stderr) { - t.error(err) + exec(_('%s %s/corpus/extrafield.log', BUNYAN, __dirname), + function (err, stdout, stderr) { + t.ifError(err) t.equal(stdout, '[2012-02-08T22:56:52.856Z] INFO: myservice/123 on example.com: ' + 'My message (extra=field)\n'); @@ -94,9 +106,9 @@ test('extrafield.log', function (t) { }); }); test('extrafield.log with color', function (t) { - exec(BUNYAN + ' --color corpus/extrafield.log', + exec(_('%s --color %s/corpus/extrafield.log', BUNYAN, __dirname), function (err, stdout, stderr) { - t.error(err) + t.ifError(err) t.equal(stdout, '[2012-02-08T22:56:52.856Z] \u001b[36m INFO\u001b[39m: myservice/123 ' + 'on example.com: \u001b[36mMy message\u001b[39m' @@ -106,31 +118,35 @@ test('extrafield.log with color', function (t) { }); test('bogus.log', function (t) { - exec(BUNYAN + ' corpus/bogus.log', function (err, stdout, stderr) { - t.error(err) + exec(_('%s %s/corpus/bogus.log', BUNYAN, __dirname), + function (err, stdout, stderr) { + t.ifError(err) t.equal(stdout, 'not a JSON line\n{"hi": "there"}\n'); t.end(); }); }); test('bogus.log -j', function (t) { - exec(BUNYAN + ' -j corpus/bogus.log', function (err, stdout, stderr) { - t.error(err) - t.equal(stdout, 'not a JSON line\n{\n "hi": "there"\n}\n'); + exec(_('%s -j %s/corpus/bogus.log', BUNYAN, __dirname), + function (err, stdout, stderr) { + t.ifError(err) + t.equal(stdout, 'not a JSON line\n{"hi": "there"}\n'); t.end(); }); }); test('all.log', function (t) { - exec(BUNYAN + ' corpus/all.log', function (err, stdout, stderr) { + exec(_('%s %s/corpus/all.log', BUNYAN, __dirname), + function (err, stdout, stderr) { // Just make sure don't blow up on this. - t.error(err) + t.ifError(err) t.end(); }); }); test('simple.log doesnotexist1.log doesnotexist2.log', function (t) { - exec(BUNYAN + ' corpus/simple.log doesnotexist1.log doesnotexist2.log', + exec(_('%s %s/corpus/simple.log doesnotexist1.log doesnotexist2.log', + BUNYAN, __dirname), function (err, stdout, stderr) { t.ok(err) t.equal(err.code, 2) @@ -151,9 +167,9 @@ test('simple.log doesnotexist1.log doesnotexist2.log', function (t) { }); test('multiple logs', function (t) { - exec(BUNYAN + ' corpus/log1.log corpus/log2.log', + exec(_('%s %s/corpus/log1.log %s/corpus/log2.log', BUNYAN, __dirname, __dirname), function (err, stdout, stderr) { - t.error(err); + t.ifError(err); t.equal(stdout, [ '[2012-05-08T16:57:55.586Z] INFO: agent1/73267 on headnode: message\n', '[2012-05-08T16:58:55.586Z] INFO: agent2/73267 on headnode: message\n', @@ -170,8 +186,9 @@ test('multiple logs', function (t) { }); test('log1.log.gz', function (t) { - exec(BUNYAN + ' corpus/log1.log.gz', function (err, stdout, stderr) { - t.error(err); + exec(_('%s %s/corpus/log1.log.gz', BUNYAN, __dirname), + function (err, stdout, stderr) { + t.ifError(err); t.equal(stdout, [ '[2012-05-08T16:57:55.586Z] INFO: agent1/73267 on headnode: message\n', '[2012-05-08T17:02:49.339Z] INFO: agent1/73267 on headnode: message\n', @@ -183,9 +200,9 @@ test('log1.log.gz', function (t) { }); test('mixed text and gzip logs', function (t) { - exec(BUNYAN + ' corpus/log1.log.gz corpus/log2.log', + exec(_('%s %s/corpus/log1.log.gz %s/corpus/log2.log', BUNYAN, __dirname, __dirname), function (err, stdout, stderr) { - t.error(err); + t.ifError(err); t.equal(stdout, [ '[2012-05-08T16:57:55.586Z] INFO: agent1/73267 on headnode: message\n', '[2012-05-08T16:58:55.586Z] INFO: agent2/73267 on headnode: message\n', @@ -215,11 +232,13 @@ test('--level 40', function (t) { 'not a JSON line\n', '{"hi": "there"}\n' ].join(''); - exec(BUNYAN + ' -l 40 corpus/all.log', function (err, stdout, stderr) { - t.error(err); + exec(_('%s -l 40 %s/corpus/all.log', BUNYAN, __dirname), + function (err, stdout, stderr) { + t.ifError(err); t.equal(stdout, expect); - exec(BUNYAN + ' --level 40 corpus/all.log', function (err, stdout, stderr) { - t.error(err); + exec(_('%s --level 40 %s/corpus/all.log', BUNYAN, __dirname), + function (err, stdout, stderr) { + t.ifError(err); t.equal(stdout, expect); t.end(); }); @@ -237,13 +256,13 @@ test('--condition "level === 10 && pid === 123"', function (t) { 'not a JSON line\n', '{"hi": "there"}\n' ].join(''); - exec(BUNYAN + ' -c "level === 10 && pid === 123" corpus/all.log', + exec(_('%s -c "level === 10 && pid === 123" %s/corpus/all.log', BUNYAN, __dirname), function (err, stdout, stderr) { - t.error(err); + t.ifError(err); t.equal(stdout, expect); - exec(BUNYAN + ' --condition "level === 10 && pid === 123" corpus/all.log', + exec(_('%s --condition "level === 10 && pid === 123" %s/corpus/all.log', BUNYAN, __dirname), function (err, stdout, stderr) { - t.error(err); + t.ifError(err); t.equal(stdout, expect); t.end(); }); @@ -263,10 +282,11 @@ test('multiple --conditions', function (t) { 'not a JSON line\n', '{"hi": "there"}\n' ].join(''); - exec(BUNYAN + ' corpus/all.log ' + - '-c "if (level === 40) pid = 1; true" ' + - '-c "pid === 1"', function (err, stdout, stderr) { - t.error(err); + exec(_('%s %s/corpus/all.log ' + + '-c "if (level === 40) pid = 1; true" ' + + '-c "pid === 1"', BUNYAN, __dirname), + function (err, stdout, stderr) { + t.ifError(err); t.equal(stdout, expect); t.end(); }); @@ -310,17 +330,9 @@ test('robust req handling', function (t) { ' "version": false', ' }' ].join('\n') + '\n'; - exec(BUNYAN + ' corpus/withreq.log', function (err, stdout, stderr) { - t.error(err); - t.equal(stdout, expect); - t.end(); - }); -}); - -test('non-object res field', function (t) { - var expect = '[2012-10-10T16:14:07.610Z] INFO: cnapi.get_existing_nics/24440 on 710c784f-6aa5-428c-9074-e046c3af884e: got existing: 02:08:20:d7:53:e0 (job_uuid=3499b13e-dbca-4331-b13a-f164c0da320a, nic=, res="error: Unknown nic \\"020820d753e0\\"")\n'; - exec(BUNYAN + ' corpus/non-object-res.log', function (err, stdout, stderr) { - t.error(err); + exec(_('%s %s/corpus/withreq.log', BUNYAN, __dirname), + function (err, stdout, stderr) { + t.ifError(err); t.equal(stdout, expect); t.end(); }); diff --git a/test/ctor.test.js b/test/ctor.test.js index a5c0bcc..685f418 100644 --- a/test/ctor.test.js +++ b/test/ctor.test.js @@ -4,19 +4,26 @@ * Test type checking on creation of the Logger. */ -var test = require('tap').test; var bunyan = require('../lib/bunyan'), Logger = bunyan; +// node-tap API +if (require.cache[__dirname + '/tap4nodeunit.js']) + delete require.cache[__dirname + '/tap4nodeunit.js']; +var tap4nodeunit = require('./tap4nodeunit.js'); +var after = tap4nodeunit.after; +var before = tap4nodeunit.before; +var test = tap4nodeunit.test; + test('ensure Logger creation options', function (t) { t.throws(function () { new Logger(); }, - {name: 'TypeError', message: 'options (object) is required'}, + 'options (object) is required', 'no options should throw'); t.throws(function () { new Logger({}); }, - {name: 'TypeError', message: 'options.name (string) is required'}, + 'options.name (string) is required', 'no options.name should throw'); t.doesNotThrow(function () { new Logger({name: 'foo'}); }, @@ -29,23 +36,17 @@ test('ensure Logger creation options', function (t) { // https://github.com/trentm/node-bunyan/issues/3 options = {name: 'foo', streams: {}}; t.throws(function () { new Logger(options); }, - {name: 'TypeError', message: 'invalid options.streams: must be an array'}, + 'invalid options.streams: must be an array', '"streams" must be an array'); options = {name: 'foo', serializers: 'a string'}; t.throws(function () { new Logger(options); }, - { - name: 'TypeError', - message: 'invalid options.serializers: must be an object' - }, + 'invalid options.serializers: must be an object', '"serializers" cannot be a string'); options = {name: 'foo', serializers: [1, 2, 3]}; t.throws(function () { new Logger(options); }, - { - name: 'TypeError', - message: 'invalid options.serializers: must be an object' - }, + 'invalid options.serializers: must be an object', '"serializers" cannot be an array'); t.end(); @@ -54,11 +55,11 @@ test('ensure Logger creation options', function (t) { test('ensure Logger creation options (createLogger)', function (t) { t.throws(function () { bunyan.createLogger(); }, - {name: 'TypeError', message: 'options (object) is required'}, + 'options (object) is required', 'no options should throw'); t.throws(function () { bunyan.createLogger({}); }, - {name: 'TypeError', message: 'options.name (string) is required'}, + 'options.name (string) is required', 'no options.name should throw'); t.doesNotThrow(function () { bunyan.createLogger({name: 'foo'}); }, @@ -71,23 +72,17 @@ test('ensure Logger creation options (createLogger)', function (t) { // https://github.com/trentm/node-bunyan/issues/3 options = {name: 'foo', streams: {}}; t.throws(function () { bunyan.createLogger(options); }, - {name: 'TypeError', message: 'invalid options.streams: must be an array'}, + 'invalid options.streams: must be an array', '"streams" must be an array'); options = {name: 'foo', serializers: 'a string'}; t.throws(function () { bunyan.createLogger(options); }, - { - name: 'TypeError', - message: 'invalid options.serializers: must be an object' - }, + 'invalid options.serializers: must be an object', '"serializers" cannot be a string'); options = {name: 'foo', serializers: [1, 2, 3]}; t.throws(function () { bunyan.createLogger(options); }, - { - name: 'TypeError', - message: 'invalid options.serializers: must be an object' - }, + 'invalid options.serializers: must be an object', '"serializers" cannot be an array'); t.end(); @@ -104,10 +99,7 @@ test('ensure Logger child() options', function (t) { 'empty options should be fine too'); t.throws(function () { log.child({name: 'foo'}); }, - { - name: 'TypeError', - message: 'invalid options.name: child cannot set logger name' - }, + 'invalid options.name: child cannot set logger name', 'child cannot change name'); var options = {stream: process.stdout, streams: []}; @@ -117,23 +109,17 @@ test('ensure Logger child() options', function (t) { // https://github.com/trentm/node-bunyan/issues/3 options = {streams: {}}; t.throws(function () { log.child(options); }, - {name: 'TypeError', message: 'invalid options.streams: must be an array'}, + 'invalid options.streams: must be an array', '"streams" must be an array'); options = {serializers: 'a string'}; t.throws(function () { log.child(options); }, - { - name: 'TypeError', - message: 'invalid options.serializers: must be an object' - }, + 'invalid options.serializers: must be an object', '"serializers" cannot be a string'); options = {serializers: [1, 2, 3]}; t.throws(function () { log.child(options); }, - { - name: 'TypeError', - message: 'invalid options.serializers: must be an object' - }, + 'invalid options.serializers: must be an object', '"serializers" cannot be an array'); t.end(); diff --git a/test/cycles.test.js b/test/cycles.test.js index c845aae..83f569f 100644 --- a/test/cycles.test.js +++ b/test/cycles.test.js @@ -4,9 +4,17 @@ * Make sure cycles are safe. */ -var test = require('tap').test; var Logger = require('../lib/bunyan.js'); +// node-tap API +if (require.cache[__dirname + '/tap4nodeunit.js']) + delete require.cache[__dirname + '/tap4nodeunit.js']; +var tap4nodeunit = require('./tap4nodeunit.js'); +var after = tap4nodeunit.after; +var before = tap4nodeunit.before; +var test = tap4nodeunit.test; + + var Stream = require('stream').Stream; var outstr = new Stream; outstr.writable = true; @@ -61,7 +69,13 @@ var log = new Logger({ test('cycles', function (t) { outstr.on('end', function () { output.forEach(function (o, i) { - t.has(o, expect[i], 'log item ' + i + ' matches'); + // Drop variable parts for comparison. + delete o.hostname; + delete o.pid; + delete o.time; + // Hack object/dict comparison: JSONify. + t.equal(JSON.stringify(o), JSON.stringify(expect[i]), + 'log item ' + i + ' matches'); }); t.end(); }); @@ -72,5 +86,5 @@ test('cycles', function (t) { log.info('kaboom', obj.KABOOM); log.info(obj); outstr.end(); - t.pass('did not throw'); + t.ok('did not throw'); }); diff --git a/test/dtrace.test.js b/test/dtrace.test.js index ccce639..062b740 100644 --- a/test/dtrace.test.js +++ b/test/dtrace.test.js @@ -7,9 +7,16 @@ var spawn = require('child_process').spawn; var format = require('util').format; -var test = require('tap').test; var bunyan = require('../lib/bunyan'); +// node-tap API +if (require.cache[__dirname + '/tap4nodeunit.js']) + delete require.cache[__dirname + '/tap4nodeunit.js']; +var tap4nodeunit = require('./tap4nodeunit.js'); +var after = tap4nodeunit.after; +var before = tap4nodeunit.before; +var test = tap4nodeunit.test; + // Determine if we can run the dtrace tests. var dtracePlats = ['sunos', 'darwin', 'freebsd']; diff --git a/test/error-event.test.js b/test/error-event.test.js index 6c8f0cf..9c138f9 100644 --- a/test/error-event.test.js +++ b/test/error-event.test.js @@ -5,13 +5,21 @@ * stream. */ -var test = require('tap').test; -var Logger = require('../lib/bunyan'); +var bunyan = require('../lib/bunyan'); + +// node-tap API +if (require.cache[__dirname + '/tap4nodeunit.js']) + delete require.cache[__dirname + '/tap4nodeunit.js']; +var tap4nodeunit = require('./tap4nodeunit.js'); +var after = tap4nodeunit.after; +var before = tap4nodeunit.before; +var test = tap4nodeunit.test; + test('error event on log write', function (t) { LOG_PATH = '/this/path/is/bogus.log' - var log = new Logger({name: 'error-event', streams: [{path: LOG_PATH}]}); - t.plan(5); + var log = bunyan.createLogger( + {name: 'error-event', streams: [{path: LOG_PATH}]}); log.on('error', function (err, stream) { t.ok(err, 'got err in error event: ' + err); t.equal(err.code, 'ENOENT', 'error code is ENOENT'); diff --git a/test/log.test.js b/test/log.test.js index 264d946..5862374 100644 --- a/test/log.test.js +++ b/test/log.test.js @@ -4,10 +4,18 @@ * Test the `log.trace(...)`, `log.debug(...)`, ..., `log.fatal(...)` API. */ -var test = require('tap').test; -var Logger = require('../lib/bunyan'); +var bunyan = require('../lib/bunyan'); -var log1 = new Logger({ +// node-tap API +if (require.cache[__dirname + '/tap4nodeunit.js']) + delete require.cache[__dirname + '/tap4nodeunit.js']; +var tap4nodeunit = require('./tap4nodeunit.js'); +var after = tap4nodeunit.after; +var before = tap4nodeunit.before; +var test = tap4nodeunit.test; + + +var log1 = bunyan.createLogger({ name: 'log1', streams: [ { @@ -17,7 +25,7 @@ var log1 = new Logger({ ] }); -var log2 = new Logger({ +var log2 = bunyan.createLogger({ name: 'log2', streams: [ { @@ -32,7 +40,7 @@ var log2 = new Logger({ }) test('log.LEVEL() -> boolean', function (t) { - t.equal(log1.trace(), false) + t.equal(log1.trace(), false, 'log1.trace() is false') t.equal(log1.debug(), false) t.equal(log1.info(), true) t.equal(log1.warn(), true) diff --git a/test/other-api.test.js b/test/other-api.test.js index 25bee68..29fc580 100644 --- a/test/other-api.test.js +++ b/test/other-api.test.js @@ -4,9 +4,17 @@ * Test other parts of the exported API. */ -var test = require('tap').test; var bunyan = require('../lib/bunyan'); +// node-tap API +if (require.cache[__dirname + '/tap4nodeunit.js']) + delete require.cache[__dirname + '/tap4nodeunit.js']; +var tap4nodeunit = require('./tap4nodeunit.js'); +var after = tap4nodeunit.after; +var before = tap4nodeunit.before; +var test = tap4nodeunit.test; + + test('bunyan.s', function (t) { t.ok(bunyan.TRACE, 'TRACE'); t.ok(bunyan.DEBUG, 'DEBUG'); @@ -32,4 +40,3 @@ test('bunyan.resolveLevel()', function (t) { t.equal(bunyan.resolveLevel('FATAL'), bunyan.FATAL, 'FATAL'); t.end(); }); - diff --git a/test/raw-stream.test.js b/test/raw-stream.test.js index 8eb1336..21d5ad7 100644 --- a/test/raw-stream.test.js +++ b/test/raw-stream.test.js @@ -5,9 +5,15 @@ */ var format = require('util').format; -var test = require('tap').test; var Logger = require('../lib/bunyan'); +// node-tap API +if (require.cache[__dirname + '/tap4nodeunit.js']) + delete require.cache[__dirname + '/tap4nodeunit.js']; +var tap4nodeunit = require('./tap4nodeunit.js'); +var after = tap4nodeunit.after; +var before = tap4nodeunit.before; +var test = tap4nodeunit.test; function CapturingStream(recs) { diff --git a/test/ringbuffer.test.js b/test/ringbuffer.test.js index 75a6a12..1fd7329 100644 --- a/test/ringbuffer.test.js +++ b/test/ringbuffer.test.js @@ -2,10 +2,18 @@ * Test the RingBuffer output stream. */ -var test = require('tap').test; var Logger = require('../lib/bunyan'); var ringbuffer = new Logger.RingBuffer({ 'limit': 5 }); +// node-tap API +if (require.cache[__dirname + '/tap4nodeunit.js']) + delete require.cache[__dirname + '/tap4nodeunit.js']; +var tap4nodeunit = require('./tap4nodeunit.js'); +var after = tap4nodeunit.after; +var before = tap4nodeunit.before; +var test = tap4nodeunit.test; + + var log1 = new Logger({ name: 'log1', streams: [ diff --git a/test/std-serializers.test.js b/test/std-serializers.test.js index 5ab13a7..98cf99c 100644 --- a/test/std-serializers.test.js +++ b/test/std-serializers.test.js @@ -4,12 +4,19 @@ * Test the standard serializers in Bunyan. */ -var test = require('tap').test; var http = require('http'); var bunyan = require('../lib/bunyan'); var verror = require('verror'); +// node-tap API +if (require.cache[__dirname + '/tap4nodeunit.js']) + delete require.cache[__dirname + '/tap4nodeunit.js']; +var tap4nodeunit = require('./tap4nodeunit.js'); +var after = tap4nodeunit.after; +var before = tap4nodeunit.before; +var test = tap4nodeunit.test; + function CapturingStream(recs) { this.recs = recs; diff --git a/test/tap4nodeunit.js b/test/tap4nodeunit.js new file mode 100644 index 0000000..6443be0 --- /dev/null +++ b/test/tap4nodeunit.js @@ -0,0 +1,62 @@ +/* + * Copyright 2012 Mark Cavage. All rights reserved. + * + * Help nodeunit API feel like node-tap's. + * + * Usage: + * if (require.cache[__dirname + '/tap4nodeunit.js']) + * delete require.cache[__dirname + '/tap4nodeunit.js']; + * var tap4nodeunit = require('./tap4nodeunit.js'); + * var after = tap4nodeunit.after; + * var before = tap4nodeunit.before; + * var test = tap4nodeunit.test; + */ + + + +//---- Exports + +module.exports = { + + after: function after(teardown) { + module.parent.exports.tearDown = function _teardown(callback) { + try { + teardown.call(this, callback); + } catch (e) { + console.error('after:\n' + e.stack); + process.exit(1); + } + }; + }, + + before: function before(setup) { + module.parent.exports.setUp = function _setup(callback) { + try { + setup.call(this, callback); + } catch (e) { + console.error('before:\n' + e.stack); + process.exit(1); + } + }; + }, + + test: function test(name, tester) { + module.parent.exports[name] = function _(t) { + var _done = false; + t.end = function end() { + if (!_done) { + _done = true; + t.done(); + } + }; + t.notOk = function notOk(ok, message) { + return (t.ok(!ok, message)); + }; + t.error = t.ifError; + + tester.call(this, t); + }; + } + + +};