測試您的專案
現在,在編寫和建置程式碼之後,讓我們實際執行它!您可以使用以下指令執行測試
$ wasm-pack test --firefox
[INFO]: Checking for the Wasm target...
Finished dev [unoptimized + debuginfo] target(s) in 0.02s
Running target/wasm32-unknown-unknown/debug/deps/web-9e7d380f8600b08e.wasm
Interactive browsers tests are now available at http://127.0.0.1:8000
Note that interactive mode is enabled because `NO_HEADLESS`
is specified in the environment of this process. Once you're
done with testing you'll need to kill this server with
Ctrl-C.
主控台不會立即完成,但如指示所示,您可以在您的網頁瀏覽器中訪問 http://127.0.0.1:8000 以查看測試輸出
running 1 test
test web::pass ... ok
test result: ok. 1 passed; 0 failed; 0 ignored
我們現在已經在網頁瀏覽器中執行了我們的第一次測試!
如果您想在無頭網頁瀏覽器中執行測試(您不需要手動訪問頁面),您可以執行
$ wasm-pack test --headless --firefox
同樣地,如果您正在開發 Node.js 專案,您也可以執行 wasm-pack test --nodejs
以在 Node 中運行測試。
請務必查看 測試參考文件 以了解其他支援的功能!