Skip to content

Commit 1ed5946

Browse files
chore: initial Playwright tests (#313)
* chore: initial Playwright tests * chore: just test on main Co-authored-by: Celine Sarafa <celinesarafa@gmail.com> * chore: script name Co-authored-by: Celine Sarafa <celinesarafa@gmail.com> * fix: docs * chore: reset to main * chore: install deps --------- Co-authored-by: Celine Sarafa <celinesarafa@gmail.com>
1 parent 7498b08 commit 1ed5946

File tree

8 files changed

+176
-2
lines changed

8 files changed

+176
-2
lines changed

.github/workflows/playwright.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Playwright Tests
2+
on:
3+
push:
4+
branches: [ main ]
5+
pull_request:
6+
branches: [ main ]
7+
jobs:
8+
test:
9+
timeout-minutes: 10
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v3
13+
- uses: actions/setup-node@v3
14+
with:
15+
node-version: 18
16+
- name: Install dependencies
17+
run: yarn
18+
- name: Install Playwright Browsers
19+
run: yarn playwright:install
20+
- name: Run Playwright tests
21+
run: yarn playwright:test
22+
env:
23+
VITE_PROJECT_ID: ${{ secrets.VITE_DEV_PROJECT_ID }}
24+
- uses: actions/upload-artifact@v3
25+
if: always()
26+
with:
27+
name: playwright-report
28+
path: playwright-report/
29+
retention-days: 30

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,7 @@ dist-ssr
2727
*.sw?
2828

2929
dev-dist
30+
/test-results/
31+
/playwright-report/
32+
/blob-report/
33+
/playwright/.cache/

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,10 @@ Run the development server:
2424
```bash
2525
yarn dev
2626
```
27+
28+
## Testing
29+
30+
```bash
31+
yarn playwright:install
32+
yarn playwright:test
33+
```

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
"lint": "eslint .",
1313
"prepare": "husky install",
1414
"prettier": "prettier --check '**/*.{js,ts,jsx,tsx,scss}'",
15-
"prettier:write": "prettier --write '**/*.{js,ts,jsx,tsx,scss}'"
15+
"prettier:write": "prettier --write '**/*.{js,ts,jsx,tsx,scss}'",
16+
"playwright:install": "playwright install --with-deps",
17+
"playwright:test": "playwright test"
1618
},
1719
"dependencies": {
1820
"@sentry/react": "^7.64.0",
@@ -41,9 +43,11 @@
4143
"wagmi": "^1.4.2"
4244
},
4345
"devDependencies": {
46+
"@playwright/test": "^1.40.1",
4447
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
4548
"@types/lodash.debounce": "^4.0.7",
4649
"@types/mixpanel-browser": "^2.47.1",
50+
"@types/node": "^20.10.5",
4751
"@types/react": "^18.0.24",
4852
"@types/react-dom": "^18.0.8",
4953
"@typescript-eslint/eslint-plugin": "^5.45.1",

playwright.config.ts

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

tests/home.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { test, expect } from '@playwright/test';
2+
3+
test('has title', async ({ page }) => {
4+
await page.goto("/");
5+
await expect(page).toHaveTitle(/Web3Inbox/);
6+
});
7+
8+
test('welcome message', async ({ page }) => {
9+
await page.goto("/");
10+
await expect(page.getByText("Welcome to Web3Inbox")).toBeVisible();
11+
});

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"@/*": ["./src/*"]
2121
}
2222
},
23-
"include": ["src"],
23+
"include": ["src", "playwright.config.ts", "tests"],
2424
"exclude": ["*/**/*.js"],
2525
"references": [{ "path": "./tsconfig.node.json" }]
2626
}

yarn.lock

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2283,6 +2283,13 @@
22832283
"@parcel/watcher-win32-ia32" "2.3.0"
22842284
"@parcel/watcher-win32-x64" "2.3.0"
22852285

