Skip to content

Commit

Permalink
add test to verify standard trnsport functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaspeklak committed Feb 24, 2013
1 parent d3200b1 commit 176d254
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
6 changes: 3 additions & 3 deletions index.js
Expand Up @@ -2,7 +2,6 @@

var util = require("util");
var os = require("os");
var email = require("emailjs");
var winston = require("winston");
var _ = require("underscore");

Expand Down Expand Up @@ -42,6 +41,9 @@ var NodeMailer = function (options) {
this.handleExceptions = options.handleExceptions || false;
};

/** @extends winston.Transport */
util.inherits(NodeMailer, winston.Transport);

NodeMailer.prototype.log = function (level, msg, meta, callback) {
var self = this;
if (this.silent) return callback(null, true);
Expand All @@ -63,8 +65,6 @@ NodeMailer.prototype.log = function (level, msg, meta, callback) {
});
};

/** @extends winston.Transport */
util.inherits(NodeMailer, winston.Transport);

winston.transports.NodeMailer = NodeMailer;

Expand Down
7 changes: 4 additions & 3 deletions package.json
Expand Up @@ -4,7 +4,7 @@
"description": "An email transport layer for winston",
"main": "index.js",
"scripts": {
"test": "mocha"
"test": "vows test/*-test.js --spec"
},
"repository": "",
"keywords": [
Expand All @@ -13,10 +13,11 @@
"email"
],
"dependencies" : {
"underscore" : "1.4.x"
},
"devDependencies" : {
"mocha" : "*",
"should" : "*"
"winston" : "0.6.x",
"vows" : "*"
},
"peerDependencies" : {
"nodemailer" : "0.3.x",
Expand Down
36 changes: 36 additions & 0 deletions test/winston-nodemailer-test.js
@@ -0,0 +1,36 @@
"use strict";

var vows = require("vows");
var assert = require("assert");
var winston = require("winston");
var helpers = require("winston/test/helpers");
var NodeMailer = require("../index.js");

function assertMail(transport) {
assert.instanceOf(transport, NodeMailer);
assert.isFunction(transport.log);
}

var called = false;
var nodeMailerTransport = {
sendMail: function (optoins, cb) {
called = true;
cb(null);
}
};

var transport = new (NodeMailer)({ to: "test.@test.xx", from: "dev@server.com", transport: nodeMailerTransport });

vows.describe("winston-mail").addBatch({
"An instance of the NodeMailer Transport": {
"should have the proper methods defined": function () {
assertMail(transport);
},
"the log() method": helpers.testNpmLevels(transport,
"should log messages to NodeMailer", function (ign, err, logged) {
assert.isTrue(!err);
assert.isTrue(logged);
assert.isTrue(called);
})
}
}).export(module);

0 comments on commit 176d254

Please sign in to comment.