serveStaticJson and serveStaticText failing default CORS tests in dev-middleware
还没有人认领这个 Issue。
- 主要语言
- C++
- 星标
- 127k
- 派生
- 25.3k
- 平均合并
- 1 天 23 小时
- 30 天内合并 PR
- 4
描述
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
- Clone the repository.
2 . Run: yarn jest packages/dev-middleware/src/tests/ServerUtils-test.js --runInBand --verbose
- 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
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 packages/dev-middleware/src/tests/ServerUtils-test.js 开始,并运行报告中的 Yarn Jest 命令。检查 serveStaticJson 和 serveStaticText,以确定缺失的 CORS 标头是否反映了预期的契约;完成的标准是测试和实现一致,并且目标测试文件通过。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript, react-native
- 领域
- devtools, testing-qa
- Issue 类型
- 缺陷
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 活跃度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 58/100