-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add base Playwright setup for e2e testing, and first smoke test
- Loading branch information
1 parent
1435fbd
commit 69d3824
Showing
12 changed files
with
255 additions
and
49 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
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,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 install -g pnpm && 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: always() | ||
with: | ||
name: playwright-report | ||
path: playwright-report/ | ||
retention-days: 30 |
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,34 @@ | ||
import { expect, test } from '@playwright/test'; | ||
|
||
test.describe('Smoke test suite', () => { | ||
test.beforeEach(async ({ page }) => { | ||
console.log(`Running ${test.info().title}`); | ||
await page.goto('/'); | ||
}); | ||
|
||
test('should navigate to the about page', async ({ page }) => { | ||
await expect(page.locator('h2')).toContainText('Hi, ik ben Daniel Stals!'); | ||
}); | ||
|
||
test('dark or light mode should be toggled when theme toggle button is clicked', async ({ page }) => { | ||
const themeToggleButton = page.getByRole('button', { name: /toggle theme/i }); | ||
const htmlElement = page.locator('html'); | ||
await themeToggleButton.click(); | ||
await expect(htmlElement).toHaveClass(/dark/); | ||
await themeToggleButton.click(); | ||
await expect(htmlElement).toHaveClass(/light/); | ||
}); | ||
|
||
test('chat window should open when input is focussed', async ({ page }) => { | ||
const formElement = page.getByRole('form', { name: /chat/i }); | ||
await formElement.click(); | ||
await expect(formElement).toHaveClass(/sm:h-\[400px\]/); | ||
}); | ||
|
||
test('clicking a prompt suggestion should update chat input', async ({ page }) => { | ||
const promptSuggestionButtons = page.getByTestId('prompt-button'); | ||
const firstPromptText = await promptSuggestionButtons.first().innerText(); | ||
await promptSuggestionButtons.first().click(); | ||
await expect(page.getByRole('textbox', { name: /chat-input/i })).toHaveValue(firstPromptText); | ||
}); | ||
}); |
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,56 @@ | ||
import { defineConfig, devices } from '@playwright/test'; | ||
|
||
const PORT = 3000; | ||
|
||
/** | ||
* Read environment variables from file. | ||
* https://github.com/motdotla/dotenv | ||
*/ | ||
// import dotenv from 'dotenv'; | ||
// dotenv.config({ path: path.resolve(__dirname, '.env') }); | ||
|
||
/** | ||
* See https://playwright.dev/docs/test-configuration. | ||
*/ | ||
export default defineConfig({ | ||
testDir: './e2e', | ||
/* 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: { | ||
/* Base URL to use in actions like `await page.goto('/')`. */ | ||
baseURL: 'http://localhost:3000', | ||
|
||
/* 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: 'setup', testMatch: /.*\.setup\.ts/ }, | ||
{ | ||
name: 'chromium', | ||
testMatch: /.*\.spec\.ts/, | ||
use: { | ||
...devices['Desktop Chrome'], | ||
}, | ||
dependencies: ['setup'], | ||
}, | ||
], | ||
|
||
/* Run your local dev server before starting the tests */ | ||
webServer: { | ||
command: `pnpm dev --port ${PORT}`, | ||
timeout: 10 * 1000, | ||
port: PORT, | ||
reuseExistingServer: !process.env.CI, // reuse server to speed up tests | ||
}, | ||
}); |
Oops, something went wrong.