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

Add e2e tests powered by playwright #98

Merged
merged 13 commits into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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 ]
pull_request:
branches: [ main ]
jobs:
test:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
- name: Install dependencies
run: corepack enable && pnpm install
- name: Install Playwright Browsers
run: pnpm exec playwright install --with-deps
- name: Run Playwright tests
run: pnpm exec 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 @@ -35,3 +35,7 @@ package-lock.json
*.idea

.astro
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
30 changes: 30 additions & 0 deletions e2e-tests/hp.e2e.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { test, expect } from '@playwright/test';

test('italian HP is well formed', async ({ page }) => {
await page.goto('./');

const html = page.locator('html');
const lang = await html.getAttribute('lang');

expect(lang).toBe('it');
// Expect a title "to contain" a substring.
await expect(page).toHaveTitle(/La tech community di Javascript su Roma/);

const h1 = page.locator('h1');
await h1.isVisible();
await expect(h1).toHaveText(/La tech community di Javascript su Roma/);
});

test('english HP is well formed', async ({ page }) => {
await page.goto('./en');

const html = page.locator('html');
const lang = await html.getAttribute('lang');

expect(lang).toBe('en');
await expect(page).toHaveTitle(/The Javascript community in Rome/);

const h1 = page.locator('h1');
await h1.isVisible();
await expect(h1).toHaveText(/The Javascript community in Rome/);
});
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"build": "npm run lint:ts && astro build",
"astro:sync": "astro sync",
"astro:upgrade": "pnpm dlx @astrojs/upgrade",
"test:e2e": "pnpm exec playwright test",
"test:e2e:ui": "pnpm exec playwright test --ui",
"lint:ts": "tsc --noEmit",
"lint:astro": "astro check",
"create-post": "node scripts/create-post.mjs",
Expand All @@ -29,6 +31,8 @@
"@astrojs/rss": "^4.0.7",
"@astrojs/sitemap": "^3.1.6",
"@astrojs/solid-js": "^4.4.1",
"@playwright/test": "^1.49.1",
"@types/node": "^22.10.2",
"astro": "4.15.4",
"astro-i18next": "1.0.0-beta.21",
"chalk": "^5.0.1",
Expand Down
74 changes: 74 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
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') });

const isCi = process.env.CI === 'true';
const baseURL = 'http://localhost:4321/';
/**
* 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: isCi,
/* Retry on CI only */
retries: isCi ? 1 : 0,
/* Opt out of parallel tests on CI. */
workers: isCi ? 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,

/* 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: 'android(Pixel 7)',
use: { ...devices['Pixel 7'] },
},
/* 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: 'pnpm run build && pnpm run preview',
url: baseURL,
reuseExistingServer: !isCi,
},
});
Loading
Loading