眠気.jl

投稿=不定期

WSL2でcypress起動した備忘録

背景

NextならCypressで簡単にテスト書けるよといぬねこ様に言われてチュートリやりました。
pages/にabout.tsx生やしてhome->aboutとURLが遷移するテスト実施しました。
ゲーミングOSであるWindows(Ubuntu20.04 on WSL2)でやろうとしたら詰まったのでメモ。

現象

Cypressに必要なライブラリ(https://docs.cypress.io/guides/getting-started/installing-cypress#System-requirements)全部入れても

Cypress verification timed out.
----------
Platform: linux-x64 (Ubuntu - 20.04)
Cypress Version: 9.4.1

解決法

こちらの方CypressをWSL2上で動かすために必要な作業を参考にして、 VcXsrvをインストール後

コントロール パネル\システムとセキュリティ\Windows Defender ファイアウォール\許可されたアプリ

を編集後

npm run cypress

で無事cypress/integration/app.spec.tsに書いてあるテスト実施できました 。
f:id:julialangisthebestlang:20220210180924p:plain
左上npm run dev
左下npm run cypress
右上npm run cypressで開くcypress画面,
右下cypressで遷移実行(Chrome), cypress画面化からapp.spec.tsをクリックすると開く
デフォルトがこのファイルで, 同階層に書き足していくようです。

dbusエラー消したい時(やらなくても動きます)

cypress起動するたびに

dbus[28048]: Unknown username "whoopsie" in message bus configuration file
dbus-daemon[28048]: Failed to start message bus: Failed to bind socket "/var/run/dbus/system_bus_socket": Address already in use

が出てましたが,whoopsie(Canonicalにバグレポート送る係)を無効化すれば上記のエラーでなくなりました。
次のファイルのenabled=0にしました。

❯ bat /etc/default/apport
───────┬────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: /etc/default/apport
───────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ # set this to 0 to disable apport, or to 1 to enable it
   2   │ # you can temporarily override this with
   3   │ # sudo service apport start force_start=1
   4   │ enabled=1

cypress verify times out on WSL2 · Issue #8119 · cypress-io/cypress · GitHub

投稿に従ってxvfb入れてDISPLAY無効化しても無理でした

終わりに

GUIのアプデが入ればこんなこと不要らしいので早く出してほしいと思う反面、ゲーム用OSにそんなに開発環境期待している自分は間違っているなという気にもなりました。

参考

next | Cypress Documentation

apport - What is the 'whoopsie' process and how can I remove it? - Ask Ubuntu