Web 平台测试
Deno 使用自定义的 Web 平台测试运行器。它可以在 ./tools/wpt.ts
中找到。
运行测试 Jump to heading
如果您在 Windows 上,或者您的系统不支持 hashbang,请在所有
./tools/wpt.ts
命令前加上deno run --unstable --allow-write --allow-read --allow-net --allow-env --allow-run
。
在首次尝试运行 WPT 测试之前,请先运行 WPT 设置。每次更新 ./test_util/wpt
子模块时,您也必须运行此命令
./tools/wpt.ts setup
要运行所有可用的 web 平台测试,请运行以下命令
./tools/wpt.ts run
# You can also filter which test files to run by specifying filters:
./tools/wpt.ts run -- streams/piping/general hr-time
测试运行器将运行每个 web 平台测试并记录其状态(失败或成功)。然后,它会将此输出与 ./tools/wpt/expectation.json
文件中指定的每个测试的预期输出进行比较。此文件是一个嵌套的 JSON 结构,它镜像了 ./test_utils/wpt
目录。它描述了对于每个测试文件,它是否应该作为一个整体通过(所有测试通过,true
),它是否应该作为一个整体失败(测试运行器在测试之外遇到异常或所有测试都失败,false
),或者它期望哪些测试失败(测试用例名称的字符串数组)。
更新启用的测试或期望 Jump to heading
您可以通过更改 JSON 结构中每个测试文件条目的值来手动更新 ./tools/wpt/expectation.json
文件。另一种也是首选的方法是让 WPT 运行器运行所有测试或经过筛选的测试子集,然后自动更新 expectation.json
文件以匹配当前实际情况。您可以使用 ./wpt.ts update
命令来执行此操作。例如
./tools/wpt.ts update -- hr-time
运行此命令后,expectation.json
文件将匹配所有已运行测试的当前输出。这意味着在 wpt.ts update
之后立即运行 wpt.ts run
应该始终通过。
子命令 Jump to heading
setup
Jump to heading
验证您的环境配置是否正确,或帮助您配置环境。
这将检查 python3 (或 Windows 上的 python.exe
) 实际上是 Python 3。
您可以指定以下标志来自定义行为
--rebuild
Rebuild the manifest instead of downloading. This can take up to 3 minutes.
--auto-config
Automatically configure /etc/hosts if it is not configured (no prompt will be shown).
run
Jump to heading
像 expectation.json
中指定的那样运行所有测试。
您可以指定以下标志来自定义行为
--release
Use the ./target/release/deno binary instead of ./target/debug/deno
--quiet
Disable printing of `ok` test cases.
--json=
Output the test results as JSON to the file specified.
您还可以通过在 --
之后指定一个或多个过滤器来精确指定要运行的测试。
./tools/wpt.ts run -- hr-time streams/piping/general
update
Jump to heading
更新 expectation.json
以匹配当前实际情况。
您可以指定以下标志来自定义行为
--release
Use the ./target/release/deno binary instead of ./target/debug/deno
--quiet
Disable printing of `ok` test cases.
--json=
Output the test results as JSON to the file specified.
您还可以通过在 --
之后指定一个或多个过滤器来精确指定要运行的测试。
./tools/wpt.ts update -- hr-time streams/piping/general
FAQ Jump to heading
升级 wpt 子模块: Jump to heading
cd test_util/wpt/
git fetch origin
git checkout origin/epochs/daily
cd ../../
git add ./test_util/wpt
所有贡献者在此之后都需要重新运行 ./tools/wpt.ts setup
。
由于升级 WPT 通常需要更新期望以涵盖各种上游更改,因此最好将其作为单独的 PR 进行,而不是作为实现修复或功能的 PR 的一部分。