Provide an official mocking library for mocking Node-Redis in Jest tests
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 45/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- node.js, redis, typescript
- Lĩnh vực
- testing
Hướng nghiên cứu
Bắt đầu với lib/redis-client.ts và lib/services/tests/area.spec.ts đang bị lỗi, sau đó so sánh cấu hình Jest trong package.json và jest.setup.redis-mock.js với API của client Redis v4. Được xem là hoàn tất khi một phương pháp mocking hoặc thư viện chính thức hỗ trợ cách sử dụng createClient, connect, duplicate và TypeScript/Jest như được trình bày mà không yêu cầu một dịch vụ Redis đang hoạt động.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Description
I am struggling to find a way to combine the modern Redis v4 client with the jest test framework.
This is my production code:
import redis from 'redis';
import config from './config';
import logger from './logger';
const redisClient = redis.createClient(config.redisConfig);
redisClient.on('error', (e) => logger.error(e));
(async () => {
await redisClient.connect();
})();
export type RedisClient = typeof redisClient;
export default async () => {
const clone = redisClient.duplicate();
await clone.connect();
return clone;
};
Some of my services of course use redis, and when I try to test them, the entire test suite usually fails at startup. This is a project that was migrated from plain JS to TS, from node-redis 3 to 4, and from mocha to jest.
Below are a few scenarios that don't work.
No config added:
FAIL lib/services/tests/area.spec.ts
● Test suite failed to run
TypeError: Cannot read properties of undefined (reading 'createClient')
4 |
> 5 | const redisClient = redis.createClient(config.redisConfig);
| ^
at Object.createClient (lib/redis-client.ts:5:27)
Using the documented scenario with redis-mock:
in package.json
"jest": {
"setupFilesAfterEnv": [
"./jest.setup.redis-mock.js"
]
},
in jest.setup.redis-mock.js
import {jest} from '@jest/globals';
jest.mock('redis', () => jest.requireActual('redis-mock'));
Gives the error:
FAIL lib/services/tests/area.spec.ts
TypeError: redisClient.connect is not a function
8 | (async () => {
> 9 | await redisClient.connect();
| ^
10 | })();
at connect (lib/redis-client.ts:9:21)
at asyncGeneratorStep (lib/redis-client.ts:3:31)
Messing around in the jest setup file usually ends up with the entire library being undefined, etc.
- Ngôn ngữ chính
- TypeScript
- Star
- 17.6k
- Fork
- 2k
- Merge trung bình
- 1 ngày 22 giờ
- Pull request đã merge (30 ngày)
- 62
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của redis/node-redis
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
redis/node-redis#3664 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
After a MOVING handoff, a client never becomes ready again on reconnectCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 68/100
redis/node-redis#3705 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
accepted Bug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 52/100
redis/node-redis#3674 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Support Uint8Array values for zero-copy transfer to worker_threadsCó thể đã có người làm @umeshmore45 đã nhận 286 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
redis/node-redis#3106 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
`RedisClientType` type is slow to typecheck (TS performance issue)Có thể làm lại được @nkaradzhov đã nhận 556 ngày trước và không có pull request nào đang mở. Đang mởBug
redis/node-redis#2975 · 30 bình luận · 27 reaction · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của redis/node-redis
Issue tương tự
-
dependencies effort: small good first issue priority: low
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100
TMHSDigital/screencast-mcp#509 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
from-review tech-debt testing
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
blamechris/chroxy#9520 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area:web complexity:S priority:P2 type:chore
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
nahuelcostac/agent-hub#104 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
snaglet-org/snaglet#78 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
agent/guide documentation help wanted stage/010-actionable
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
kubestellar/console-marketplace#1101 ·
Maintainer thường phản hồi trong vòng 1 ngày