nodejs / nodejs/node

test_runner: support mock file system

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

Chưa có ai nhận issue này.

feature request fs test_runner
Ngôn ngữ chính
JavaScript
Star
122k
Fork
37.4k
Merge trung bình
4 ngày 2 giờ
Pull request đã merge (30 ngày)
283

Mô tả

What is the problem this feature will solve?

The current test requires writing files to a real disk when reading and writing files related to the file system, which is very unsafe.

After all, the file may remain due to test case failure and other reasons.

What is the feature you are proposing to solve the problem?

Under the mock namespace, APIs are exposed to provide a mock file system.

mock.fileSystem.enable({ });

And provide some options

e.g.

Override the file that defined by defaults

mock.fileSystem.enable({
  files: {
    '/path/to/file': new Uint8Array([0])
  }
});

// it will read the virtual file system first if it does exist
// if not found, then read the read the real file system
fs.readFileSync('/path/to/file')

Override the whole file system

mock.fileSystem.enable({
  files: {
    '/path/to/file': new Uint8Array([0])
  },
  override: true // override the whole file system
});

// This file is exists in the real file system
// But not define in the vitual file system, so it should throw an error
fs.readFileSync('/etc/proc')
What alternatives have you considered?

mock-fs

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

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.

Hướng nghiên cứu

Bắt đầu bằng việc xem xét namespace mock của test_runner và các API hệ thống tệp được mô tả trong issue. Xác định cách mock.fileSystem.enable xử lý các tệp đã cấu hình, fallback về hệ thống tệp thực và xử lý chế độ override; hoàn thành khi các hành vi này được cung cấp và được kiểm thử.

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

Đánh giá

Công nghệ
javascript, node.js
Lĩnh vực
operating-systems, testing-qa
Loại issue
Tính năng
Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
42/100

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.