菜单

兼容性测试

相关源文件

本文档涵盖了 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应执行的测试核心功能测试
windowsIgnoreWindows 特定的测试排除项特定于平台的故障
darwinIgnoremacOS 特定的测试排除项特定于平台的故障

测试分类流程

来源: 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_ARGStests/node_compat/common.ts134-140标准 Deno 脚本执行标志
TEST_ARGStests/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 系统跨多个平台运行兼容性测试,并发布结果以监控兼容性趋势。

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