Mock Redis server for Node unit tests.
Requires Node version 5.7.0 or higher for the newest language features.
I created this project to help unit test an application that I was writing that used Redis for caching. I didn't want to stub out my client library code since I felt that would not be reliable enough, and I didn't want to get to functional/integration tests and find that my code was broken. I wanted to support sentinel and clustering, and couldn't find something that I felt would work, so I wrote this POS.
Call the start method after creating a new instance of the RedisServer class. This method returns an ES6 promise.
constRedisServer=require('redmock');letredisServer=newRedisServer();redisServer.start().then((res)=>{// Server is now up}).catch((err)=>{// Deal with error});Call the stop method. This method returns an ES6 promise. You do not have to worry about catching errors from this method.
redisServer.stop().then((res)=>{// Server is now stopped});// require/import needed crapdescribe('SomeTestSpec',()=>{letredisServer,underTest;// Start the serverbefore((done)=>{redisServer=newRedisServer();redisServer.start().then((res)=>{done();}).catch((err)=>{done(err);});});// Stop the serverafter((done)=>{redisServer.stop().then((res)=>{done();});});describe('#somemethod()',()=>{beforeEach(()=>{underTest=newUnderTest();});it('should test it',()=>{returnunderTest.somemethod().should.eventually.equal(true);});});});