From 08580e9e90dd30873da266b4ccda247694b9d087 Mon Sep 17 00:00:00 2001 From: Phred Date: Mon, 10 Jan 2022 20:15:26 -0600 Subject: [PATCH 1/9] cleaning up --- test/exception-handler.test.js | 31 ++++++++++++++----------------- test/helpers/index.js | 6 +----- test/rejection-handler.test.js | 31 ++++++++++++++----------------- 3 files changed, 29 insertions(+), 39 deletions(-) diff --git a/test/exception-handler.test.js b/test/exception-handler.test.js index 9a2286c7b..e89567e0d 100644 --- a/test/exception-handler.test.js +++ b/test/exception-handler.test.js @@ -6,7 +6,6 @@ * */ -const stream = require('stream'); const assume = require('assume'); const mocha = require('mocha'); const winston = require('../lib/winston'); @@ -38,6 +37,7 @@ describe('ExceptionHandler', function () { it('new ExceptionHandler()', function () { assume(function () { + // eslint-disable-next-line no-new new winston.ExceptionHandler(); }).throws(/Logger is required/); }); @@ -70,21 +70,18 @@ describe('ExceptionHandler', function () { it('.handle()', function (done) { var existing = helpers.clearExceptions(); - var writeable = new stream.Writable({ - objectMode: true, - write: function (info) { - assume(info).is.an('object'); - assume(info.error).is.an('error'); - assume(info.error.message).equals('wtf this error'); - assume(info.message).includes('uncaughtException: wtf this error'); - assume(info.stack).is.a('string'); - assume(info.process).is.an('object'); - assume(info.os).is.an('object'); - assume(info.trace).is.an('array'); - - existing.restore(); - done(); - } + var writeable = helpers.writeable(function (info) { + assume(info).is.an('object'); + assume(info.error).is.an('error'); + assume(info.error.message).equals('wtf this error'); + assume(info.message).includes('uncaughtException: wtf this error'); + assume(info.stack).is.a('string'); + assume(info.process).is.an('object'); + assume(info.os).is.an('object'); + assume(info.trace).is.an('array'); + + existing.restore(); + done(); }); var transport = new winston.transports.Stream({ stream: writeable }); @@ -93,7 +90,7 @@ describe('ExceptionHandler', function () { transports: [transport] }); - assume(handler.catcher).equals(undefined); + assume(handler.catcher).is.a('undefined'); transport.handleExceptions = true; handler.handle(); diff --git a/test/helpers/index.js b/test/helpers/index.js index fe51be9e3..447551d46 100644 --- a/test/helpers/index.js +++ b/test/helpers/index.js @@ -8,11 +8,9 @@ const assume = require('assume'), fs = require('fs'), - path = require('path'), through = require('through2'), spawn = require('child_process').spawn, stream = require('stream'), - util = require('util'), winston = require('../../lib/winston'), mockTransport = require('./mocks/mock-transport'); @@ -125,9 +123,7 @@ helpers.throw = function (msg) { * @param {String} msg Error mesage to use */ helpers.reject = function (msg) { - return new Promise((resolve, reject) => { - reject(msg); - }); + return Promise.reject(msg); }; /** diff --git a/test/rejection-handler.test.js b/test/rejection-handler.test.js index aef41b1aa..b65095f64 100644 --- a/test/rejection-handler.test.js +++ b/test/rejection-handler.test.js @@ -6,7 +6,6 @@ * */ -const stream = require('stream'); const assume = require('assume'); const mocha = require('mocha'); const winston = require('../lib/winston'); @@ -38,6 +37,7 @@ describe('UnhandledRejectionHandler', function () { it('new RejectionHandler()', function () { assume(function () { + // eslint-disable-next-line no-new new winston.RejectionHandler(); }).throws(/Logger is required/); }); @@ -70,21 +70,18 @@ describe('UnhandledRejectionHandler', function () { it('.handle()', function (done) { var existing = helpers.clearRejections(); - var writeable = new stream.Writable({ - objectMode: true, - write: function (info) { - assume(info).is.an('object'); - assume(info.error).is.an('error'); - assume(info.error.message).equals('wtf this rejection'); - assume(info.message).includes('unhandledRejection: wtf this rejection'); - assume(info.stack).is.a('string'); - assume(info.process).is.an('object'); - assume(info.os).is.an('object'); - assume(info.trace).is.an('array'); - - existing.restore(); - done(); - } + var writeable = helpers.writeable(function (info) { + assume(info).is.an('object'); + assume(info.error).is.an('error'); + assume(info.error.message).equals('wtf this rejection'); + assume(info.message).includes('unhandledRejection: wtf this rejection'); + assume(info.stack).is.a('string'); + assume(info.process).is.an('object'); + assume(info.os).is.an('object'); + assume(info.trace).is.an('array'); + + existing.restore(); + done(); }); var transport = new winston.transports.Stream({ stream: writeable }); @@ -93,7 +90,7 @@ describe('UnhandledRejectionHandler', function () { transports: [transport] }); - assume(handler.catcher).equals(undefined); + assume(handler.catcher).is.a('undefined'); transport.handleRejections = true; handler.handle(); From 072554b29e69cd74ae596501ac254b6531b6d9e5 Mon Sep 17 00:00:00 2001 From: Phred Date: Mon, 10 Jan 2022 20:16:17 -0600 Subject: [PATCH 2/9] added some debug --- test/rejection-handler.test.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test/rejection-handler.test.js b/test/rejection-handler.test.js index b65095f64..c98cf4ba8 100644 --- a/test/rejection-handler.test.js +++ b/test/rejection-handler.test.js @@ -71,6 +71,7 @@ describe('UnhandledRejectionHandler', function () { it('.handle()', function (done) { var existing = helpers.clearRejections(); var writeable = helpers.writeable(function (info) { + console.log('in writeable', info); assume(info).is.an('object'); assume(info.error).is.an('error'); assume(info.error.message).equals('wtf this rejection'); @@ -100,7 +101,14 @@ describe('UnhandledRejectionHandler', function () { handler.catcher ]); - helpers.reject('wtf this rejection').then(done()); + const meh = (e) => console.log('my handler', e); + process.on('unhandledRejection', meh); + assume(process.listeners('unhandledRejection')).deep.equals([ + handler.catcher, + meh + ]); + + process.emit('unhandledRejection', helpers.reject('wtf this rejection')); }); it('.getAllInfo(undefined)', function () { From 0723048acd7b485b381b949dc31c54d8197cae91 Mon Sep 17 00:00:00 2001 From: Phred Date: Tue, 11 Jan 2022 10:35:01 -0600 Subject: [PATCH 3/9] fixed typo --- test/helpers/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/helpers/index.js b/test/helpers/index.js index 447551d46..7d68c086b 100644 --- a/test/helpers/index.js +++ b/test/helpers/index.js @@ -98,7 +98,7 @@ helpers.clearExceptions = function () { */ helpers.clearRejections = function () { var listeners = process.listeners('unhandledRejection'); - process.removeAllListeners('unhandledRejections'); + process.removeAllListeners('unhandledRejection'); return { restore: function () { From 264350b195a726755816f7d4bbeaa37f77c6ca98 Mon Sep 17 00:00:00 2001 From: Phred Date: Tue, 11 Jan 2022 10:42:20 -0600 Subject: [PATCH 4/9] refactored tests to show they are almost identical --- test/exception-handler.test.js | 111 +++------------------------- test/helpers/handlers.js | 119 ++++++++++++++++++++++++++++++ test/rejection-handler.test.js | 128 ++++----------------------------- 3 files changed, 144 insertions(+), 214 deletions(-) create mode 100644 test/helpers/handlers.js diff --git a/test/exception-handler.test.js b/test/exception-handler.test.js index e89567e0d..a491fb1a2 100644 --- a/test/exception-handler.test.js +++ b/test/exception-handler.test.js @@ -6,108 +6,19 @@ * */ -const assume = require('assume'); -const mocha = require('mocha'); -const winston = require('../lib/winston'); +const baseHandlerTests = require('./helpers/handlers'); const helpers = require('./helpers'); -// -// This is an awful and fragile hack that -// needs to be changed ASAP. -// https://github.com/mochajs/mocha/issues/1985 -// -var _runTest = mocha.Runner.prototype.runTest; -mocha.Runner.prototype.runTest = function () { - this.allowUncaught = true; - _runTest.apply(this, arguments); -}; - describe('ExceptionHandler', function () { - this.timeout(5000); - - it('has expected methods', function () { - var handler = helpers.exceptionHandler(); - assume(handler.handle).is.a('function'); - assume(handler.unhandle).is.a('function'); - assume(handler.getAllInfo).is.a('function'); - assume(handler.getProcessInfo).is.a('function'); - assume(handler.getOsInfo).is.a('function'); - assume(handler.getTrace).is.a('function'); - }); - - it('new ExceptionHandler()', function () { - assume(function () { - // eslint-disable-next-line no-new - new winston.ExceptionHandler(); - }).throws(/Logger is required/); - }); - - it('new ExceptionHandler(logger)', function () { - var logger = winston.createLogger(); - var handler = new winston.ExceptionHandler(logger); - assume(handler.logger).equals(logger); - }); - - it('.getProcessInfo()', function () { - var handler = helpers.exceptionHandler(); - helpers.assertProcessInfo(handler.getProcessInfo()); - }); - - it('.getOsInfo()', function () { - var handler = helpers.exceptionHandler(); - helpers.assertOsInfo(handler.getOsInfo()); - }); - - it('.getTrace(new Error)', function () { - var handler = helpers.exceptionHandler(); - helpers.assertTrace(handler.getTrace(new Error())); - }); - - it('.getTrace()', function () { - var handler = helpers.exceptionHandler(); - helpers.assertTrace(handler.getTrace()); - }); - - it('.handle()', function (done) { - var existing = helpers.clearExceptions(); - var writeable = helpers.writeable(function (info) { - assume(info).is.an('object'); - assume(info.error).is.an('error'); - assume(info.error.message).equals('wtf this error'); - assume(info.message).includes('uncaughtException: wtf this error'); - assume(info.stack).is.a('string'); - assume(info.process).is.an('object'); - assume(info.os).is.an('object'); - assume(info.trace).is.an('array'); - - existing.restore(); - done(); - }); - - var transport = new winston.transports.Stream({ stream: writeable }); - var handler = helpers.exceptionHandler({ - exitOnError: false, - transports: [transport] - }); - - assume(handler.catcher).is.a('undefined'); - - transport.handleExceptions = true; - handler.handle(); - - assume(handler.catcher).is.a('function'); - assume(process.listeners('uncaughtException')).deep.equals([ - handler.catcher - ]); - - helpers.throw('wtf this error'); - }); - - after(function () { - // - // Restore normal `runTest` functionality - // so that we only affect the current suite. - // - mocha.Runner.prototype.runTest = _runTest; + this.timeout(100); + + baseHandlerTests({ + name: 'ExceptionHandler', + helper: 'exceptionHandler', + getAllInfo: new Error('catpants'), + setup: 'clearExceptions', + listener: 'uncaughtException', + toggleSetting: 'handleExceptions', + trigger: msg => helpers.throw(msg) }); }); diff --git a/test/helpers/handlers.js b/test/helpers/handlers.js new file mode 100644 index 000000000..7c37b05f4 --- /dev/null +++ b/test/helpers/handlers.js @@ -0,0 +1,119 @@ +const assume = require('assume'); +const mocha = require('mocha'); + +const helpers = require('.'); +const winston = require('../../lib/winston'); + +module.exports = function ({ getAllInfo, helper, listener, name, setup, toggleSetting, trigger }) { + before(function () { + /* + * This is an awful and fragile hack that + * needs to be changed ASAP. + * https://github.com/mochajs/mocha/issues/1985 + */ + var _runTest = this.originalRunTest = mocha.Runner.prototype.runTest; + + mocha.Runner.prototype.runTest = function () { + this.allowUncaught = true; + _runTest.apply(this, arguments); + }; + }); + + after(function () { + mocha.Runner.prototype.runTest = this.originalRunTest; + }); + + it('has expected methods', function () { + var handler = helpers[helper](); + assume(handler.handle).is.a('function'); + assume(handler.unhandle).is.a('function'); + assume(handler.getAllInfo).is.a('function'); + assume(handler.getProcessInfo).is.a('function'); + assume(handler.getOsInfo).is.a('function'); + assume(handler.getTrace).is.a('function'); + }); + + it(`new ${name}()`, function () { + assume(function () { + // eslint-disable-next-line no-new + new winston[name](); + }).throws(/Logger is required/); + }); + + it(`new ${name}(logger)`, function () { + var logger = winston.createLogger(); + var handler = new winston[name](logger); + assume(handler.logger).equals(logger); + }); + + it('.getProcessInfo()', function () { + var handler = helpers[helper](); + helpers.assertProcessInfo(handler.getProcessInfo()); + }); + + it('.getOsInfo()', function () { + var handler = helpers[helper](); + helpers.assertOsInfo(handler.getOsInfo()); + }); + + it('.getTrace(new Error)', function () { + var handler = helpers[helper](); + helpers.assertTrace(handler.getTrace(new Error())); + }); + + it('.getTrace()', function () { + var handler = helpers[helper](); + helpers.assertTrace(handler.getTrace()); + }); + + it('.getAllInfo(undefined)', function () { + var handler = helpers[helper](); + // eslint-disable-next-line no-undefined + handler.getAllInfo(getAllInfo); + }); + + describe('when error case is triggered', function () { + beforeEach(function () { + this.listeners = helpers[setup](); + }); + + afterEach(function () { + this.listeners.restore(); + }); + + it('.handle()', function (done) { + var msg = new Date().toString(); + var writeable = helpers.writeable(function (info) { + console.log('in writeable', info); + assume(info).is.an('object'); + assume(info.error).is.an('error'); + assume(info.error.message).equals(msg); + assume(info.message).includes(`${listener}: ${msg}`); + assume(info.stack).is.a('string'); + assume(info.process).is.an('object'); + assume(info.os).is.an('object'); + assume(info.trace).is.an('array'); + + done(); + }); + + var transport = new winston.transports.Stream({ stream: writeable }); + var handler = helpers[helper]({ + exitOnError: false, + transports: [transport] + }); + + assume(handler.catcher).is.a('undefined'); + + transport[toggleSetting] = true; + handler.handle(); + + assume(handler.catcher).is.a('function'); + assume(process.listeners(listener)).deep.equals([ + handler.catcher + ]); + + trigger(msg); + }); + }); +}; diff --git a/test/rejection-handler.test.js b/test/rejection-handler.test.js index c98cf4ba8..0672533b7 100644 --- a/test/rejection-handler.test.js +++ b/test/rejection-handler.test.js @@ -6,122 +6,22 @@ * */ -const assume = require('assume'); -const mocha = require('mocha'); -const winston = require('../lib/winston'); -const helpers = require('./helpers'); -// -// This is an awful and fragile hack that -// needs to be changed ASAP. -// https://github.com/mochajs/mocha/issues/1985 -// -var _runTest = mocha.Runner.prototype.runTest; -mocha.Runner.prototype.runTest = function () { - this.allowUncaught = true; - _runTest.apply(this, arguments); -}; +const baseHandlerTests = require('./helpers/handlers'); +const helpers = require('./helpers'); describe('UnhandledRejectionHandler', function () { - this.timeout(5000); - - it('has expected methods', function () { - var handler = helpers.rejectionHandler(); - assume(handler.handle).is.a('function'); - assume(handler.unhandle).is.a('function'); - assume(handler.getAllInfo).is.a('function'); - assume(handler.getProcessInfo).is.a('function'); - assume(handler.getOsInfo).is.a('function'); - assume(handler.getTrace).is.a('function'); - }); - - it('new RejectionHandler()', function () { - assume(function () { - // eslint-disable-next-line no-new - new winston.RejectionHandler(); - }).throws(/Logger is required/); - }); - - it('new RejectionHandler(logger)', function () { - var logger = winston.createLogger(); - var handler = new winston.RejectionHandler(logger); - assume(handler.logger).equals(logger); - }); - - it('.getProcessInfo()', function () { - var handler = helpers.rejectionHandler(); - helpers.assertProcessInfo(handler.getProcessInfo()); - }); - - it('.getOsInfo()', function () { - var handler = helpers.rejectionHandler(); - helpers.assertOsInfo(handler.getOsInfo()); - }); - - it('.getTrace(new Error)', function () { - var handler = helpers.rejectionHandler(); - helpers.assertTrace(handler.getTrace(new Error())); - }); - - it('.getTrace()', function () { - var handler = helpers.rejectionHandler(); - helpers.assertTrace(handler.getTrace()); - }); - - it('.handle()', function (done) { - var existing = helpers.clearRejections(); - var writeable = helpers.writeable(function (info) { - console.log('in writeable', info); - assume(info).is.an('object'); - assume(info.error).is.an('error'); - assume(info.error.message).equals('wtf this rejection'); - assume(info.message).includes('unhandledRejection: wtf this rejection'); - assume(info.stack).is.a('string'); - assume(info.process).is.an('object'); - assume(info.os).is.an('object'); - assume(info.trace).is.an('array'); - - existing.restore(); - done(); - }); - - var transport = new winston.transports.Stream({ stream: writeable }); - var handler = helpers.rejectionHandler({ - exitOnError: false, - transports: [transport] - }); - - assume(handler.catcher).is.a('undefined'); - - transport.handleRejections = true; - handler.handle(); - - assume(handler.catcher).is.a('function'); - assume(process.listeners('unhandledRejection')).deep.equals([ - handler.catcher - ]); - - const meh = (e) => console.log('my handler', e); - process.on('unhandledRejection', meh); - assume(process.listeners('unhandledRejection')).deep.equals([ - handler.catcher, - meh - ]); - - process.emit('unhandledRejection', helpers.reject('wtf this rejection')); - }); - - it('.getAllInfo(undefined)', function () { - var handler = helpers.rejectionHandler(); - // eslint-disable-next-line no-undefined - handler.getAllInfo(undefined); - }); - - after(function () { - // - // Restore normal `runTest` functionality - // so that we only affect the current suite. - // - mocha.Runner.prototype.runTest = _runTest; + this.timeout(100); + + baseHandlerTests({ + name: 'RejectionHandler', + helper: 'rejectionHandler', + setup: 'clearRejections', + listener: 'unhandledRejection', + toggleSetting: 'handleRejections', + trigger(msg) { + process.on('unhandledRejection', (e, p) => console.log('my handler is called', e, p)) + process.emit('unhandledRejection', msg, helpers.reject(msg)); + } }); }); From 4af5b1ce7860ac94d10bdedfdea6bd934a0363e5 Mon Sep 17 00:00:00 2001 From: Phred Date: Sun, 11 Aug 2024 12:38:19 -0500 Subject: [PATCH 5/9] fixed rejection trigger --- test/helpers/handlers.js | 82 +++++++++++---------- test/unit/winston/rejection-handler.test.js | 5 +- 2 files changed, 43 insertions(+), 44 deletions(-) diff --git a/test/helpers/handlers.js b/test/helpers/handlers.js index 7c37b05f4..5e3a9bb4c 100644 --- a/test/helpers/handlers.js +++ b/test/helpers/handlers.js @@ -23,53 +23,55 @@ module.exports = function ({ getAllInfo, helper, listener, name, setup, toggleSe mocha.Runner.prototype.runTest = this.originalRunTest; }); - it('has expected methods', function () { - var handler = helpers[helper](); - assume(handler.handle).is.a('function'); - assume(handler.unhandle).is.a('function'); - assume(handler.getAllInfo).is.a('function'); - assume(handler.getProcessInfo).is.a('function'); - assume(handler.getOsInfo).is.a('function'); - assume(handler.getTrace).is.a('function'); - }); + describe('basics', function () { + var handler; - it(`new ${name}()`, function () { - assume(function () { - // eslint-disable-next-line no-new - new winston[name](); - }).throws(/Logger is required/); - }); + beforeEach(function () { + handler = helpers[helper](); + }); - it(`new ${name}(logger)`, function () { - var logger = winston.createLogger(); - var handler = new winston[name](logger); - assume(handler.logger).equals(logger); - }); + it('has expected methods', function () { + assume(handler.handle).is.a('function'); + assume(handler.unhandle).is.a('function'); + assume(handler.getAllInfo).is.a('function'); + assume(handler.getProcessInfo).is.a('function'); + assume(handler.getOsInfo).is.a('function'); + assume(handler.getTrace).is.a('function'); + }); - it('.getProcessInfo()', function () { - var handler = helpers[helper](); - helpers.assertProcessInfo(handler.getProcessInfo()); - }); + it(`new ${name}()`, function () { + assume(function () { + // eslint-disable-next-line no-new + new winston[name](); + }).throws(/Logger is required/); + }); - it('.getOsInfo()', function () { - var handler = helpers[helper](); - helpers.assertOsInfo(handler.getOsInfo()); - }); + it(`new ${name}(logger)`, function () { + var logger = winston.createLogger(); + var handler_ = new winston[name](logger); + assume(handler_.logger).equals(logger); + }); - it('.getTrace(new Error)', function () { - var handler = helpers[helper](); - helpers.assertTrace(handler.getTrace(new Error())); - }); + it('.getProcessInfo()', function () { + helpers.assertProcessInfo(handler.getProcessInfo()); + }); - it('.getTrace()', function () { - var handler = helpers[helper](); - helpers.assertTrace(handler.getTrace()); - }); + it('.getOsInfo()', function () { + helpers.assertOsInfo(handler.getOsInfo()); + }); - it('.getAllInfo(undefined)', function () { - var handler = helpers[helper](); - // eslint-disable-next-line no-undefined - handler.getAllInfo(getAllInfo); + it('.getTrace(new Error)', function () { + helpers.assertTrace(handler.getTrace(new Error())); + }); + + it('.getTrace()', function () { + helpers.assertTrace(handler.getTrace()); + }); + + it('.getAllInfo(undefined)', function () { + // eslint-disable-next-line no-undefined + handler.getAllInfo(getAllInfo); + }); }); describe('when error case is triggered', function () { diff --git a/test/unit/winston/rejection-handler.test.js b/test/unit/winston/rejection-handler.test.js index e3593418b..d56af4e93 100644 --- a/test/unit/winston/rejection-handler.test.js +++ b/test/unit/winston/rejection-handler.test.js @@ -18,9 +18,6 @@ describe('UnhandledRejectionHandler', function () { setup: 'clearRejections', listener: 'unhandledRejection', toggleSetting: 'handleRejections', - trigger(msg) { - process.on('unhandledRejection', (e, p) => console.log('my handler is called', e, p)); - process.emit('unhandledRejection', msg, helpers.reject(msg)); - } + trigger: msg => helpers.reject(new Error(msg)) }); }); From f8d7c7b076eca6057f4cccaf852c93ebbb3af0e6 Mon Sep 17 00:00:00 2001 From: Phred Date: Sun, 11 Aug 2024 12:40:29 -0500 Subject: [PATCH 6/9] removed debug code --- test/helpers/handlers.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/helpers/handlers.js b/test/helpers/handlers.js index 5e3a9bb4c..f2a7c82b8 100644 --- a/test/helpers/handlers.js +++ b/test/helpers/handlers.js @@ -42,7 +42,7 @@ module.exports = function ({ getAllInfo, helper, listener, name, setup, toggleSe it(`new ${name}()`, function () { assume(function () { // eslint-disable-next-line no-new - new winston[name](); + new winston[name](); }).throws(/Logger is required/); }); @@ -86,7 +86,6 @@ module.exports = function ({ getAllInfo, helper, listener, name, setup, toggleSe it('.handle()', function (done) { var msg = new Date().toString(); var writeable = helpers.writeable(function (info) { - console.log('in writeable', info); assume(info).is.an('object'); assume(info.error).is.an('error'); assume(info.error.message).equals(msg); From 4fcf9ab8765fb61a3cfcc525fbc7156659f47329 Mon Sep 17 00:00:00 2001 From: Phred Date: Sun, 11 Aug 2024 13:00:49 -0500 Subject: [PATCH 7/9] cleaning up --- test/unit/winston/exception-handler.test.js | 3 +-- test/unit/winston/rejection-handler.test.js | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/test/unit/winston/exception-handler.test.js b/test/unit/winston/exception-handler.test.js index 9e5c0f434..e10e7cd84 100644 --- a/test/unit/winston/exception-handler.test.js +++ b/test/unit/winston/exception-handler.test.js @@ -6,7 +6,7 @@ * */ -const baseHandlerTests = require('../../helpers/handlers'); +const baseHandlerTests = require('../../helpers/handler-tests'); const helpers = require('../../helpers'); describe('ExceptionHandler', function () { @@ -15,7 +15,6 @@ describe('ExceptionHandler', function () { baseHandlerTests({ name: 'ExceptionHandler', helper: 'exceptionHandler', - getAllInfo: new Error('catpants'), setup: 'clearExceptions', listener: 'uncaughtException', toggleSetting: 'handleExceptions', diff --git a/test/unit/winston/rejection-handler.test.js b/test/unit/winston/rejection-handler.test.js index d56af4e93..40049d88f 100644 --- a/test/unit/winston/rejection-handler.test.js +++ b/test/unit/winston/rejection-handler.test.js @@ -6,7 +6,7 @@ * */ -const baseHandlerTests = require('../../helpers/handlers'); +const baseHandlerTests = require('../../helpers/handler-tests'); const helpers = require('../../helpers'); describe('UnhandledRejectionHandler', function () { From cb41aa9c738ba165f1957d8822419691bce14712 Mon Sep 17 00:00:00 2001 From: Phred Date: Sun, 11 Aug 2024 13:12:31 -0500 Subject: [PATCH 8/9] replaced hack with Mocha setting --- .mocharc.yml | 1 + .../helpers/{handlers.js => handler-tests.js} | 22 ++----------------- 2 files changed, 3 insertions(+), 20 deletions(-) rename test/helpers/{handlers.js => handler-tests.js} (81%) diff --git a/.mocharc.yml b/.mocharc.yml index 2d4ed8a59..458b14f26 100644 --- a/.mocharc.yml +++ b/.mocharc.yml @@ -1,3 +1,4 @@ +allow-uncaught: true exclude: - test/helpers/scripts/*.js exit: true diff --git a/test/helpers/handlers.js b/test/helpers/handler-tests.js similarity index 81% rename from test/helpers/handlers.js rename to test/helpers/handler-tests.js index f2a7c82b8..6986b0307 100644 --- a/test/helpers/handlers.js +++ b/test/helpers/handler-tests.js @@ -4,25 +4,7 @@ const mocha = require('mocha'); const helpers = require('.'); const winston = require('../../lib/winston'); -module.exports = function ({ getAllInfo, helper, listener, name, setup, toggleSetting, trigger }) { - before(function () { - /* - * This is an awful and fragile hack that - * needs to be changed ASAP. - * https://github.com/mochajs/mocha/issues/1985 - */ - var _runTest = this.originalRunTest = mocha.Runner.prototype.runTest; - - mocha.Runner.prototype.runTest = function () { - this.allowUncaught = true; - _runTest.apply(this, arguments); - }; - }); - - after(function () { - mocha.Runner.prototype.runTest = this.originalRunTest; - }); - +module.exports = function ({ helper, listener, name, setup, toggleSetting, trigger }) { describe('basics', function () { var handler; @@ -70,7 +52,7 @@ module.exports = function ({ getAllInfo, helper, listener, name, setup, toggleSe it('.getAllInfo(undefined)', function () { // eslint-disable-next-line no-undefined - handler.getAllInfo(getAllInfo); + handler.getAllInfo(undefined); }); }); From ef3c00c9ea19aeef474204f6ec80f4471d8bd19a Mon Sep 17 00:00:00 2001 From: Phred Date: Sun, 11 Aug 2024 13:18:54 -0500 Subject: [PATCH 9/9] removed unreferenced variable --- test/helpers/handler-tests.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/helpers/handler-tests.js b/test/helpers/handler-tests.js index 6986b0307..8dbfeeb98 100644 --- a/test/helpers/handler-tests.js +++ b/test/helpers/handler-tests.js @@ -1,5 +1,4 @@ const assume = require('assume'); -const mocha = require('mocha'); const helpers = require('.'); const winston = require('../../lib/winston');