mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 07:07:35 +01:00
fix tests that relied on different logger
This commit is contained in:
@@ -61,13 +61,15 @@ describe('emails', () => {
|
||||
sandbox.stub(logger, 'error');
|
||||
|
||||
let attachEmail = require(pathToEmailLib);
|
||||
attachEmail.send();
|
||||
let promise = attachEmail.send();
|
||||
expect(sendMailSpy).to.be.calledOnce;
|
||||
deferred.reject();
|
||||
deferred.promise.catch(() => {
|
||||
|
||||
// wait for unhandledRejection event to fire
|
||||
setTimeout(() => {
|
||||
expect(logger.error).to.be.calledOnce;
|
||||
done();
|
||||
});
|
||||
}, 20);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -153,11 +153,10 @@ describe('errorHandler', () => {
|
||||
errorHandler(error, req, res, next);
|
||||
|
||||
expect(logger.error).to.be.calledOnce;
|
||||
expect(logger.error).to.be.calledWithExactly(error.stack, {
|
||||
expect(logger.error).to.be.calledWithExactly(error, {
|
||||
originalUrl: req.originalUrl,
|
||||
headers: req.headers,
|
||||
body: req.body,
|
||||
fullError: error,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -21,19 +21,8 @@ if (IS_PROD) {
|
||||
});
|
||||
}
|
||||
|
||||
// Logs unhandled promises errors
|
||||
// when no catch is attached to a promise a unhandledRejection event will be triggered
|
||||
process.on('unhandledRejection', function handlePromiseRejection (reason, promise) {
|
||||
let stack = reason.stack || reason.message || reason;
|
||||
|
||||
logger.error(stack, {
|
||||
promise,
|
||||
fullError: reason,
|
||||
});
|
||||
});
|
||||
|
||||
// exports a public interface insteaf of accessing directly the logger module
|
||||
module.exports = {
|
||||
let loggerInterface = {
|
||||
info (...args) {
|
||||
logger.info(...args);
|
||||
},
|
||||
@@ -56,3 +45,13 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
// Logs unhandled promises errors
|
||||
// when no catch is attached to a promise a unhandledRejection event will be triggered
|
||||
process.on('unhandledRejection', function handlePromiseRejection (reason, promise) {
|
||||
loggerInterface.error(reason, {
|
||||
promise,
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = loggerInterface;
|
||||
|
||||
Reference in New Issue
Block a user