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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pnpm exec playwright install chromium webkit
pnpm test:e2e
pnpm test:e2e -- --project=mobile
pnpm test:e2e -- --project=webkit
PLAYWRIGHT_BASE_URL=https://danieldcs.com pnpm test:e2e
```

`pnpm test:e2e` builds and starts the app (`pnpm build && pnpm start`) via Playwright's `webServer`.
Expand Down
3 changes: 2 additions & 1 deletion e2e/feed.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { expect, test } from '@playwright/test'
import { expect } from '@playwright/test'
import { test } from './helpers/block-posthog'
import { xmlTextContents } from './helpers/xml'

function canonicalHref(html: string) {
Expand Down
18 changes: 18 additions & 0 deletions e2e/helpers/block-posthog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { test as base } from '@playwright/test'

const postHogHosts = new Set(['us.i.posthog.com', 'us-assets.i.posthog.com'])

export const test = base.extend<{ blockPostHog: undefined }>({
blockPostHog: [
async ({ page }, use, testInfo) => {
if (testInfo.project.name === 'deployed') {
await page.route(
(url) => postHogHosts.has(url.hostname),
(route) => route.abort(),
)
}
await use(undefined)
},
{ auto: true },
],
})
3 changes: 2 additions & 1 deletion e2e/not-found.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { expect, test } from '@playwright/test'
import { expect } from '@playwright/test'
import { test } from './helpers/block-posthog'

const unmatchedPaths = [
'/qualquer',
Expand Down
8 changes: 2 additions & 6 deletions e2e/seo-consistency.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import {
type APIRequestContext,
expect,
type Page,
test,
} from '@playwright/test'
import { type APIRequestContext, expect, type Page } from '@playwright/test'
import { test } from './helpers/block-posthog'
import { getNewestBlogPost } from './helpers/posts'
import { xmlTextContents } from './helpers/xml'

Expand Down
3 changes: 2 additions & 1 deletion e2e/smoke.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { expect, test } from '@playwright/test'
import { expect } from '@playwright/test'
import { test } from './helpers/block-posthog'

const lightBackground = 'rgb(242, 235, 235)'
const darkBackground = 'rgb(16, 13, 13)'
Expand Down
98 changes: 64 additions & 34 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,67 @@
import { defineConfig, devices } from '@playwright/test'

const baseURL = 'http://127.0.0.1:3000'
const deployedBaseURL = process.env.PLAYWRIGHT_BASE_URL

export default defineConfig({
testDir: './e2e',
fullyParallel: true,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
reporter: 'list',
use: {
baseURL,
trace: 'on-first-retry',
},
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
grepInvert: /@mobile|@smoke/,
},
{
name: 'mobile',
use: { ...devices['Pixel 7'] },
grep: /@mobile/,
},
{
name: 'webkit',
use: { ...devices['Desktop Safari'] },
grep: /@smoke/,
},
],
webServer: {
command: 'pnpm build && pnpm start',
url: baseURL,
reuseExistingServer: !process.env.CI,
},
})
const deployedTestMatch = [
'redirects.spec.ts',
'metadata.spec.ts',
'seo-consistency.spec.ts',
'feed.spec.ts',
'not-found.spec.ts',
'smoke.spec.ts',
]

export default defineConfig(
deployedBaseURL
? {
testDir: './e2e',
fullyParallel: true,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
reporter: 'list',
use: {
baseURL: deployedBaseURL,
trace: 'on-first-retry',
},
projects: [
{
name: 'deployed',
use: { ...devices['Desktop Chrome'] },
testMatch: deployedTestMatch,
},
],
}
: {
testDir: './e2e',
fullyParallel: true,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
reporter: 'list',
use: {
baseURL: 'http://127.0.0.1:3000',
trace: 'on-first-retry',
},
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
grepInvert: /@mobile|@smoke/,
},
{
name: 'mobile',
use: { ...devices['Pixel 7'] },
grep: /@mobile/,
},
{
name: 'webkit',
use: { ...devices['Desktop Safari'] },
grep: /@smoke/,
},
],
webServer: {
command: 'pnpm build && pnpm start',
url: 'http://127.0.0.1:3000',
reuseExistingServer: !process.env.CI,
},
},
)
Loading