Skip to content
Merged
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
27 changes: 27 additions & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Playwright Tests
on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
jobs:
test:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
- name: Install dependencies
run: npm ci
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Run Playwright tests
run: npx playwright test
- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: playwright-report
path: playwright-report/
retention-days: 30
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,12 @@ next-env.d.ts
# jest testing
coverage/
.jest-cache/
__snapshots__/
__snapshots__/

# Playwright
node_modules/
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
/playwright/.auth/
Empty file added e2e/fixtures/.keep
Empty file.
5 changes: 5 additions & 0 deletions e2e/tests/example.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { test, expect as playwrightExpect } from '@playwright/test'

test('placeholder test', async ({ page }) => {
playwrightExpect(true).toBe(true)
})
12 changes: 12 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ const config: Config = {
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/$1',
},

testMatch: [
'<rootDir>/src/**/*.test.{js,jsx,ts,tsx}',
'<rootDir>/src/**/__tests__/**/*.{js,jsx,ts,tsx}',
],

testPathIgnorePatterns: [
'/node_modules/',
'/e2e/', // Ignore Playwright tests
'/.next/',
'/dist/',
],

// Coverage configuration
collectCoverageFrom: [
Expand Down
64 changes: 64 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@
"format:check": "prettier --check \"src/**/*.{ts,tsx,js,jsx,json,css}\"",
"test": "jest",
"test:watch": "jest --watch",
"test:coverage": "jest --coverage"
"test:coverage": "jest --coverage",
"test:e2e": "playwright test",
"test:e2e:ui": "playwright test --ui",
"test:e2e:headed": "playwright test --headed",
"test:e2e:debug": "playwright test --debug",
"test:e2e:report": "playwright show-report",
"test:all": "npm test && npm run test:e2e"
},
"dependencies": {
"next": "15.3.1",
Expand All @@ -21,6 +27,7 @@
"devDependencies": {
"@eslint/eslintrc": "^3.3.1",
"@eslint/js": "^9.39.1",
"@playwright/test": "^1.57.0",
"@tailwindcss/postcss": "^4",
"@testing-library/dom": "^10.4.1",
"@testing-library/jest-dom": "^6.9.1",
Expand Down
94 changes: 94 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
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({
testDir: './e2e/tests',
/* 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',
/* Only match .spec.ts files (avoid conflicts with Jest .test.ts files) */
testMatch: '**/*.spec.ts',
/* Ignore non-test files */
testIgnore: ['**/.keep', '**/README.md', '**/node_modules/**'],
/* 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://localhost:3001',

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

/* Take screenshot on failure */
screenshot: 'only-on-failure',

/* Record video on failure */
video: 'retain-on-failure',

},

/* 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: 'npm run dev',
url: 'http://localhost:3001',
reuseExistingServer: !process.env.CI,
timeout: 120 * 1000, // 2 minutes for Next.js to start
stdout: 'pipe', // Show server output
stderr: 'pipe',
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import '@testing-library/jest-dom'
describe('CharacterRoster', () => {
it('renders all character cards', () => {
render(<CharacterRoster characters={mockCharacters} />)
console.log(mockCharacters);

mockCharacters.forEach((character) => {
expect(screen.getByText(character.name)).toBeInTheDocument()
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/components/layout/Header/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default function Header() {
<Link href="">About</Link>
</li>
<li>
<Link href="/userHome">Profile</Link>
<Link href="/profile">Profile</Link>
</li>
<li>
<Link href="/character">Create</Link>
Expand Down
11 changes: 11 additions & 0 deletions tsconfig.e2e.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"target": "ES2020",
"lib": ["ES2021"],
"types": ["@playwright/test", "node"],
"moduleResolution": "node"
},
"include": ["e2e/**/*"],
"exclude": ["node_modules"]
}
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "ES2017",
"target": "ES2020",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
Expand All @@ -24,5 +24,5 @@
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
"exclude": ["node_modules", "e2e"]
}
Loading