-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: init playwright * ci(e2e): add postgres service in github action * ci(e2e): remove failing browser Update reporter to use "github" one in CI * feat: add utils to authenticate update playwright config with default urls remove gitlab component testings * feat: update recommended extensions * doc(e2e): update README.md * fix: pnpm update * wip: add target branch to test CI * ci(e2e): use pnpm instead of yarn
- Loading branch information
1 parent
be73792
commit 55fd688
Showing
9 changed files
with
266 additions
and
4 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,87 @@ | ||
name: Playwright Tests | ||
on: | ||
push: | ||
branches: [main, master] | ||
pull_request: | ||
branches: [main, master, v2-going-full-stack] | ||
|
||
jobs: | ||
E2E: | ||
timeout-minutes: 60 | ||
runs-on: ubuntu-latest | ||
env: | ||
NEXT_PUBLIC_BASE_URL: http://localhost:3000 | ||
NEXT_PUBLIC_DEV_ENV_NAME: tests | ||
DATABASE_URL: postgres://startui:startui@localhost:5432/startui | ||
NEXT_PUBLIC_IS_DEMO: false | ||
AUTH_SECRET: Replace me with `openssl rand -base64 32` generated secret | ||
EMAIL_SERVER: smtp://username:password@localhost:1025 | ||
EMAIL_FROM: Start UI <noreply@example.com> | ||
services: | ||
postgres: | ||
image: postgres | ||
|
||
env: | ||
POSTGRES_PASSWORD: startui | ||
POSTGRES_USER: startui | ||
POSTGRES_DB: startui | ||
|
||
options: >- | ||
--health-cmd pg_isready | ||
--health-interval 10s | ||
--health-timeout 5s | ||
--health-retries 5 | ||
ports: | ||
- 5432:5432 | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18 | ||
|
||
- uses: pnpm/action-setup@v2 | ||
name: Install pnpm | ||
with: | ||
version: 8 | ||
run_install: false | ||
|
||
- name: Get pnpm store directory | ||
shell: bash | ||
run: | | ||
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV | ||
- name: Cache node modules | ||
uses: actions/cache@v2 | ||
env: | ||
cache-name: cache-node-modules | ||
with: | ||
path: ${{ env.STORE_PATH }} | ||
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} | ||
restore-keys: | | ||
${{ runner.os }}-pnpm-store-${{ env.cache-name }}- | ||
${{ runner.os }}-pnpm-store- | ||
${{ runner.os }}- | ||
- name: Install dependencies | ||
run: pnpm install | ||
|
||
- name: Install Playwright Browsers | ||
run: pnpm playwright install --with-deps | ||
|
||
- name: Migrate database | ||
run: pnpm db:push | ||
|
||
- name: Add default data into database | ||
run: pnpm db:seed | ||
|
||
- name: Run Playwright tests | ||
run: pnpm e2e | ||
|
||
- uses: actions/upload-artifact@v3 | ||
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
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,28 @@ | ||
import { expect, test } from '@playwright/test'; | ||
import { getUtils } from 'e2e/utils'; | ||
|
||
test.describe('Authentication flow', () => { | ||
test('Login as admin', async ({ page }) => { | ||
const utils = getUtils(page); | ||
|
||
await utils.loginAsAdmin(); | ||
|
||
await expect( | ||
page.getByRole('heading', { name: 'Dashboard', level: 2 }) | ||
).toBeVisible(); | ||
|
||
await expect(page.getByRole('link', { name: 'Admin' })).toBeVisible(); | ||
}); | ||
|
||
test('Login as user', async ({ page }) => { | ||
const utils = getUtils(page); | ||
|
||
await utils.loginAsUser(); | ||
|
||
await expect( | ||
page.getByRole('heading', { name: 'Dashboard', level: 2 }) | ||
).toBeVisible(); | ||
|
||
await expect(page.getByRole('link', { name: 'Admin' })).not.toBeVisible(); | ||
}); | ||
}); |
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,45 @@ | ||
import { Page } from '@playwright/test'; | ||
|
||
/** | ||
* Utilities constructor | ||
* | ||
* @example | ||
* ```ts | ||
* test.describe('My scope', () => { | ||
* test('My test', async ({ page }) => { | ||
* const utils = getUtils(page); | ||
* | ||
* // No need too pass page on each util | ||
* await utils.login(...) | ||
* }) | ||
* }) | ||
* ``` | ||
*/ | ||
export const getUtils = (page: Page) => { | ||
return { | ||
/** | ||
* Utility used to authenticate the user on the app | ||
*/ | ||
async login(userDetails: { email: string; password: string }) { | ||
await page.goto('/login'); | ||
await page.waitForURL('**/login'); | ||
|
||
await page.getByLabel('Email').fill(userDetails.email); | ||
await page.getByLabel(/^Password/).fill(userDetails.password); | ||
|
||
await page.getByRole('button', { name: 'Log In' }).click(); | ||
}, | ||
async loginAsAdmin() { | ||
return this.login({ | ||
email: 'admin@admin.com', | ||
password: 'admin', | ||
}); | ||
}, | ||
async loginAsUser() { | ||
return this.login({ | ||
email: 'user@user.com', | ||
password: 'user', | ||
}); | ||
}, | ||
} as const; | ||
}; |
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,49 @@ | ||
import { defineConfig, devices } from '@playwright/test'; | ||
|
||
/** | ||
* 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: process.env.CI ? 'github' : 'html', | ||
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ | ||
use: { | ||
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: 'chromium', | ||
use: { ...devices['Desktop Chrome'] }, | ||
}, | ||
|
||
{ | ||
name: 'firefox', | ||
use: { ...devices['Desktop Firefox'] }, | ||
}, | ||
{ | ||
name: 'webkit', | ||
use: { ...devices['Desktop Safari'] }, | ||
}, | ||
], | ||
|
||
/* Run your local dev server before starting the tests */ | ||
webServer: { | ||
command: 'yarn dev', | ||
url: 'http://localhost:3000', | ||
reuseExistingServer: !process.env.CI, | ||
}, | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.