cocalc/src / smc-project / node_modules / forever / node_modules / winston / test / container-test.js
50659 views/*1* container-test.js: Tests for the Container object2*3* (C) 2011 Charlie Robbins4* MIT LICENSE5*6*/78var assert = require('assert'),9fs = require('fs'),10http = require('http'),11path = require('path'),12vows = require('vows'),13winston = require('../lib/winston'),14helpers = require('./helpers');1516vows.describe('winston/container').addBatch({17"An instance of winston.Container": {18topic: new winston.Container(),19"the add() method": {20topic: function (container) {21return container.add('default-test');22},23"should correctly instantiate a Logger": function (logger) {24assert.instanceOf(logger, winston.Logger);25},26"the get() method": {27topic: function (logger, container) {28this.callback.apply(this, arguments);29},30"should respond with the logger previously created": function (existing, container) {31var logger = container.get('default-test');32assert.isTrue(existing === logger);33}34},35"the has() method": {36topic: function (logger, container) {37this.callback.apply(this, arguments);38},39"should indicate `default-test` logger exists": function (existing, container) {40assert.isTrue(container.has('default-test'));41},42"should indicate `not-has` logger doesnt exists": function (existing, container) {43assert.isFalse(container.has('not-has'));44}45},46"the close() method": {47topic: function (logger, container) {48this.callback.apply(this, arguments);49},50"should remove the specified logger": function (logger, container) {51container.close('default-test');52assert.isTrue(!container.loggers['default-test']);53}54}55}56},57"An instance of winston.Container with explicit transports": {58topic: function () {59this.port = 9412;60this.transports = [61new winston.transports.Webhook({62port: this.port63})64];6566this.container = new winston.Container({67transports: this.transports68});6970return null;71},72"the get() method": {73topic: function (container) {74var server = http.createServer(function (req, res) {75res.end();76});7778server.listen(this.port, this.callback.bind(this, null));79},80"should add the logger correctly": function () {81this.someLogger = this.container.get('some-logger');82assert.isObject(this.someLogger.transports);83assert.instanceOf(this.someLogger.transports['webhook'], winston.transports.Webhook);84assert.strictEqual(this.someLogger.transports['webhook'], this.transports[0]);85},86"a second call to get()": {87"should respond with the same transport object": function () {88this.someOtherLogger = this.container.get('some-other-logger');8990assert.isObject(this.someOtherLogger.transports);91assert.instanceOf(this.someOtherLogger.transports['webhook'], winston.transports.Webhook);92assert.strictEqual(this.someOtherLogger.transports['webhook'], this.transports[0]);93assert.strictEqual(this.someOtherLogger.transports['webhook'], this.someLogger.transports['webhook']);94}95}96}97}98}).export(module);99100