Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

serveStaticJson and serveStaticText failing default CORS tests in dev-middleware

未关闭
#54,523 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
58/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
冷清
技术栈
javascript, react-native

调研方向

从 packages/dev-middleware/src/tests/ServerUtils-test.js 开始,并运行报告中的 Yarn Jest 命令。检查 serveStaticJson 和 serveStaticText,以确定缺失的 CORS 标头是否反映了预期的契约;完成的标准是测试和实现一致,并且目标测试文件通过。

由索引模型根据 Issue 内容生成。

描述

Needs: Triage :mag:
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

主要语言
C++
星标
127k
派生
25.3k
PR 合并指标
30 天内没有已合并 PR

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

react/react-native 的其他 Issue

查看 react/react-native 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。