跳至主要內容

Web 平台測試

Deno 使用自訂測試執行器進行 Web 平台測試。它可以在 ./tools/wpt.ts 中找到。

執行測試

如果您使用的是 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

若要執行所有可用的網路平台測試,請執行下列命令

./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

測試執行器將執行每個網路平台測試並記錄其狀態(失敗或正常)。然後,它會將此輸出與 ./tools/wpt/expectation.json 檔案中指定的每個測試的預期輸出進行比較。此檔案是一個巢狀 JSON 結構,反映了 ./test_utils/wpt 目錄。它針對每個測試檔案說明它是否應該整體通過(所有測試通過,true),是否應該整體失敗(測試執行器在測試之外遇到例外或所有測試失敗,false),或它預期哪些測試會失敗(測試案例名稱的字串陣列)。

更新已啟用的測試或預期

您可以透過變更 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 應該會永遠通過。

子命令

setup

驗證您的環境是否正確設定,或協助您設定環境。

這會檢查 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

執行所有在 expectation.json 中指定的測試。

您可以指定下列旗標來自訂行為

--release
Use the ./target/release/deno binary instead of ./target/debug/deno

--quiet
Disable printing of `ok` test cases.

--json=<file>
Output the test results as JSON to the file specified.

您也可以在 -- 之後指定一個或多個篩選器,以明確指定要執行的測試。

./tools/wpt.ts run -- hr-time streams/piping/general

update

更新 expectation.json 以符合目前的實際情況。

您可以指定下列旗標來自訂行為

--release
Use the ./target/release/deno binary instead of ./target/debug/deno

--quiet
Disable printing of `ok` test cases.

--json=<file>
Output the test results as JSON to the file specified.

您也可以在 -- 之後指定一個或多個篩選器,以明確指定要執行的測試。

./tools/wpt.ts update -- hr-time streams/piping/general

常見問題

升級 wpt 子模組:

cd test_util/wpt/
git fetch origin
git checkout origin/epochs/daily
cd ../../
git add ./test_util/wpt

在此之後,所有貢獻者都需要重新執行 ./tools/wpt.ts setup

由於升級 WPT 通常需要更新預期值以涵蓋所有上游變更,因此最好將其作為一個獨立的公關,而不是作為實作修正或功能的公關的一部分。