本文档涵盖了 Deno 的 Node.js 兼容性测试系统,该系统通过运行实际的 Node.js 测试套件来验证 Deno 的 Node.js 兼容性层。该系统包括测试配置、执行、报告和持续集成组件。
有关 Node.js API polyfills 本身的信息,请参阅 Node.js API Polyfills。有关 NPM 包集成,请参阅 NPM 集成。
Node.js 兼容性测试系统通过针对 Deno 的运行时执行官方 Node.js 测试套件来验证 Deno 运行 Node.js 代码的能力。该系统旨在跟踪兼容性进展并识别回归。
来源: tests/node_compat/config.jsonc1-177 tests/node_compat/run_all_test_unmodified.ts1-432 ext/node/polyfills/internal/buffer.mjs1-100
兼容性测试系统采用集中式配置方法,用于管理哪些 Node.js 测试应在不同平台上执行、忽略或以不同方式处理。
config.jsonc 文件是主要的配置文件,其结构如下:
| 配置节 | 目的 | 示例 |
|---|---|---|
ignore | 永不运行的测试 | 与 Deno 架构不兼容的测试 |
tests | 应执行的测试 | 核心功能测试 |
windowsIgnore | Windows 特定的测试排除项 | 特定于平台的故障 |
darwinIgnore | macOS 特定的测试排除项 | 特定于平台的故障 |
来源: tests/node_compat/config.jsonc2-177 tests/node_compat/common.ts59-66
该系统通过条件测试执行来处理平台差异。
来源: tests/node_compat/config.jsonc27-29 tests/node_compat/common.ts31-33
测试执行系统在 Deno 的运行时上运行 Node.js 测试,并捕获结果以供分析。
来源: tests/node_compat/run_all_test_unmodified.ts159-227 tests/node_compat/common.ts61-66
该系统根据测试需求配置 Deno 执行。
| 参数 | 来源 | 目的 |
|---|---|---|
RUN_ARGS | tests/node_compat/common.ts134-140 | 标准 Deno 脚本执行标志 |
TEST_ARGS | tests/node_compat/common.ts142-147 | 用于 node:test 模块测试的 Deno 测试标志 |
| V8 标志 | 来自测试文件的 parseFlags() | 测试特定的 V8 配置 |
| Node 选项 | 环境变量 | Node.js 兼容性设置 |
来源: tests/node_compat/common.ts211-216 tests/node_compat/run_all_test_unmodified.ts126-152 tests/node_compat/common.ts129-132
该测试系统会生成全面的报告,用于跟踪兼容性进展和识别问题。
来源: tests/node_compat/run_all_test_unmodified.ts31-46 tests/node_compat/run_all_test_unmodified.ts110-124
该系统将测试执行结果转化为结构化报告。
| 阶段 | 功能 | 输出 |
|---|---|---|
| 测试执行 | runSingle() | NodeTestFileReport |
| 结果转换 | transformReportsIntoResults() | Record<string, SingleResult> |
| 报告组装 | writeTestReport() | 完整的 TestReport JSON |
| 上传 | CI 工作流 | 将压缩的报告上传到云存储 |
来源: tests/node_compat/run_all_test_unmodified.ts229-252 tests/node_compat/run_all_test_unmodified.ts254-281
CI 系统跨多个平台运行兼容性测试,并发布结果以监控兼容性趋势。
来源: .github/workflows/node_compat_test.yml1-89 tests/node_compat/add_day_summary_to_month_summary.ts113-134
该系统生成聚合摘要,用于跟踪长期兼容性趋势。
来源: tests/node_compat/add_day_summary_to_month_summary.ts58-69 tests/node_compat/slack.ts21-34 tests/node_compat/slack.ts50-101
该系统将测试结果分类为特定状态以进行跟踪。
| 结果类型 | 枚举值 | 含义 |
|---|---|---|
| 通过 | NodeTestFileResult.PASS | 测试成功执行 |
| 失败 | NodeTestFileResult.FAIL | 测试因错误而失败 |
| 跳过 | NodeTestFileResult.SKIP | 测试被过滤(调试) |
| 忽略 | NodeTestFileResult.IGNORED | 测试被故意排除 |
来源: tests/node_compat/run_all_test_unmodified.ts91-96 tests/node_compat/run_all_test_unmodified.ts364-396