`I.waitForFile` (FileSystem helper) fails if directory does not exist (yet)

Đang mở Phù hợp với người mới
#5,420 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

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

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
72/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
javascript, nodejs
Lĩnh vực
testing

Hướng nghiên cứu

Bắt đầu trong lib/helper/FileSystem.js tại isFileExists và theo dõi cách I.waitForFile xử lý thư mục cha bị thiếu cùng việc dọn dẹp timeout của nó. Xác nhận hành vi bằng phần coverage hiện có của helper FileSystem nếu có; được xem là hoàn tất khi thao tác chờ không ném exception dù thư mục ban đầu không tồn tại và vẫn phát hiện tệp ngay khi tệp xuất hiện.

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

Mô tả

stale

I.waitForFile sometimes fails and throws weird exceptions if the directory containing the expected file does not exist yet.

Example (all output goes to ${codecept_dir}/output/):

  I.handleDownloads('downloads/example.txt');
  I.click('button.download');
  I.amInPath('output/downloads');
  I.waitForFile('example.txt', 5);

If the directory ${codecept_dir}/output/downloads does not exist yet (it will be created by the browser download at some point in time), the function I.waitForFile will throw an exception ReferenceError: Cannot access 'watcher' before initialization and the test will fail.

Root cause is in the function isFileExists of the FileSystem helper. The line const watcher = fs.watch(dir, (eventType, filename) => {... will throw if dir does not exist yet. This exception remains unhandled. Later, the timer for the 5sec timeout detection will try to close the uninitialized watcher, leading to the ReferenceError.

I will try to create a PR.

Ngôn ngữ chính
JavaScript
Star
4.2k
Fork
756
Merge trung bình
2 ngày 9 giờ
Pull request đã merge (30 ngày)
16

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.

Issue khác của codeceptjs/CodeceptJS

Tất cả issue của codeceptjs/CodeceptJS

Issue tương tự

Thêm issue về JavaScript

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.