Skip to content

Commit 05f41e5

Browse files
committed
add playwright test
1 parent b919efc commit 05f41e5

File tree

7 files changed

+165
-1
lines changed

7 files changed

+165
-1
lines changed

.github/workflows/playwright.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Playwright Tests
2+
on:
3+
push:
4+
branches: ['main']
5+
pull_request:
6+
types: [opened, synchronize]
7+
8+
jobs:
9+
test:
10+
timeout-minutes: 60
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
- uses: actions/setup-node@v3
15+
with:
16+
node-version: 18
17+
- name: Install dependencies
18+
run: npm install -g pnpm && pnpm install
19+
- name: Install Playwright Browsers
20+
run: pnpm --dir apps/demo exec playwright install --with-deps
21+
- name: Run Playwright tests
22+
run: pnpm --dir apps/demo exec playwright test
23+
- uses: actions/upload-artifact@v3
24+
if: always()
25+
with:
26+
name: playwright-report
27+
path: playwright-report/
28+
retention-days: 30

.npmrc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//registry.npmjs.org/:_authToken=${NPM_TOKEN}
21

32
# npm options
43
auth-type=legacy

apps/demo/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules/
2+
/test-results/
3+
/playwright-report/
4+
/blob-report/
5+
/playwright/.cache/

apps/demo/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,9 @@
99
},
1010
"dependencies": {
1111
"jsx-email": "workspace:*"
12+
},
13+
"devDependencies": {
14+
"@playwright/test": "^1.40.1",
15+
"@types/node": "20.6.2"
1216
}
1317
}

apps/demo/playwright.config.ts

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import { defineConfig, devices } from '@playwright/test';
2+
3+
/**
4+
* Read environment variables from file.
5+
* https://github.com/motdotla/dotenv
6+
*/
7+
// require('dotenv').config();
8+
9+
/**
10+
* See https://playwright.dev/docs/test-configuration.
11+
*/
12+
export default defineConfig({
13+
testDir: './tests',
14+
/* Run tests in files in parallel */
15+
fullyParallel: true,
16+
/* Fail the build on CI if you accidentally left test.only in the source code. */
17+
forbidOnly: !!process.env.CI,
18+
/* Retry on CI only */
19+
retries: process.env.CI ? 2 : 0,
20+
/* Opt out of parallel tests on CI. */
21+
workers: process.env.CI ? 1 : undefined,
22+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
23+
reporter: 'html',
24+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
25+
use: {
26+
/* Base URL to use in actions like `await page.goto('/')`. */
27+
baseURL: 'http://localhost:55420',
28+
29+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
30+
trace: 'on-first-retry'
31+
},
32+
33+
/* Configure projects for major browsers */
34+
projects: [
35+
{
36+
name: 'chromium',
37+
use: { ...devices['Desktop Chrome'] }
38+
},
39+
40+
{
41+
name: 'firefox',
42+
use: { ...devices['Desktop Firefox'] }
43+
},
44+
45+
{
46+
name: 'webkit',
47+
use: { ...devices['Desktop Safari'] }
48+
}
49+
50+
/* Test against mobile viewports. */
51+
// {
52+
// name: 'Mobile Chrome',
53+
// use: { ...devices['Pixel 5'] },
54+
// },
55+
// {
56+
// name: 'Mobile Safari',
57+
// use: { ...devices['iPhone 12'] },
58+
// },
59+
60+
/* Test against branded browsers. */
61+
// {
62+
// name: 'Microsoft Edge',
63+
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
64+
// },
65+
// {
66+
// name: 'Google Chrome',
67+
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
68+
// },
69+
],
70+
71+
/* Run your local dev server before starting the tests */
72+
webServer: {
73+
command: 'pnpm exec email preview ./emails --no-open',
74+
url: 'http://localhost:55420',
75+
reuseExistingServer: !process.env.CI
76+
}
77+
});

apps/demo/tests/smoke.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { test, expect } from '@playwright/test';
2+
3+
test('has title', async ({ page }) => {
4+
await page.goto('/');
5+
await expect(page).toHaveTitle('JSX email');
6+
});
7+
8+
test('renders email', async ({ page }) => {
9+
await page.goto('/');
10+
await page.getByRole('link', { name: 'Airbnb-Review' }).click();
11+
await page.frameLocator('iframe').getByText("Here's what Joker wrote");
12+
});

pnpm-lock.yaml

Lines changed: 39 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)