Skip to content

Commit 068b8fe

Browse files
committed
feat: add Playwright for end-to-end testing and update configurations
1 parent abf6e33 commit 068b8fe

File tree

9 files changed

+188
-43
lines changed

9 files changed

+188
-43
lines changed

.github/workflows/build-lint-test.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ on:
1111
jobs:
1212
build:
1313
runs-on: ubuntu-latest
14+
timeout-minutes: 15
1415

1516
steps:
1617
- name: Checkout
@@ -21,7 +22,7 @@ jobs:
2122
- uses: pnpm/action-setup@v4
2223
name: Install pnpm
2324
with:
24-
version: 10.8.0
25+
version: 10
2526

2627
- name: Install Node.js
2728
uses: actions/setup-node@v4

apps/web/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
# testing
1414
/coverage
15+
/playwright-report
16+
/test-results
1517

1618
# next.js
1719
/.next/

apps/web/e2e/auth.spec.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { test, expect } from '@playwright/test';
2+
3+
// Generate random user data for test isolation
4+
function generateTestUser() {
5+
const randomId = Math.floor(Math.random() * 1000000);
6+
return {
7+
name: `test_user_${randomId}`,
8+
email: `test_user_${randomId}@example.com`,
9+
password: `Password123!${randomId}`,
10+
};
11+
}
12+
13+
test.describe('Authentication', () => {
14+
const testUser = generateTestUser();
15+
16+
test('should allow user registration', async ({ page }) => {
17+
// Navigate to registration page
18+
await page.goto('/register');
19+
20+
// Wait for the form to be visible
21+
await expect(
22+
page.getByRole('heading', { name: /register/i }),
23+
).toBeVisible();
24+
25+
// Fill out registration form
26+
await page.getByLabel(/name/i).fill(testUser.name);
27+
await page.getByLabel(/email/i).fill(testUser.email);
28+
await page.getByLabel(/^password$/i).fill(testUser.password);
29+
30+
// Submit form
31+
await page.locator('button[type="submit"]').click();
32+
33+
// Verify successful registration (redirect or success message)
34+
// This might vary based on your app flow, adjust as needed
35+
await expect(page).toHaveURL(/\/verify-email|\/dashboard/);
36+
});
37+
38+
test('should allow user login', async ({ page }) => {
39+
// Navigate to login page
40+
await page.goto('/login');
41+
42+
// Wait for the form to be visible
43+
await expect(page.getByRole('heading', { name: /login/i })).toBeVisible();
44+
45+
// Fill out login form with previously registered credentials
46+
await page.getByLabel(/email/i).fill(testUser.email);
47+
await page.getByLabel(/password/i).fill(testUser.password);
48+
49+
// Submit form
50+
await page.locator('button[type="submit"]').click();
51+
52+
await expect(page.getByText('Start Your Journey!')).toBeVisible();
53+
});
54+
});

apps/web/e2e/homepage.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { test, expect } from '@playwright/test';
2+
3+
test.describe('Homepage', () => {
4+
test('should load successfully', async ({ page }) => {
5+
await page.goto('/');
6+
await expect(page).toHaveTitle(/VitNode/);
7+
await expect(page.getByText('Start Your Journey!')).toBeVisible();
8+
});
9+
});

apps/web/package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313
"build": "next build --turbopack",
1414
"start": "next start",
1515
"lint": "eslint .",
16-
"lint:fix": "eslint . --fix"
16+
"lint:fix": "eslint . --fix",
17+
"test:e2e": "playwright test",
18+
"test:e2e:ui": "playwright test --ui",
19+
"test:e2e:debug": "playwright test --debug",
20+
"test:e2e:report": "playwright show-report"
1721
},
1822
"dependencies": {
1923
"@hono/zod-openapi": "^0.19.6",
@@ -37,6 +41,7 @@
3741
"zod": "^3.24.3"
3842
},
3943
"devDependencies": {
44+
"@playwright/test": "^1.52.0",
4045
"@tailwindcss/postcss": "^4.1.4",
4146
"@types/node": "^22.15.3",
4247
"@types/react": "^19.1.2",

apps/web/playwright.config.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { defineConfig, devices } from '@playwright/test';
2+
3+
/**
4+
* See https://playwright.dev/docs/test-configuration
5+
*/
6+
export default defineConfig({
7+
testDir: './e2e',
8+
fullyParallel: true,
9+
forbidOnly: !!process.env.CI,
10+
/* Maximum time one test can run for */
11+
timeout: 30 * 1000,
12+
/* Fail the build on CI if test failures */
13+
reporter: process.env.CI ? 'github' : 'html',
14+
/* Shared settings for all projects */
15+
use: {
16+
/* Base URL to use in actions like `await page.goto('/')` */
17+
baseURL: process.env.TEST_BASE_URL ?? 'http://localhost:3000',
18+
/* Collect trace when retrying the failed test */
19+
trace: 'on-first-retry',
20+
/* Take screenshots on failure */
21+
screenshot: 'only-on-failure',
22+
/* Record video on failure */
23+
video: 'on-first-retry',
24+
},
25+
/* Configure projects for different browsers */
26+
projects: [
27+
{
28+
name: 'chromium',
29+
use: { ...devices['Desktop Chrome'] },
30+
},
31+
{
32+
name: 'firefox',
33+
use: { ...devices['Desktop Firefox'] },
34+
},
35+
{
36+
name: 'webkit',
37+
use: { ...devices['Desktop Safari'] },
38+
},
39+
/* Test against mobile viewports. */
40+
{
41+
name: 'mobile-chrome',
42+
use: { ...devices['Pixel 7'] },
43+
},
44+
{
45+
name: 'mobile-safari',
46+
use: { ...devices['iPhone 14'] },
47+
},
48+
],
49+
/* Run web server for the tests */
50+
webServer: {
51+
command: 'pnpm dev',
52+
url: 'http://localhost:3000',
53+
reuseExistingServer: !process.env.CI,
54+
stdout: 'pipe',
55+
stderr: 'pipe',
56+
},
57+
});

apps/web/src/plugins/core/langs/en.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"sign_up": {
5656
"desc": "Hello there! Create your account to get started.",
5757
"already_have_account": "You already have an account? <link>Sign in</link>.",
58-
"submit": "Sign up",
58+
"submit": "Register",
5959
"username": {
6060
"label": "Username",
6161
"min_length": "Username must be at least 3 characters long.",
@@ -106,7 +106,7 @@
106106
"desc": "The email address or password was incorrect. Please try again (make sure your caps lock is off)."
107107
}
108108
},
109-
"submit": "Sign in"
109+
"submit": "Login"
110110
}
111111
}
112112
},

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"dev": "pnpm build:scripts && turbo dev",
1212
"lint": "turbo lint",
1313
"lint:fix": "turbo lint:fix",
14-
"test": "turbo test"
14+
"test": "turbo test",
15+
"test:e2e": "turbo test:e2e"
1516
},
1617
"devDependencies": {
1718
"eslint-config-typescript-vitnode": "workspace:*",

0 commit comments

Comments
 (0)