Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Accept numbers and booleans in `withEnvironment`

Đang mở
#1,543 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

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ó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
65/100
Loại issue
Tính năng
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
docker, node.js, typescript
Lĩnh vực
testing, tooling

Hướng nghiên cứu

Read packages/testcontainers/src/types.ts and trace how Environment is consumed by the two withEnvironment methods and exec's env option. Check how subclasses access the protected environment field, then review the related issue #1519 because both changes rewrite withEnvironment. Done means accepting string, number, boolean, and undefined values while stored environment values remain strings and undefined keys are skipped.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

enhancement minor

What happens

Environment is { [key: string]: string }, so every non-string value has to be converted at the call site:

.withEnvironment({
  PORT: String(port),
  MAX_CONNECTIONS: maxConnections.toString(),
  DEBUG: "true",
})

Optional values need a conditional spread to avoid passing undefined:

.withEnvironment({ ...(token ? { TOKEN: token } : {}) })

The same type is used by DockerComposeEnvironment.withEnvironment and by exec's env option.

Expected

withEnvironment accepts string | number | boolean values and converts them, and skips keys whose value is undefined:

.withEnvironment({ PORT: port, DEBUG: true, TOKEN: token })

Where

  • Environment in packages/testcontainers/src/types.ts
  • withEnvironment in packages/testcontainers/src/generic-container/generic-container.ts
  • withEnvironment in packages/testcontainers/src/docker-compose-environment/docker-compose-environment.ts

Notes

  • Widening the accepted type is compatible for callers. Subclasses that read the protected environment field should keep seeing strings.
  • Related: #1519 (duplicate entries when a key is set twice).

Dependencies

  • Stack on #1519: both rewrite withEnvironment.
Ngôn ngữ chính
TypeScript
Star
2.6k
Fork
274
Merge trung bình
1 ngày 14 giờ
Pull request đã merge (30 ngày)
44

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của testcontainers/testcontainers-node

Tất cả issue của testcontainers/testcontainers-node

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.