react / react/react-native

serveStaticJson and serveStaticText failing default CORS tests in dev-middleware

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

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

Needs: Triage :mag:
Ngôn ngữ chính
C++
Star
127k
Fork
25.3k
Merge trung bình
1 ngày 23 giờ
Pull request đã merge (30 ngày)
4

Mô tả

Description

During the development of the dev-middleware package, the automated tests for serveStaticJson and serveStaticText fail because they expect default Access-Control-Allow-Origin headers in the response. The current implementation no longer includes these headers by default.

This causes test failures even though the main functionality of serving JSON or text works correctly.

Steps to reproduce
  1. Clone the repository.

2 . Run: yarn jest packages/dev-middleware/src/tests/ServerUtils-test.js --runInBand --verbose

  1. Observe that the tests for serveStaticJson and serveStaticText fail due to missing CORS headers.

Expected behavior:
Tests should pass or be updated to reflect the current implementation.

Actual behavior:
Tests fail because the response does not include "Access-Control-Allow-Origin": "*" as previously expected.

React Native Version

0.82.1

Affected Platforms

Build - MacOS

Output of npx @react-native-community/cli info
System:
  OS: macOS 14.1.1
  CPU: (10) arm64 Apple M1 Max
  Memory: 417.81 MB / 64.00 GB
  Shell: 5.9 - /bin/zsh
Binaries:
  Node: 22.14.0
  Yarn: 1.22.22
  npm: 10.9.4
SDKs:
  iOS SDK: 17A400
  Android SDK: 33
npmPackages:
  react: 19.1.1
  react-native: 0.82.1
Stacktrace or Logs
FAIL  packages/dev-middleware/src/__tests__/ServerUtils-test.js
  ServerUtils
    ✕ serveStaticJson sets CORS header (285 ms)
    ✕ serveStaticText sets CORS header
    ✓ baseUrlForServer returns correct URL (1 ms)

  ● ServerUtils › serveStaticJson sets CORS header
    expect(jest.fn()).toHaveBeenCalledWith(...expected)
    Expected: 200, ObjectContaining {"Access-Control-Allow-Origin": "*", "Content-Type": "application/json"}
    Received: 200, {"Content-Type": "application/json"}

  ● ServerUtils › serveStaticText sets CORS header
    expect(jest.fn()).toHaveBeenCalledWith(...expected)
    Expected: 200, ObjectContaining {"Access-Control-Allow-Origin": "*", "Content-Type": "text/plain"}
    Received: 200, {"Content-Type": "text/plain"}
MANDATORY Reproducer

https://github.com/THE-Amrit-mahto-05/react-native-dev-middleware-repo.git

Screenshots and Videos

https://github.com/user-attachments/assets/bbec821b-f0a8-42a3-be58-a17fdceabf08

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 với packages/dev-middleware/src/tests/ServerUtils-test.js và chạy lệnh Yarn Jest đã được báo cáo. Kiểm tra serveStaticJson và serveStaticText để xác định liệu header CORS bị thiếu có phản ánh contract dự kiến hay không; hoàn tất có nghĩa là các test và implementation thống nhất với nhau, đồng thời file test được chỉ định chạy thành công.

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, react-native
Lĩnh vực
devtools, testing-qa
Loại issue
Lỗi
Độ khó
2/5
Thời gian dự kiến
1-3 giờ
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
58/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.