-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
はじめてのE2Eテストを作成する #42
はじめてのE2Eテストを作成する #42
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@komagata さん、 |
@kazuma-naka 僕はいい感じだと思います! |
承知しました! |
package.json
Outdated
@@ -14,6 +14,7 @@ | |||
"@supabase/supabase-js": "^2.47.3", | |||
"class-variance-authority": "^0.7.1", | |||
"clsx": "^2.1.1", | |||
"dotenv": "^16.4.7", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
これだとインストールパッケージに dotenv
が入りますが、
運用時に使わないのであれば、
代わりに devDependencies に dotenv-cli
を入れて
scripts
セクションに
"e2e": "dotenv -e .env.local -- playwright test",
で呼び出せると思います。
(スクリプト内の import
も不要になる)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@firewood さん、
レビューありがとうございます😊
dotenv
を削除dotenv-cli
を入れたのですが process.env.EMAIL
が not defined となりテストを実行することができませんでした。具体的には
npm run e2e は実行できましたが Playwright Test for VSCode を使用した際にエラーが出て実行できませんでした。
dotenv
を devDependencies
に移動する対応を今回したのですが dotenv-cli
を使用する方がよいでしょうか?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
なるほど、VSCodeから呼ぶときに困るんですね。
devDependencies + dotenv でも良いと思います!
55e48be
to
26b2dd2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@kazuma-naka コンフリクトの修正をお願いします。 |
26b2dd2
to
8622244
Compare
@komagata さん、 |
README.md
Outdated
EMAIL=Wikiのローカル環境ユーザーの Email を設定する | ||
PASSWORD=Wikiのローカル環境ユーザーの Pass を設定する |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
開発環境のPASSWORDなので隠さないで大丈夫です〜
package.json
Outdated
"test": "true", | ||
"e2e": "dotenv -e .env.local -- playwright test" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
npm run test
でE2Eテストも動くようにお願いします。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CI環境でも動くことになるのでヘッドレスブラウザで動くようにお願いします。
supabase-e2e-test 内で bash runE2Etest.sh で supabase を clone する URL: http://localhost:8000
a8b0d3f
to
43a43d8
Compare
@komagata さん、 お疲れ様です。 |
playwright.config.ts
Outdated
* Read environment variables from file. | ||
* https://github.com/motdotla/dotenv | ||
*/ | ||
console.log("Loaded ENV:", process.env); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(nit) デバッグ用なら消してもよいかもです
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
削除しました!
うまく動いているようです 👍 |
e2e/database.types.ts
Outdated
| { [key: string]: Json | undefined } | ||
| Json[] | ||
|
||
export type Database = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: モデルが二重管理になっていますが、このファイルって必要でしょうか?
src/lib/database.types をimportしてもテストは動作していそうです。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/libのほうをimportすると Type 'Database' does not satisfy the constraint 'GenericDatabase'.
というエラーになるんですが、もしかして型定義が古いためですか? このE2Eのほうをsrc/lib/の方で使えばよさそう
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
レビューありがとうございます😊
Supawright を使用するために Supabase の型のタイプを変更する必要がありました。
src/lib/databaase.types.ts に変更しました。
不必要なログを削除
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
大変なIssueお疲れ様です。
確認させて頂きました。OKです〜🙆♂️
#28
概要
ローカル環境のテストユーザーを使用してログイン、ログアウトをする。
2025年1月5日現在の問題
ログアウトをしても自動的に画面が更新されないため `await page.reload();` が必要となる。 しかし ` await page.waitForTimeout(1500);` を追加しないと flaky なテストとなる(ログアウトは非同期処理でログアウト前にリロードされてしまうため `Timeout` が必要)2025年1月13日(このPRで修正済み)
`login`と`signUp`ページ内のロゴ、`pjord.svg` の `height` が定義されておらずエラーが起こったので新たに高さを定義2025年1月16日 CI のテスト内で Supabase の立ち上げ、 Next.js のビルドと開始
E2E テストでログイン、ログアウトを行いヘッダーのボタンが変わるのかをテストするため実際に Supabase と Next.js を `ci.yml` の `test` 内で環境を構築しました。 [この記事](https://playwright.dev/docs/ci-intro)を参考に `ci.yml` を修正.env.local
をtest
のインスタンス内で動的に作成するnpm run build
をCI環境で実行したさいにsupabaseUrl is required.
のエラーが出ました。.env.local
はリモートに追加されないので supabase の url と anon key が定義されずビルドに失敗すると考えました。エラーが起こった個所にcreateClient()
が使用されていたため。npx supabase status の例
npx supabase status
の結果を代入する.env.local
を動的に作成してNEXT_PUBLIC_SUPABASE_URL=$API_URL
,NEXT_PUBLIC_SUPABASE_ANON_KEY=$ANON_KEY
で生成された URL と Anon Key を書き込む2025年 1月19日 テストCI環境でデータベースをE2Eテスト実行前、実行後にリセットする。
テスト環境のための seed.sql ファイル。
seed を使用する際にテーブルを初期化する
手順
npm init playwright@latest
コマンドを実行するe2e
に設定する3. テストユーザーの設定を.env.local
にEMAIL
とPASSWORD
を設定する。EMAIL と PASSWORD は WIKI のローカル環境のユーザーのものを記載する
login_then_logout.spec.ts
内に定義するこの動画を参考にしてテストを作成しました。
ログイン時
ログアウトのリンクが表示されているかチェックする。
ログアウト時
ログアウト後、リロードをしないと画面が更新されない
ログアウトボタンがクリックされて1.5秒待ちリロードする。
でないとリロードしてもログアウトの状態にならず flaky なテストとなる。
ログインのリンク、ユーザー登録のリンクが表示されているかチェックする。
Playwright の結果
Artifacts としてアップロードする
テスト環境ではseed.test.sql
を使用するテスト前とテスト後に以下のコマンドを実行して seed.test.sql を取り込む~~ ~~psql "postgres://postgres:postgres@localhost:54322/postgres" -f ~~~~./src/supabase/seed.test.sql~~ ~~
### E2Eテスト環境のためにユーザーを作成、テスト後にユーザーを削除するcreateClient().auth.signUp
でユーザーを新規登録後、email confirmation
が必要となりテストが失敗する。そのためcreateClient().auth.admin.createUser()
でユーザーを新規登録、email_confirm: true
にするSupawright を使用する
Supabase と Playwright を組み合わせた Supawright を使用してテスト用のユーザーをテスト前に作成、テスト後に作成したテストユーザーを自動的に削除してくれます。
README にある通りではうまく動かなかったので Issue で質問させて頂きました。