Repository: pactumjs/pactum
Pull request #69 (2021-05-29 10:01:46)

issue #68 add new log level silent in logger.js
Update
- logger.js
- settings.d.js
- logger.spec.js


Patch:
diff --git a/src/exports/logger.js b/src/exports/logger.js
index 3cc0261..53f4e52 100644
--- a/src/exports/logger.js
+++ b/src/exports/logger.js
@@ -1,10 +1,12 @@
 const { options, magenta, blue, green, yellow, red } = require('../helpers/colors');
 
+const LEVEL_VERBOSE = 2;
 const LEVEL_TRACE = 3;
 const LEVEL_DEBUG = 4;
 const LEVEL_INFO = 5;
 const LEVEL_WARN = 6;
 const LEVEL_ERROR = 7;
+const LEVEL_SILENT = 8;
 
 /**
  * returns log level value
@@ -23,6 +25,10 @@ function getLevelValue(level) {
       return LEVEL_WARN;
     case 'ERROR':
       return LEVEL_ERROR;
+    case 'SILENT':
+      return LEVEL_SILENT;
+    case 'VERBOSE':
+      return LEVEL_VERBOSE;
     default:
       return LEVEL_INFO;
   }
@@ -104,4 +110,4 @@ module.exports = {
   set(lgr) {
     this.logger = lgr;
   }
-};
\ No newline at end of file
+};
diff --git a/src/exports/settings.d.ts b/src/exports/settings.d.ts
index 8554a7f..495f3f7 100644
--- a/src/exports/settings.d.ts
+++ b/src/exports/settings.d.ts
@@ -1,4 +1,4 @@
-export type LogLevel = 'TRACE'|'DEBUG'|'INFO'|'WARN'|'ERROR';
+export type LogLevel = 'VERBOSE'|'TRACE'|'DEBUG'|'INFO'|'WARN'|'ERROR'|'SILENT';
 
 /**
   * sets log level


Test patch:
diff --git a/test/unit/logger.spec.js b/test/unit/logger.spec.js
index 3fdb0b8..fa6aee3 100644
--- a/test/unit/logger.spec.js
+++ b/test/unit/logger.spec.js
@@ -11,6 +11,40 @@ describe('Logger', () => {
     this.errorStub = sandbox.stub(console, 'error');
     this.writeStub = sandbox.stub(process.stdout, 'write');
   });
+  
+  it('verbose', () => {
+    logger.setLevel('VERBOSE');
+    logger.trace('demo');
+    expect(this.writeStub.callCount).equals(1);
+    expect(this.debugStub.callCount).equals(1);
+    expect(this.infoStub.callCount).equals(0);
+    expect(this.warnStub.callCount).equals(0);
+    expect(this.errorStub.callCount).equals(0);
+    logger.debug('demo');
+    expect(this.writeStub.callCount).equals(2);
+    expect(this.debugStub.callCount).equals(2);
+    expect(this.infoStub.callCount).equals(0);
+    expect(this.warnStub.callCount).equals(0);
+    expect(this.errorStub.callCount).equals(0);
+    logger.info('demo');
+    expect(this.writeStub.callCount).equals(3);
+    expect(this.debugStub.callCount).equals(2);
+    expect(this.infoStub.callCount).equals(1);
+    expect(this.warnStub.callCount).equals(0);
+    expect(this.errorStub.callCount).equals(0);
+    logger.warn('demo');
+    expect(this.writeStub.callCount).equals(4);
+    expect(this.debugStub.callCount).equals(2);
+    expect(this.infoStub.callCount).equals(1);
+    expect(this.warnStub.callCount).equals(1);
+    expect(this.errorStub.callCount).equals(0);
+    logger.error('demo');
+    expect(this.writeStub.callCount).equals(5);
+    expect(this.debugStub.callCount).equals(2);
+    expect(this.infoStub.callCount).equals(1);
+    expect(this.warnStub.callCount).equals(1);
+    expect(this.errorStub.callCount).equals(1);
+  });
 
   it('trace', () => {
     logger.setLevel('TRACE');
@@ -182,6 +216,40 @@ describe('Logger', () => {
     expect(this.errorStub.callCount).equals(1);
   });
 
+  it('silent', () => {
+    logger.setLevel('SILENT');
+    logger.trace('demo');
+    expect(this.writeStub.callCount).equals(0);
+    expect(this.debugStub.callCount).equals(0);
+    expect(this.infoStub.callCount).equals(0);
+    expect(this.warnStub.callCount).equals(0);
+    expect(this.errorStub.callCount).equals(0);
+    logger.debug('demo');
+    expect(this.writeStub.callCount).equals(0);
+    expect(this.debugStub.callCount).equals(0);
+    expect(this.infoStub.callCount).equals(0);
+    expect(this.warnStub.callCount).equals(0);
+    expect(this.errorStub.callCount).equals(0);
+    logger.info('demo');
+    expect(this.writeStub.callCount).equals(0);
+    expect(this.debugStub.callCount).equals(0);
+    expect(this.infoStub.callCount).equals(0);
+    expect(this.warnStub.callCount).equals(0);
+    expect(this.errorStub.callCount).equals(0);
+    logger.warn('demo');
+    expect(this.writeStub.callCount).equals(0);
+    expect(this.debugStub.callCount).equals(0);
+    expect(this.infoStub.callCount).equals(0);
+    expect(this.warnStub.callCount).equals(0);
+    expect(this.errorStub.callCount).equals(0);
+    logger.error('demo');
+    expect(this.writeStub.callCount).equals(0);
+    expect(this.debugStub.callCount).equals(0);
+    expect(this.infoStub.callCount).equals(0);
+    expect(this.warnStub.callCount).equals(0);
+    expect(this.errorStub.callCount).equals(0);
+  });
+
   afterEach(() => {
     sandbox.restore();
   });
@@ -190,4 +258,4 @@ describe('Logger', () => {
     logger.setLevel('INFO');
   });
 
-});
\ No newline at end of file
+});