|
| 1 | +/** |
| 2 | + * Copyright(c) Microsoft Corporation.All rights reserved. |
| 3 | + * Licensed under the MIT License. |
| 4 | + */ |
| 5 | + |
| 6 | +const { ok } = require("assert"); |
| 7 | +const { ConsoleLogger } = require("../lib/logger"); |
| 8 | +const sandbox = require("sinon").createSandbox(); |
| 9 | +const logger = new ConsoleLogger(); |
| 10 | +const message = "Custom Message"; |
| 11 | +const command = "Custom Command"; |
| 12 | + |
| 13 | +describe("The logger", function () { |
| 14 | + beforeEach(function () { |
| 15 | + this.stubError = sandbox.spy(console, 'error'); |
| 16 | + this.stubMessage = sandbox.spy(console, 'log'); |
| 17 | + }); |
| 18 | + |
| 19 | + afterEach(function() { |
| 20 | + this.stubError.restore(); |
| 21 | + this.stubMessage.restore(); |
| 22 | + }); |
| 23 | + |
| 24 | + describe("should print", function(){ |
| 25 | + it("the custom error message", function() { |
| 26 | + logger.error(message); |
| 27 | + ok(this.stubError.called); |
| 28 | + ok(logger.isError); |
| 29 | + }); |
| 30 | + |
| 31 | + it("the custom informative message", function() { |
| 32 | + logger.message(message); |
| 33 | + ok(this.stubMessage.called); |
| 34 | + }); |
| 35 | + |
| 36 | + it("the custom success message", function() { |
| 37 | + logger.success(message); |
| 38 | + ok(this.stubMessage.called); |
| 39 | + }); |
| 40 | + |
| 41 | + it("the custom warning message", function() { |
| 42 | + logger.warning(message); |
| 43 | + ok(this.stubMessage.called); |
| 44 | + }); |
| 45 | + |
| 46 | + describe("the custom command message without verbose flag", function() { |
| 47 | + it("without verbose flag", function() { |
| 48 | + logger.isVerbose = undefined; |
| 49 | + logger.command(message, command); |
| 50 | + ok(this.stubMessage.called); |
| 51 | + }); |
| 52 | + |
| 53 | + it("with verbose flag", function() { |
| 54 | + logger.isVerbose = true; |
| 55 | + logger.command(message, command); |
| 56 | + ok(this.stubMessage.called); |
| 57 | + }); |
| 58 | + }); |
| 59 | + }); |
| 60 | +}); |
0 commit comments