Skip to content

Commit 2a0d365

Browse files
committed
feat: setup tests
1 parent dcbb1be commit 2a0d365

File tree

10 files changed

+660
-1
lines changed

10 files changed

+660
-1
lines changed

.github/workflows/playwright.yml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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 ci
18+
- name: Install Playwright Browsers
19+
run: npx playwright install --with-deps
20+
- name: Run Playwright tests
21+
run: npx playwright test
22+
- uses: actions/upload-artifact@v4
23+
if: always()
24+
with:
25+
name: playwright-report
26+
path: playwright-report/
27+
retention-days: 30

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,7 @@ yarn-error.log*
3333
# typescript
3434
*.tsbuildinfo
3535
next-env.d.ts
36+
/test-results/
37+
/playwright-report/
38+
/blob-report/
39+
/playwright/.cache/

bun.lockb

54.2 KB
Binary file not shown.

e2e/auth.spec.ts

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { expect, test } from "@playwright/test"
2+
3+
test.describe("auth page", () => {
4+
test.beforeEach(async ({ page }) => {
5+
await page.goto("http://localhost:3000/auth")
6+
})
7+
8+
test("auth page renders", async ({ page }) => {
9+
await expect(page.getByRole("heading", { name: "Login" })).toBeVisible()
10+
})
11+
})
12+
13+
// test("get started link", async ({ page }) => {
14+
// await page.goto("https://playwright.dev/")
15+
16+
// // Click the get started link.
17+
// await page.getByRole("link", { name: "Get started" }).click()
18+
19+
// // Expects page to have a heading with the name of Installation.
20+
// await expect(
21+
// page.getByRole("heading", { name: "Installation" }),
22+
// ).toBeVisible()
23+
// })

e2e/landing.spec.ts

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { expect, test } from "@playwright/test"
2+
3+
test.describe("landing page", () => {
4+
test.beforeEach(async ({ page }) => {
5+
await page.goto("http://localhost:3000/")
6+
})
7+
8+
test("landing page renders", async ({ page }) => {
9+
await expect(page.getByRole("heading", { name: "KeepArr" })).toBeVisible()
10+
})
11+
12+
test("dark mode toggle works", async ({ page }) => {
13+
await page.getByRole("button", { name: "Toggle Theme" }).click()
14+
15+
await page.getByRole("menuitem", { name: "Dark" }).click()
16+
17+
await expect(page.locator("html").first()).toHaveClass("dark")
18+
})
19+
20+
test("it goes to the auth page from the landing", async ({ page }) => {
21+
await page.locator("button[data-testid=nav-menu]").click()
22+
23+
await page.locator("a[href='/auth']").click()
24+
25+
await page.waitForTimeout(1000)
26+
27+
await expect(page.url()).toBe("http://localhost:3000/auth")
28+
})
29+
})

package.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"build": "next build",
99
"start": "next start",
1010
"lint": "next lint",
11+
"test": "vitest",
1112
"format": "prettier --check --ignore-path .gitignore .",
1213
"format:fix": "prettier --write --ignore-path .gitignore .",
1314
"prepare": "husky"
@@ -35,9 +36,12 @@
3536
"@commitlint/cli": "^19.1.0",
3637
"@commitlint/config-conventional": "^19.1.0",
3738
"@ianvs/prettier-plugin-sort-imports": "^4.1.1",
39+
"@playwright/test": "^1.42.1",
40+
"@testing-library/react": "^14.2.1",
3841
"@types/node": "^20",
3942
"@types/react": "^18.2.52",
4043
"@types/react-dom": "^18.2.18",
44+
"@vitejs/plugin-react": "^4.2.1",
4145
"autoprefixer": "^10",
4246
"eslint": "^8",
4347
"eslint-config-next": "latest",
@@ -46,11 +50,13 @@
4650
"eslint-plugin-react": "^7.34.0",
4751
"eslint-plugin-tailwindcss": "^3.15.1",
4852
"husky": "^9.0.11",
53+
"jsdom": "^24.0.0",
4954
"postcss": "^8",
5055
"prettier": "^3.2.4",
5156
"prettier-plugin-tailwindcss": "^0.5.11",
5257
"pretty-quick": "^4.0.0",
5358
"tailwindcss": "^3",
54-
"typescript": "^5"
59+
"typescript": "^5",
60+
"vitest": "^1.3.1"
5561
}
5662
}

playwright.config.ts

+77
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: "./e2e",
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://127.0.0.1:3000',
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: "bun run turbo",
74+
// url: "http://localhost:3000",
75+
// reuseExistingServer: !process.env.CI,
76+
// },
77+
})

src/app/(landing)/_components/nav.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ function SMNav({ Items }: { Items: ReactElement }) {
8282
<Button
8383
variant={"plain"}
8484
size={"icon"}
85+
data-testid="nav-menu"
8586
className="aspect-square rounded-full border border-black/40 hover:border-black/80 dark:border-white/40 dark:hover:border-white/80"
8687
>
8788
<svg className="size-6 " fill="currentColor" viewBox="0 0 20 20">

0 commit comments

Comments
 (0)