-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from ReoHakase/44/add-e2e-tests
E2Eテストを追加した
- Loading branch information
Showing
11 changed files
with
230 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
name: E2E Test with Playwright (Turbo) | ||
|
||
on: | ||
- pull_request | ||
|
||
env: | ||
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} | ||
TURBO_TEAM: ${{ secrets.TURBO_TEAM }} | ||
RESAS_API_KEY: ${{ secrets.RESAS_API_KEY }} | ||
|
||
jobs: | ||
e2e-test: | ||
timeout-minutes: 40 | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup pnpm | ||
uses: moonrepo/setup-toolchain@v0 | ||
with: | ||
# A GitHub action that sets up an environment for proto and moon. | ||
# - Installs proto globally so that installed tools can also be executed globally. | ||
# - Caches the toolchain (~/.proto) so subsequent runs are faster. | ||
# - Hashes .prototools and .moon/toolchain.yml files to generate a unique cache key. | ||
# - Cleans the toolchain before caching to remove unused or stale tools. | ||
# See: https://github.com/moonrepo/setup-toolchain | ||
auto-install: true | ||
|
||
- name: Get pnpm Store | ||
id: pnpm-cache | ||
run: echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT | ||
|
||
- uses: actions/cache@v4 | ||
name: Setup pnpm Cache | ||
with: | ||
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }} | ||
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} | ||
restore-keys: ${{ runner.os }}-pnpm-store- | ||
|
||
- name: Install | ||
run: pnpm install --frozen-lockfile | ||
|
||
- name: Install Playwright with Dependencies | ||
run: pnpm playwright install --with-deps | ||
|
||
- name: Run E2E tests with Playwright and Turbo | ||
run: pnpm turbo playwright:test | ||
|
||
- uses: actions/upload-artifact@v4 | ||
if: ${{ !cancelled() }} | ||
with: | ||
name: playwright-report | ||
path: apps/web/playwright-report/ | ||
retention-days: 30 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { defineConfig, devices } from '@playwright/test'; | ||
|
||
export default defineConfig({ | ||
// Look for test files in the "tests" directory, relative to this configuration file. | ||
testDir: 'tests', | ||
|
||
// Run all tests in parallel. | ||
fullyParallel: true, | ||
|
||
// Fail the build on CI if you accidentally left test.only in the source code. | ||
forbidOnly: !!process.env.CI, | ||
|
||
// Retry on CI only. | ||
retries: process.env.CI ? 2 : 0, | ||
|
||
// Opt out of parallel tests on CI. | ||
workers: process.env.CI ? 1 : undefined, | ||
|
||
// Reporter to use | ||
reporter: 'html', | ||
|
||
use: { | ||
// Base URL to use in actions like `await page.goto('/')`. | ||
baseURL: 'http://127.0.0.1:3000', | ||
|
||
// Collect trace when retrying the failed test. | ||
trace: 'on-first-retry', | ||
}, | ||
// Configure projects for major browsers. | ||
projects: [ | ||
{ | ||
name: 'Chromium', | ||
use: { ...devices['Desktop Chrome'] }, | ||
}, | ||
], | ||
// Run your local dev server before starting the tests. | ||
webServer: { | ||
command: 'pnpm -F web start', | ||
url: 'http://127.0.0.1:3000', | ||
reuseExistingServer: !process.env.CI, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { test, expect } from '@playwright/test'; | ||
|
||
test('/', async ({ page }) => { | ||
// `/` ページにアクセス | ||
await page.goto('/'); | ||
|
||
const suggestionLinks = await page.locator('main nav a').all(); // 使用例の提案リンク | ||
const headerLinks = await page.locator('header *:not(nav) a').all(); // トップページへのアイコン型リンクとGitHubリンク | ||
const headerNavigationLinks = await page.locator('header nav a').all(); // 各人口統計ページへのリンク | ||
|
||
expect(suggestionLinks).toHaveLength(3); | ||
expect(headerLinks).toHaveLength(2); | ||
expect(headerNavigationLinks).toHaveLength(4); | ||
|
||
const suggestions = [ | ||
{ | ||
name: '四大都市圏の総人口はどのくらい?', | ||
title: '東京都、愛知県、大阪府、福岡県の総人口', | ||
}, | ||
{ | ||
name: '都市部と近郊の子供の数の違いは?', | ||
title: '茨城県、千葉県、東京都の年少人口', | ||
}, | ||
{ | ||
name: '北と南で総人口が多いのは?', | ||
title: '北海道、沖縄県の総人口', | ||
}, | ||
]; | ||
|
||
for (const { name, title } of suggestions) { | ||
const link = await page.locator(`main nav a`, { hasText: name }); | ||
await link.click(); | ||
await expect(page.locator('h1')).toHaveText(title); | ||
await page.goBack(); | ||
} | ||
|
||
const prefectures = { | ||
'1': '北海道', | ||
'8': '茨城県', | ||
'47': '沖縄県', | ||
}; | ||
|
||
for (const [prefCode] of Object.entries(prefectures)) { | ||
const checkbox = await page.locator(`input[type="checkbox"]#prefecture-${prefCode}`); | ||
await expect(checkbox).toBeTruthy(); | ||
const label = await page.locator(`label#prefecture-${prefCode}-label`); | ||
await label.click(); | ||
await expect(checkbox).toBeChecked(); | ||
await expect(page).toHaveURL(`/?prefCodes=${prefCode}`); | ||
await label.click(); | ||
await expect(checkbox).not.toBeChecked(); | ||
await expect(page).toHaveURL('/'); | ||
} | ||
}); | ||
|
||
test('/[statLabel]', async ({ page }) => { | ||
// `/all?prefCodes=13,23,27,40` ページにアクセス | ||
await page.goto('/all?prefCodes=13,23,27,40'); | ||
|
||
// 選択している都道府県の数を確認 | ||
const selectionStateLabel = await page.locator('h2#selection-state-label'); | ||
await expect(selectionStateLabel).toHaveText('4つの都道府県を選択中'); | ||
|
||
// グラフが表示されていることを確認 | ||
const chart = await page.locator('main div .recharts-wrapper'); | ||
await expect(chart).toBeVisible(); | ||
|
||
// グラフの線(都道府県)の数を確認 | ||
await page.waitForSelector('main div .recharts-surface .recharts-line-dots'); | ||
const lines = await page.locator('main div .recharts-surface .recharts-line-dots').all(); | ||
await expect(lines).toHaveLength(4); | ||
|
||
// グラフの線一つについて、データポイントの数を確認 | ||
await page.waitForSelector('main div .recharts-surface .recharts-line-dots circle'); | ||
const firstLineDots = await page.locator('main div .recharts-surface .recharts-line-dots circle').all(); | ||
await expect(firstLineDots.length).toBeGreaterThanOrEqual(18); // 1960年から2045年まで5年刻み | ||
|
||
// クリアボタンを押すと `/all` に遷移することを確認 | ||
const clearButton = await page.locator('#selection-state-label a', { hasText: 'クリア' }); | ||
await clearButton.click(); | ||
await expect(page).toHaveURL('/all'); | ||
}); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters