Skip to content
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

✅test: add playwright #668

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Playwright Tests

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

on:
push:
branches: main
pull_request:
branches: main
workflow_dispatch:

jobs:
test:
timeout-minutes: 30
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
ref: ${{ env.SHA }}
env:
SHA: ${{ github.event.pull_request.head.sha || github.sha }}

- name: Install bun
uses: oven-sh/setup-bun@v2
with:
bun-version: canary

- name: Install dependencies
run: bun i

- name: Build app
run: bun run build

- name: Install Playwright Browsers
run: bunx playwright install --with-deps

- name: Run Playwright tests
run: bunx playwright test

- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: playwright-report
path: playwright-report/
retention-days: 30
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
!.yarn/versions

# testing
/blob-report/
/coverage
/playwright/.cache/
/playwright-report/
/test-results/

# next.js
/.next/
Expand Down
2 changes: 1 addition & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"recommendations": ["biomejs.biome"]
"recommendations": ["biomejs.biome", "ms-playwright.playwright"]
}
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"devDependencies": {
"@biomejs/biome": "^1.9.4",
"@happy-dom/global-registrator": "^15.7.4",
"@playwright/test": "next",
"@testing-library/dom": "^10.4.0",
"@testing-library/react": "^16.0.1",
"@types/bun": "^1.1.12",
Expand Down
79 changes: 79 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { defineConfig, devices } from "@playwright/test"

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// import dotenv from 'dotenv';
// import path from 'path';
// dotenv.config({ path: path.resolve(__dirname, '.env') });

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({

Check warning on line 14 in playwright.config.ts

View workflow job for this annotation

GitHub Actions / quality

lint/style/noDefaultExport

Avoid default exports.
testDir: "./test/e2e",
/* Run tests in files 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. See https://playwright.dev/docs/test-reporters */
reporter: "html",
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
baseURL: "http://127.0.0.1:3000",

Check warning on line 29 in playwright.config.ts

View workflow job for this annotation

GitHub Actions / quality

lint/style/useNamingConvention

Two consecutive uppercase characters are not allowed in camelCase because strictCase is set to `true`.

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: "on-first-retry",
},

/* Configure projects for major browsers */
projects: [
{
name: "chromium",
use: { ...devices["Desktop Chrome"] },
},

{
name: "firefox",
use: { ...devices["Desktop Firefox"] },
},

{
name: "webkit",
use: { ...devices["Desktop Safari"] },
},

/* Test against mobile viewports. */
// {
// name: 'Mobile Chrome',
// use: { ...devices['Pixel 5'] },
// },
// {
// name: 'Mobile Safari',
// use: { ...devices['iPhone 12'] },
// },

/* Test against branded browsers. */
// {
// name: 'Microsoft Edge',
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
// },
// {
// name: 'Google Chrome',
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
// },
],

/* Run your local dev server before starting the tests */
webServer: {
command: "bun .next/standalone/server.js",
url: "http://127.0.0.1:3000",
reuseExistingServer: !process.env.CI,
},
})
File renamed without changes.
8 changes: 8 additions & 0 deletions test/e2e/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { expect, test } from "@playwright/test"

test("has title", async ({ page }) => {
await page.goto("/")

// Expect a title "to contain" a substring.
await expect(page).toHaveTitle(/ラズネージ/)

Check warning on line 7 in test/e2e/index.test.ts

View workflow job for this annotation

GitHub Actions / quality

lint/performance/useTopLevelRegex

This regex literal is not defined in the top level scope. This can lead to performance issues if this function is called frequently.
})
Loading