feat: Add require-again to help with unit testing

This commit is contained in:
Blade Barringer
2016-05-06 12:05:06 -05:00
parent 887aa478ec
commit 192488cb02
4 changed files with 20 additions and 29 deletions

View File

@@ -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,