2286+
"@playwright/test@^1.40.1":
2287+
version "1.40.1"
2288+
resolved "https://registry.yarnpkg.com/@playwright/test/-/test-1.40.1.tgz#9e66322d97b1d74b9f8718bacab15080f24cde65"
2289+
integrity sha512-EaaawMTOeEItCRvfmkI9v6rBkF1svM8wjl/YPRrg2N2Wmp+4qJYkWtJsbew1szfKKDm6fPLy4YAanBhIlf9dWw==
2290+
dependencies:
2291+
playwright "1.40.1"
2292+
22862293
"@protobufjs/aspromise@^1.1.1", "@protobufjs/aspromise@^1.1.2":
22872294
version "1.1.2"
22882295
resolved "https://registry.npmjs.org/@protobufjs/aspromise/-/aspromise-1.1.2.tgz"
@@ -2790,6 +2797,13 @@
27902797
resolved "https://registry.npmjs.org/@types/node/-/node-12.20.55.tgz"
27912798
integrity sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ==
27922799

2800+
"@types/node@^20.10.5":
2801+
version "20.11.0"
2802+
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.11.0.tgz#8e0b99e70c0c1ade1a86c4a282f7b7ef87c9552f"
2803+
integrity sha512-o9bjXmDNcF7GbM4CNQpmi+TutCgap/K3w1JyKgxAjqx41zp9qlIAVFi0IhCNsJcXolEqLWhbFbEeL0PvYm4pcQ==
2804+
dependencies:
2805+
undici-types "~5.26.4"
2806+
27932807
"@types/parse-json@^4.0.0":
27942808
version "4.0.0"
27952809
resolved "https://registry.npmjs.org/@types/parse-json/-/parse-json-4.0.0.tgz"
@@ -5405,6 +5419,11 @@ fs.realpath@^1.0.0:
54055419
resolved "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz"
54065420
integrity sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==
54075421

5422+
fsevents@2.3.2:
5423+
version "2.3.2"
5424+
resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.2.tgz#8a526f78b8fdf4623b709e0b975c52c24c02fd1a"
5425+
integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==
5426+
54085427
fsevents@~2.3.2:
54095428
version "2.3.3"
54105429
resolved "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz"
@@ -7008,6 +7027,20 @@ pkg-types@^1.0.3:
70087027
mlly "^1.2.0"
70097028
pathe "^1.1.0"
70107029

7030+
playwright-core@1.40.1:
7031+
version "1.40.1"
7032+
resolved "https://registry.yarnpkg.com/playwright-core/-/playwright-core-1.40.1.tgz#442d15e86866a87d90d07af528e0afabe4c75c05"
7033+
integrity sha512-+hkOycxPiV534c4HhpfX6yrlawqVUzITRKwHAmYfmsVreltEl6fAZJ3DPfLMOODw0H3s1Itd6MDCWmP1fl/QvQ==
7034+
7035+
playwright@1.40.1:
7036+
version "1.40.1"
7037+
resolved "https://registry.yarnpkg.com/playwright/-/playwright-1.40.1.tgz#a11bf8dca15be5a194851dbbf3df235b9f53d7ae"
7038+
integrity sha512-2eHI7IioIpQ0bS1Ovg/HszsN/XKNwEG1kbzSDDmADpclKc7CyqkHw7Mg2JCz/bbCxg25QUPcjksoMW7JcIFQmw==
7039+
dependencies:
7040+
playwright-core "1.40.1"
7041+
optionalDependencies:
7042+
fsevents "2.3.2"
7043+
70117044
pngjs@^5.0.0:
70127045
version "5.0.0"
70137046
resolved "https://registry.npmjs.org/pngjs/-/pngjs-5.0.0.tgz"
@@ -8083,6 +8116,11 @@ uncrypto@^0.1.3:
80838116
resolved "https://registry.yarnpkg.com/uncrypto/-/uncrypto-0.1.3.tgz#e1288d609226f2d02d8d69ee861fa20d8348ef2b"
80848117
integrity sha512-Ql87qFHB3s/De2ClA9e0gsnS6zXG27SkTiSJwjCc9MebbfapQfuPzumMIUMi38ezPZVNFcHI9sUIepeQfw8J8Q==
80858118

8119+
undici-types@~5.26.4:
8120+
version "5.26.5"
8121+
resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617"
8122+
integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==
8123+
80868124
unenv@^1.7.4:
80878125
version "1.8.0"
80888126
resolved "https://registry.yarnpkg.com/unenv/-/unenv-1.8.0.tgz#0f860d5278405700bd95d47b23bc01f3a735d68c"

0 commit comments

Comments
 (0)