Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[api] [test] execute log callback correctly. use exposed winston tests.

  • Loading branch information...
commit 80cefc954a6f96e9127a153e8becdfeed798c68f 1 parent 3fe76ae
Christopher Jeffrey (JJ) chjj authored
Showing with 8 additions and 68 deletions.
  1. +1 −1  lib/winston-nssocket.js
  2. +7 −67 test/winston-nssocket-test.js
2  lib/winston-nssocket.js
View
@@ -87,7 +87,7 @@ NsSocket.prototype.log = function (level, msg, meta, callback) {
}
self.emit('logged');
- callback && callback();
+ if (callback) callback(null, true);
});
};
74 test/winston-nssocket-test.js
View
@@ -8,6 +8,7 @@ var assert = require('assert'),
nssocket = require('nssocket'),
macros = require('./helpers/macros'),
ns = require('../'),
+ transport = require('winston/test/transports/transport'),
winstond = require('winstond');
//
@@ -26,73 +27,12 @@ server.add(winstond.transports.File, {
server.listen();
//
-// winston logger
+// test
//
-var logger = new winston.Logger({
- transports: [
- new ns.Nssocket({ host: 'localhost', port: 1234 })
- ]
-});
-
-//
-// tests
-//
-
-vows.describe('winston-nssocket').addBatch({
- 'When using `winston-nssocket`': {
- 'topic': logger,
- 'the log() method': {
- 'topic': function() {
- logger.log('info', 'hello world', {}, this.callback);
- },
- 'should respond with true': function (err, logged) {
- assert.isNull(err);
- assert.isNotNull(logged);
- }
- },
- 'the query() method': {
- 'topic': function (logger) {
- var cb = this.callback;
- logger.log('info', 'hello world', {});
- setTimeout(function () {
- logger.query({}, cb);
- }, 1000);
- },
- 'should return matching results': function (err, results) {
- results = results.nssocket.file;
- var log = results.pop();
- assert.ok(log.message.indexOf('hello world') === 0
- || log.message.indexOf('test message') === 0);
- }
- },
- 'the stream() method': {
- 'topic': function () {
- logger.log('info', 'hello world', {});
-
- var cb = this.callback,
- j = 10,
- i = 10,
- results = [],
- stream = logger.stream({});
-
- stream.on('log', function (log) {
- results.push(log);
- results.stream = stream;
- if (!--j) cb(null, results);
- });
-
- stream.on('error', function () {});
-
- while (i--) logger.log('info', 'hello world ' + i, {});
- },
- 'should stream logs': function (err, results) {
- results.forEach(function (log) {
- assert.ok(log.message.indexOf('hello world') === 0
- || log.message.indexOf('test message') === 0);
- });
- results.stream.destroy();
- }
- }
- }
+vows.describe('winston/transports/nssocket').addBatch({
+ 'An instance of the Nssocket Transport': transport(ns.Nssocket, {
+ host: 'localhost',
+ port: 1234
+ })
}).export(module);
Please sign in to comment.
Something went wrong with that request. Please try again.