Skip to content

Commit

Permalink
set up redis testcontainert instead of redis-mock
Browse files Browse the repository at this point in the history
  • Loading branch information
e11sy committed Dec 25, 2024
1 parent 1322621 commit 6b0455d
Show file tree
Hide file tree
Showing 3 changed files with 256 additions and 17 deletions.
25 changes: 23 additions & 2 deletions jest.setup.redis-mock.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
const { GenericContainer } = require('testcontainers');

let redisTestContainer;

/**
* Mock redis library
* Create test container with Redis, which could be used in tests
*/
jest.mock('redis', () => jest.requireActual('redis-mock'));
beforeAll(async () => {
redisTestContainer = await new GenericContainer('redis')
.withExposedPorts(6379)
.start();

const port = redisTestContainer.getMappedPort(6379);
const host = redisTestContainer.getContainerIpAddress();

/**
* Set environment variable for redisHelper to connect to redis container
*/
process.env.REDIS_URL = `redis://${host}:${port}`;
}
);

afterAll(async () => {
await redisTestContainer.stop();
});
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,17 @@
"typescript": "^3.8.3",
"uuid": "^8.3.0",
"winston": "^3.2.1",
"yup": "^0.28.5"
"yup": "^0.28.5",
"redis": "^4.7.0"
},
"devDependencies": {
"@shelf/jest-mongodb": "^1.2.3",
"testcontainers": "^3.0.0",
"eslint": "^7.14.0",
"eslint-config-codex": "^1.6.1",
"jest": "25.5.4",
"nodemon": "^2.0.3",
"random-words": "^1.1.1",
"redis-mock": "^0.56.3",
"ts-jest": "25.4.0",
"wait-for-expect": "^3.0.2",
"webpack": "^4.43.0",
Expand Down
Loading

0 comments on commit 6b0455d

Please sign in to comment.