Skip to content

Commit

Permalink
add playwright test
Browse files Browse the repository at this point in the history
  • Loading branch information
wladpaiva committed Dec 17, 2023
1 parent b919efc commit 05f41e5
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 1 deletion.
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: ['main']
pull_request:
types: [opened, synchronize]

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 --dir apps/demo exec playwright install --with-deps
- name: Run Playwright tests
run: pnpm --dir apps/demo exec playwright test
- uses: actions/upload-artifact@v3
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 30
1 change: 0 additions & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//registry.npmjs.org/:_authToken=${NPM_TOKEN}

# npm options
auth-type=legacy
Expand Down
5 changes: 5 additions & 0 deletions apps/demo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules/
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
4 changes: 4 additions & 0 deletions apps/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@
},
"dependencies": {
"jsx-email": "workspace:*"
},
"devDependencies": {
"@playwright/test": "^1.40.1",
"@types/node": "20.6.2"
}
}
77 changes: 77 additions & 0 deletions apps/demo/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { defineConfig, devices } from '@playwright/test';

Check failure on line 1 in apps/demo/playwright.config.ts

View workflow job for this annotation

GitHub Actions / Validate

'@playwright/test' should be listed in the project's dependencies, not devDependencies

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

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({

Check failure on line 12 in apps/demo/playwright.config.ts

View workflow job for this annotation

GitHub Actions / Validate

Prefer named exports
testDir: './tests',
/* Run tests in files in parallel */
fullyParallel: true,

Check failure on line 15 in apps/demo/playwright.config.ts

View workflow job for this annotation

GitHub Actions / Validate

Expected object keys to be in natural insensitive ascending order. 'fullyParallel' should be before 'testDir'
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,

Check failure on line 17 in apps/demo/playwright.config.ts

View workflow job for this annotation

GitHub Actions / Validate

Expected object keys to be in natural insensitive ascending order. 'forbidOnly' should be before 'fullyParallel'
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,

Check warning on line 21 in apps/demo/playwright.config.ts

View workflow job for this annotation

GitHub Actions / Validate

Unexpected use of undefined
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html',

Check failure on line 23 in apps/demo/playwright.config.ts

View workflow job for this annotation

GitHub Actions / Validate

Expected object keys to be in natural insensitive ascending order. 'reporter' should be before 'workers'
/* 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:55420',

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry'
},

/* Configure projects for major browsers */
projects: [

Check failure on line 34 in apps/demo/playwright.config.ts

View workflow job for this annotation

GitHub Actions / Validate

Expected object keys to be in natural insensitive ascending order. 'projects' should be before 'use'
{
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: 'pnpm exec email preview ./emails --no-open',
url: 'http://localhost:55420',
reuseExistingServer: !process.env.CI

Check failure on line 75 in apps/demo/playwright.config.ts

View workflow job for this annotation

GitHub Actions / Validate

Expected object keys to be in natural insensitive ascending order. 'reuseExistingServer' should be before 'url'
}
});
12 changes: 12 additions & 0 deletions apps/demo/tests/smoke.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { test, expect } from '@playwright/test';

Check failure on line 1 in apps/demo/tests/smoke.spec.ts

View workflow job for this annotation

GitHub Actions / Validate

'@playwright/test' should be listed in the project's dependencies, not devDependencies

test('has title', async ({ page }) => {
await page.goto('/');
await expect(page).toHaveTitle('JSX email');
});

test('renders email', async ({ page }) => {
await page.goto('/');
await page.getByRole('link', { name: 'Airbnb-Review' }).click();
await page.frameLocator('iframe').getByText("Here's what Joker wrote");
});
39 changes: 39 additions & 0 deletions pnpm-lock.yaml

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

0 comments on commit 05f41e5

Please sign in to comment.