From a3beb30bc116fddb45f0723a628594e9b3535fc4 Mon Sep 17 00:00:00 2001 From: qejk Date: Mon, 2 May 2016 19:33:05 +0200 Subject: [PATCH] Adds Space.logging.Winston module integration test --- package.js | 1 + tests/integration/module.integration.js | 66 +++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 tests/integration/module.integration.js diff --git a/package.js b/package.js index 637544a..f6b7990 100644 --- a/package.js +++ b/package.js @@ -38,6 +38,7 @@ Package.onTest(function(api) { api.add_files([ 'tests/unit/winston-adapter.unit.js', + 'tests/integration/module.integration.js', ], 'server'); }); \ No newline at end of file diff --git a/tests/integration/module.integration.js b/tests/integration/module.integration.js new file mode 100644 index 0000000..d17bd3e --- /dev/null +++ b/tests/integration/module.integration.js @@ -0,0 +1,66 @@ +describe("Space.logging.WinstonAdapter", function() { + + + beforeEach(function () { + this.winston = Npm.require('winston'); + testApp = Space.Application.extend('Test.App', { + configuration: {}, + requiredModules: ['Space.logging.Winston'], + }); + this.app = new testApp(); + this.app.start(); + }); + + it('adds instance of Space.Logger.WinstonAdapter to instance of Space.Logger', function() { + const log = this.app.injector.get('log'); + const adapter = log.adapter('winston'); + + expect(adapter).to.be.instanceof(Space.Logger.WinstonAdapter); + expect(adapter.lib()).to.be.instanceof(this.winston.Logger); + }); + + it('maps instance of Space.Logger.WinstonAdapter to Injector', function() { + expect( + this.app.injector.get('Space.Logger.WinstonAdapter') + ).to.be.instanceof(Space.Logger.WinstonAdapter); + }); + + describe('configuration', function () { + describe('transports', function () { + it('uses default winston.transports.Console when transports are not configured', function() { + const logger = this.app.injector.get('log'); + const adapter = logger.adapter('winston'); + + expect(adapter.hasTransport('console')).to.be.true; + }); + + it('overrides transports configuration', function() { + const options = { + colorize: false, + json: true, + level: 'error' + } + const testApp = Space.Application.extend('Test.App', { + configuration: { + log: { + enabled: true, + winston: { + transports: [new this.winston.transports.Console(options)] + } + } + }, + requiredModules: ['Space.logging.Winston'], + }); + const app = new testApp(); + app.start(); + + const log = app.injector.get('log'); + const adapter = log.adapter('winston'); + const consoleTransport = adapter.transport('console'); + + expect(consoleTransport).to.include(options); + }); + }); + }); + +}); \ No newline at end of file