mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 15:48:04 +01:00
feat: Add require-again to help with unit testing
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import winston from 'winston';
|
||||
import requireAgain from 'require-again';
|
||||
|
||||
/* eslint-disable global-require */
|
||||
describe('logger', () => {
|
||||
@@ -7,8 +8,6 @@ describe('logger', () => {
|
||||
let errorSpy;
|
||||
|
||||
beforeEach(() => {
|
||||
delete require.cache[require.resolve(pathToLoggerLib)];
|
||||
|
||||
infoSpy = sandbox.stub();
|
||||
errorSpy = sandbox.stub();
|
||||
sandbox.stub(winston, 'Logger').returns({
|
||||
@@ -22,7 +21,7 @@ describe('logger', () => {
|
||||
});
|
||||
|
||||
it('info', () => {
|
||||
let attachLogger = require(pathToLoggerLib);
|
||||
let attachLogger = requireAgain(pathToLoggerLib);
|
||||
attachLogger.info(1, 2, 3);
|
||||
expect(infoSpy).to.be.calledOnce;
|
||||
expect(infoSpy).to.be.calledWith(1, 2, 3);
|
||||
@@ -30,14 +29,14 @@ describe('logger', () => {
|
||||
|
||||
describe('error', () => {
|
||||
it('with custom arguments', () => {
|
||||
let attachLogger = require(pathToLoggerLib);
|
||||
let attachLogger = requireAgain(pathToLoggerLib);
|
||||
attachLogger.error(1, 2, 3, 4);
|
||||
expect(errorSpy).to.be.calledOnce;
|
||||
expect(errorSpy).to.be.calledWith(1, 2, 3, 4);
|
||||
});
|
||||
|
||||
it('with error', () => {
|
||||
let attachLogger = require(pathToLoggerLib);
|
||||
let attachLogger = requireAgain(pathToLoggerLib);
|
||||
let errInstance = new Error('An error.');
|
||||
attachLogger.error(errInstance, {
|
||||
data: 1,
|
||||
|
||||
Reference in New Issue
Block a user