|
| 1 | +"use strict"; |
| 2 | + |
| 3 | +const expect = require("chai").expect; |
| 4 | +const sinon = require("sinon"); |
| 5 | + |
| 6 | +const Logger = require("../../src/logger"); |
| 7 | + |
| 8 | +describe(`Logger`, function () { |
| 9 | + let sls, logOutput; |
| 10 | + |
| 11 | + beforeEach(function () { |
| 12 | + sls = { |
| 13 | + service: { |
| 14 | + service: "test-service", |
| 15 | + provider: { |
| 16 | + stage: "test", |
| 17 | + }, |
| 18 | + getAllFunctions: () => {}, |
| 19 | + getFunction: () => {}, |
| 20 | + }, |
| 21 | + version: "3.0.0", |
| 22 | + variables: { |
| 23 | + service: { |
| 24 | + custom: {}, |
| 25 | + }, |
| 26 | + }, |
| 27 | + configSchemaHandler: { |
| 28 | + defineFunctionEventProperties: () => {}, |
| 29 | + defineFunctionProperties: () => {}, |
| 30 | + defineCustomProperties: () => {}, |
| 31 | + }, |
| 32 | + classes: { |
| 33 | + Error: class ServerlessError { |
| 34 | + constructor(err) { |
| 35 | + return new Error(err); |
| 36 | + } |
| 37 | + }, |
| 38 | + }, |
| 39 | + processedInput: { |
| 40 | + options: { |
| 41 | + postmanCollection: "postman.json", |
| 42 | + }, |
| 43 | + }, |
| 44 | + }; |
| 45 | + |
| 46 | + logOutput = { |
| 47 | + log: { |
| 48 | + debug: (str) => {}, |
| 49 | + error: (str) => {}, |
| 50 | + info: (str) => {}, |
| 51 | + notice: (str) => {}, |
| 52 | + success: (str) => {}, |
| 53 | + verbose: (str) => {}, |
| 54 | + warning: (str) => {}, |
| 55 | + }, |
| 56 | + }; |
| 57 | + }); |
| 58 | + |
| 59 | + describe(`debug`, function () { |
| 60 | + it(`should log a debug log type when debug is called`, function () { |
| 61 | + const logger = new Logger(sls, logOutput.log); |
| 62 | + const spy = sinon.spy(logger, "log"); |
| 63 | + |
| 64 | + logger.debug("Testing"); |
| 65 | + |
| 66 | + expect(spy.called).to.be.true; |
| 67 | + |
| 68 | + spy.restore(); |
| 69 | + }); |
| 70 | + }); |
| 71 | + |
| 72 | + describe(`error`, function () { |
| 73 | + it(`should log a error log type when error is called`, function () { |
| 74 | + const logger = new Logger(sls, logOutput.log); |
| 75 | + const spy = sinon.spy(logger, "log"); |
| 76 | + |
| 77 | + logger.error("Testing"); |
| 78 | + |
| 79 | + expect(spy.called).to.be.true; |
| 80 | + |
| 81 | + spy.restore(); |
| 82 | + }); |
| 83 | + }); |
| 84 | + |
| 85 | + describe(`info`, function () { |
| 86 | + it(`should log a info log type when info is called`, function () { |
| 87 | + const logger = new Logger(sls, logOutput.log); |
| 88 | + const spy = sinon.spy(logger, "log"); |
| 89 | + |
| 90 | + logger.info("Testing"); |
| 91 | + |
| 92 | + expect(spy.called).to.be.true; |
| 93 | + |
| 94 | + spy.restore(); |
| 95 | + }); |
| 96 | + }); |
| 97 | + |
| 98 | + describe(`notice`, function () { |
| 99 | + it(`should log a notice log type when log is called without a log type`, function () { |
| 100 | + const logger = new Logger(sls, logOutput.log); |
| 101 | + const spy = sinon.spy(logger, "log"); |
| 102 | + |
| 103 | + logger.log("Testing"); |
| 104 | + |
| 105 | + expect(spy.called).to.be.true; |
| 106 | + |
| 107 | + spy.restore(); |
| 108 | + }); |
| 109 | + |
| 110 | + it(`should log a notice log type when notice is called`, function () { |
| 111 | + const logger = new Logger(sls, logOutput.log); |
| 112 | + const spy = sinon.spy(logger, "log"); |
| 113 | + |
| 114 | + logger.notice("Testing"); |
| 115 | + |
| 116 | + expect(spy.called).to.be.true; |
| 117 | + |
| 118 | + spy.restore(); |
| 119 | + }); |
| 120 | + }); |
| 121 | + |
| 122 | + describe(`success`, function () { |
| 123 | + it(`should log a success log type when success is called`, function () { |
| 124 | + const logger = new Logger(sls, logOutput.log); |
| 125 | + const spy = sinon.spy(logger, "log"); |
| 126 | + |
| 127 | + logger.success("Testing"); |
| 128 | + |
| 129 | + expect(spy.called).to.be.true; |
| 130 | + |
| 131 | + spy.restore(); |
| 132 | + }); |
| 133 | + }); |
| 134 | + |
| 135 | + describe(`verbose`, function () { |
| 136 | + it(`should log a verbose log type when verbose is called`, function () { |
| 137 | + const logger = new Logger(sls, logOutput.log); |
| 138 | + const spy = sinon.spy(logger, "log"); |
| 139 | + |
| 140 | + logger.verbose("Testing"); |
| 141 | + |
| 142 | + expect(spy.called).to.be.true; |
| 143 | + |
| 144 | + spy.restore(); |
| 145 | + }); |
| 146 | + }); |
| 147 | + |
| 148 | + describe(`warning`, function () { |
| 149 | + it(`should log a warning log type when warning is called`, function () { |
| 150 | + const logger = new Logger(sls, logOutput.log); |
| 151 | + const spy = sinon.spy(logger, "log"); |
| 152 | + |
| 153 | + logger.warning("Testing"); |
| 154 | + |
| 155 | + expect(spy.called).to.be.true; |
| 156 | + |
| 157 | + spy.restore(); |
| 158 | + }); |
| 159 | + }); |
| 160 | +}); |
0 commit comments