-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fea: run yarn create playwright * fix: update lock file * enh: set yarn e2e script * enh: add initial tests for home page * test(e2e): test toggle language * enh: use TEST_URL to define the base URL * oth: clean up * ci(playwright): await for vercel preview url * fix: update timeouts * fix: job name * test(playwright): validate if links are present * fix: pr suggestions
- Loading branch information
1 parent
b486ab1
commit ed3b543
Showing
9 changed files
with
2,894 additions
and
1,401 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
name: Playwright Tests | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
branches: [main] | ||
|
||
jobs: | ||
integration-tests: | ||
timeout-minutes: 300 | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: lts/* | ||
|
||
- name: Waiting for 200 from the Vercel Preview | ||
uses: patrickedqvist/wait-for-vercel-preview@v1.3.1 | ||
id: waitFor200 | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
max_timeout: 300 | ||
|
||
# access preview url | ||
- name: Inject testing URL | ||
run: echo "TEST_URL=${{steps.waitFor200.outputs.url}}" >> $GITHUB_ENV | ||
|
||
- name: Install dependencies | ||
run: npm install -g yarn && yarn | ||
|
||
- name: Install Playwright Browsers | ||
run: yarn playwright install --with-deps | ||
|
||
- name: Run Playwright tests | ||
run: yarn playwright test | ||
|
||
- uses: actions/upload-artifact@v4 | ||
if: always() | ||
with: | ||
name: playwright-report | ||
path: playwright-report/ | ||
retention-days: 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,3 +39,7 @@ yarn-error.log* | |
|
||
# dotenv | ||
.env* | ||
/test-results/ | ||
/playwright-report/ | ||
/blob-report/ | ||
/playwright/.cache/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { defineConfig, devices } from '@playwright/test'; | ||
|
||
/** | ||
* See https://playwright.dev/docs/test-configuration. | ||
*/ | ||
export default defineConfig({ | ||
testDir: './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', | ||
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ | ||
use: { | ||
/* 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'] }, | ||
}, | ||
], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { test, expect } from '@playwright/test'; | ||
|
||
import { links } from '@packages/config/site'; | ||
|
||
const PAGE_MAP: Record<string, string> = { | ||
development: 'http://localhost:3000', | ||
production: 'https://podcodar.org', | ||
}; | ||
|
||
const HOMEPAGE = | ||
process.env.TEST_URL || | ||
PAGE_MAP[process.env.NODE_ENV as string] || | ||
PAGE_MAP.development; | ||
|
||
test('has title', async ({ page }) => { | ||
await page.goto(HOMEPAGE); | ||
|
||
// Expect a title "to contain" a substring. | ||
await expect(page).toHaveTitle(/PodCodar/); | ||
}); | ||
|
||
test('has navigation links', async ({ page }) => { | ||
await page.goto(HOMEPAGE); | ||
|
||
for (const link of Object.values(links)) { | ||
expect(await page.$(`a[href="${link}"]`)).not.toBeNull(); | ||
} | ||
}); | ||
|
||
test('Join button is disabled', async ({ page }) => { | ||
await page.goto(HOMEPAGE); | ||
|
||
// Get join button | ||
const joinBtn = page.getByTestId('join-button'); | ||
expect(joinBtn).not.toBeNull(); | ||
|
||
// Expect join button to be disabled | ||
expect(await joinBtn.isEnabled()).toBeFalsy(); | ||
}); | ||
|
||
test('Toggle theme is working', async ({ page }) => { | ||
await page.goto(HOMEPAGE); | ||
|
||
// Get join button | ||
const toggleBtn = page.getByTestId('toggle-theme'); | ||
expect(toggleBtn).not.toBeNull(); | ||
|
||
// check initial theme value | ||
const initialTheme = await page.getAttribute('html', 'data-theme'); | ||
expect(initialTheme).toBe('light'); | ||
|
||
// Click the toggle theme | ||
await toggleBtn.click(); | ||
expect(await page.getAttribute('html', 'data-theme')).toBe('dark'); | ||
|
||
// Click the toggle theme | ||
await toggleBtn.click(); | ||
expect(await page.getAttribute('html', 'data-theme')).toBe('light'); | ||
}); | ||
|
||
test('Toggle language is working', async ({ page }) => { | ||
await page.goto(HOMEPAGE); | ||
|
||
// Get join button | ||
const toggleBtn = page.getByTestId('toggle-language'); | ||
expect(toggleBtn).not.toBeNull(); | ||
|
||
// check initial theme value | ||
expect(await page.getByTestId('join-button').textContent()).toBe('Entrar'); | ||
|
||
// Click the toggle language | ||
await toggleBtn.click(); | ||
expect(await page.getByTestId('join-button').textContent()).toBe('Join'); | ||
|
||
// Click the toggle language | ||
await toggleBtn.click(); | ||
expect(await page.getByTestId('join-button').textContent()).toBe('Entrar'); | ||
}); |
Oops, something went wrong.