Skip to content

Commit 15e2324

Browse files
authored
Merge pull request #40 from SpaceyaTech/setup-playwright
Add Playwright testing framework and initial tests Playwright tests inside the tests folder will now be run before merging to main CI
2 parents c01eb76 + 8f8053b commit 15e2324

File tree

12 files changed

+2569
-3826
lines changed

12 files changed

+2569
-3826
lines changed

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# base url is required n the .env or playwright tests won't work
2+
BASE_URL="http://localhost:3000"

.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, master ]
5+
pull_request:
6+
branches: [ main, master ]
7+
jobs:
8+
test:
9+
timeout-minutes: 60
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
- uses: actions/setup-node@v4
14+
with:
15+
node-version: lts/*
16+
- name: Install dependencies
17+
run: npm install -g pnpm && pnpm install
18+
- name: Install Playwright Browsers
19+
run: pnpm exec playwright install --with-deps
20+
- name: Start Vite dev server
21+
run: pnpm exec vite --port 3000 &
22+
- name: Run Playwright tests
23+
run: pnpm exec playwright test
24+
- uses: actions/upload-artifact@v4
25+
if: ${{ !cancelled() }}
26+
with:
27+
name: playwright-report
28+
path: playwright-report/
29+
retention-days: 30

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ node_modules
1111
dist
1212
dist-ssr
1313
*.local
14-
14+
.env
1515
# Editor directories and files
1616
.vscode/*
1717
!.vscode/extensions.json
@@ -23,3 +23,7 @@ dist-ssr
2323
*.sln
2424
*.sw?
2525
tsconfig.node.tsbuildinfo
26+
/test-results/
27+
/playwright-report/
28+
/blob-report/
29+
/playwright/.cache/

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"lint": "eslint . --fix",
1010
"format": "prettier --write --ignore-unknown src",
1111
"page": "tsx src/scripts/scafold-pages/script.ts",
12+
"playwright":"playwright test --ui",
1213
"preview": "vite preview"
1314
},
1415
"dependencies": {
@@ -64,6 +65,7 @@
6465
},
6566
"devDependencies": {
6667
"@eslint/js": "^9.13.0",
68+
"@playwright/test": "^1.49.0",
6769
"@tanstack/react-query-devtools": "^5.59.19",
6870
"@tanstack/router-devtools": "^1.79.0",
6971
"@tanstack/router-plugin": "^1.79.0",

playwright.config.ts

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

0 commit comments

Comments
 (0)