Skip to content

Commit

Permalink
feat: add e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
levino committed Nov 26, 2023
1 parent b9c862d commit efc495e
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 3 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Playwright Tests
on:
push:
branches: [master]
pull_request:
branches: [master]
jobs:
test:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- name: Install dependencies
run: npm install -g pnpm && pnpm install
- name: Install Playwright Browsers
run: pnpm exec playwright install --with-deps
working-directory: app/registry
- name: Run Playwright tests
run: turbo test:e2e
- uses: actions/upload-artifact@v3
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 30
4 changes: 4 additions & 0 deletions apps/registry/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ yarn-error.log*

# vercel
.vercel
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
8 changes: 6 additions & 2 deletions apps/registry/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"start": "next start",
"lint": "next lint --max-warnings=0",
"postinstall": "prisma generate --data-proxy",
"db:generate": "prisma generate"
"db:generate": "prisma generate",
"test:e2e": "playwright test"
},
"dependencies": {
"@faker-js/faker": "^8.0.2",
Expand Down Expand Up @@ -111,6 +112,9 @@
"uuid": "^9.0.0"
},
"devDependencies": {
"eslint-config-custom": "workspace:*"
"@playwright/test": "^1.40.0",
"@types/node": "^20.10.0",
"eslint-config-custom": "workspace:*",
"playwright": "^1.40.0"
}
}
81 changes: 81 additions & 0 deletions apps/registry/playwright.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// @ts-check
const { defineConfig, devices } = require('@playwright/test');

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// require('dotenv').config();

/**
* @see https://playwright.dev/docs/test-configuration
*/
module.exports = defineConfig({
webServer: {
command: 'npm run dev',
},
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: {
/* Base URL to use in actions like `await page.goto('/')`. */
// baseURL: 'http://127.0.0.1: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'] },
},

/* 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: 'npm run start',
// url: 'http://127.0.0.1:3000',
// reuseExistingServer: !process.env.CI,
// },
});
9 changes: 9 additions & 0 deletions apps/registry/tests/example.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// @ts-check
const { test, expect } = require('@playwright/test');

test('has title', async ({ page }) => {
await page.goto('http://localhost:3002/thomasdavis');

// Expect a title "to contain" a substring.
await expect(page).toHaveTitle(/Thomas Davis/);
});
44 changes: 43 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit efc495e

Please sign in to comment.