Skip to content

Commit 3730ac7

Browse files
authored
Setup tests (#86)
1 parent d4f2cae commit 3730ac7

File tree

17 files changed

+2856
-127
lines changed

17 files changed

+2856
-127
lines changed

.eslintrc.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,19 @@
22
"extends": [
33
"eslint:recommended",
44
"plugin:@typescript-eslint/recommended",
5-
"next/core-web-vitals",
5+
"plugin:@next/next/recommended",
66
"prettier"
77
],
88
"parser": "@typescript-eslint/parser",
9-
"plugins": ["@typescript-eslint"]
9+
"plugins": ["@typescript-eslint"],
10+
"overrides": [
11+
{
12+
"files": ["src/**/*.{spec,test}.{mjs,cjs,js,ts,jsx,tsx}"],
13+
"extends": ["plugin:jest-dom/recommended", "plugin:testing-library/react"]
14+
},
15+
{
16+
"files": ["e2e-tests/**/*.{spec,test}.{mjs,cjs,js,ts,jsx,tsx}"],
17+
"extends": ["plugin:playwright/recommended"]
18+
}
19+
]
1020
}

.github/workflows/ci.yaml

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
name: CI
2+
23
on: push
34

4-
permissions:
5-
contents: write
5+
concurrency:
6+
group: 'ci'
7+
cancel-in-progress: true
68

79
jobs:
810
lintfix:
911
name: Lint and fix
1012
runs-on: ubuntu-latest
13+
permissions:
14+
contents: write
1115
steps:
1216
- name: 🚀 Checkout
1317
uses: actions/checkout@v3
@@ -57,3 +61,46 @@ jobs:
5761
message: 'chore: Auto-fix lint errors'
5862
github_token: ${{ secrets.GITHUB_TOKEN }}
5963
branch: ${{ github.ref }}
64+
65+
test-integration:
66+
name: Test integration
67+
runs-on: ubuntu-latest
68+
steps:
69+
- name: 🚀 Checkout
70+
uses: actions/checkout@v3
71+
with:
72+
persist-credentials: false
73+
fetch-depth: 0
74+
75+
- name: 🎯 Read .nvmrc
76+
run: echo "##[set-output name=NVMRC;]$(cat .nvmrc)"
77+
id: nvm
78+
79+
- name: 🏗️ Setup Node.js
80+
uses: actions/setup-node@v3
81+
with:
82+
node-version: '${{ steps.nvm.outputs.NVMRC }}'
83+
84+
- name: 📦 Setup pnpm - Install pnpm
85+
uses: pnpm/action-setup@v2
86+
with:
87+
run_install: false
88+
89+
- name: 📦 Setup pnpm - Get pnpm store directory
90+
shell: bash
91+
run: |
92+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
93+
94+
- name: 📦 Setup pnpm - Setup pnpm cache
95+
uses: actions/cache@v3
96+
with:
97+
path: ${{ env.STORE_PATH }}
98+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
99+
restore-keys: |
100+
${{ runner.os }}-pnpm-store-
101+
102+
- name: 📦 Install dependencies
103+
run: pnpm install
104+
105+
- name: 🧪 Run test
106+
run: pnpm test:integration

.github/workflows/e2e-tests.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: Tests E2E
2+
3+
on: deployment_status
4+
5+
jobs:
6+
tests:
7+
name: Tests E2E
8+
timeout-minutes: 60
9+
runs-on: ubuntu-latest
10+
if: github.event_name == 'deployment_status' && github.event.deployment_status.state == 'success'
11+
concurrency:
12+
group: 'e2e-tests'
13+
cancel-in-progress: true
14+
steps:
15+
- name: 🚀 Checkout
16+
uses: actions/checkout@v3
17+
with:
18+
persist-credentials: false
19+
fetch-depth: 0
20+
21+
- name: 🎯 Read .nvmrc
22+
run: echo "##[set-output name=NVMRC;]$(cat .nvmrc)"
23+
id: nvm
24+
25+
- name: 🏗️ Setup Node.js
26+
uses: actions/setup-node@v3
27+
with:
28+
node-version: '${{ steps.nvm.outputs.NVMRC }}'
29+
30+
- name: 📦 Setup pnpm - Install pnpm
31+
uses: pnpm/action-setup@v2
32+
with:
33+
run_install: false
34+
35+
- name: 📦 Setup pnpm - Get pnpm store directory
36+
shell: bash
37+
run: |
38+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
39+
40+
- name: 📦 Setup pnpm - Setup pnpm cache
41+
uses: actions/cache@v3
42+
with:
43+
path: ${{ env.STORE_PATH }}
44+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
45+
restore-keys: |
46+
${{ runner.os }}-pnpm-store-
47+
48+
- name: 📦 Install dependencies
49+
run: pnpm install
50+
51+
- name: 🌐 Install Playwright Browsers
52+
run: pnpm exec playwright install --with-deps
53+
54+
- name: 🎭 Run Playwright tests
55+
run: pnpm test:e2e
56+
env:
57+
BASE_URL: ${{ github.event.deployment_status.target_url }}
58+
59+
- name: 📊 Upload Playwright Report
60+
uses: actions/upload-artifact@v3
61+
if: always()
62+
with:
63+
name: playwright-report
64+
path: playwright-report/
65+
retention-days: 30

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,8 @@ yarn-error.log*
3333
# typescript
3434
*.tsbuildinfo
3535
next-env.d.ts
36+
37+
# playwright
38+
/test-results/
39+
/playwright-report/
40+
/playwright/.cache/

e2e-tests/landing.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { test, expect } from '@playwright/test'
2+
3+
test('has title', async ({ page }) => {
4+
await page.goto('/en')
5+
6+
await expect(page).toHaveTitle(/Begur/)
7+
})
8+
9+
test('lunch app link', async ({ page }) => {
10+
await page.goto('/en')
11+
12+
await page.getByRole('link', { name: 'Lunch App' }).click()
13+
14+
await expect(page.getByRole('heading', { name: 'Explore' })).toBeVisible()
15+
})

jest.config.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* eslint-env node */
2+
/* eslint-disable @typescript-eslint/no-var-requires */
3+
4+
const nextJest = require('next/jest')
5+
6+
const createJestConfig = nextJest({
7+
dir: './',
8+
})
9+
10+
/** @type {import('jest').Config} */
11+
const config = {
12+
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
13+
roots: ['./src/'],
14+
testEnvironment: 'jest-environment-jsdom',
15+
preset: 'ts-jest',
16+
}
17+
18+
module.exports = createJestConfig(config)

jest.setup.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import '@testing-library/jest-dom'

package.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
"start": "next start",
88
"lint": "SKIP_ENV_VALIDATION=true next lint",
99
"format": "prettier . --write",
10+
"test:integration": "SKIP_ENV_VALIDATION=true jest --ci",
11+
"test:integration:dev": "SKIP_ENV_VALIDATION=true jest --watch",
12+
"test:e2e": "playwright test",
13+
"test:e2e:dev": "playwright test --ui",
1014
"db:generate": "drizzle-kit generate:mysql",
1115
"db:push": "drizzle-kit push:mysql",
1216
"db-local:studio": "drizzle-kit studio",
@@ -48,14 +52,25 @@
4852
"zod": "3.21.4"
4953
},
5054
"devDependencies": {
55+
"@playwright/test": "1.39.0",
56+
"@testing-library/jest-dom": "6.1.4",
57+
"@testing-library/react": "14.0.0",
58+
"@testing-library/user-event": "14.5.1",
59+
"@types/jest": "29.5.6",
5160
"@typescript-eslint/eslint-plugin": "6.7.5",
5261
"dotenv": "16.3.1",
5362
"drizzle-kit": "0.19.12",
5463
"eslint-config-prettier": "9.0.0",
64+
"eslint-plugin-jest-dom": "5.1.0",
65+
"eslint-plugin-playwright": "0.17.0",
66+
"eslint-plugin-testing-library": "6.1.0",
67+
"jest": "29.7.0",
68+
"jest-environment-jsdom": "29.7.0",
5569
"prettier": "3.0.3",
5670
"prettier-plugin-tailwindcss": "0.5.5",
5771
"server-only": "0.0.1",
58-
"tailwind-merge": "1.14.0"
72+
"tailwind-merge": "1.14.0",
73+
"ts-jest": "29.1.1"
5974
},
6075
"license": "GNU GENERAL PUBLIC LICENSE",
6176
"packageManager": "pnpm@8.9.2"

playwright.config.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { defineConfig, devices } from '@playwright/test'
2+
import dotenv from 'dotenv'
3+
import path from 'node:path'
4+
5+
dotenv.config({ path: path.resolve(process.cwd(), '.env.local') })
6+
dotenv.config({ path: path.resolve(process.cwd(), '.env') })
7+
8+
/**
9+
* See https://playwright.dev/docs/test-configuration.
10+
*/
11+
export default defineConfig({
12+
testDir: './e2e-tests',
13+
fullyParallel: true,
14+
forbidOnly: !!process.env.CI,
15+
retries: process.env.CI ? 2 : 0,
16+
workers: process.env.CI ? 1 : undefined,
17+
reporter: 'html',
18+
19+
use: {
20+
baseURL: process.env.BASE_URL || 'http://localhost:3000',
21+
trace: 'on-first-retry',
22+
},
23+
24+
projects: [
25+
{
26+
name: 'chromium',
27+
use: { ...devices['Desktop Chrome'] },
28+
},
29+
// {
30+
// name: 'firefox',
31+
// use: { ...devices['Desktop Firefox'] },
32+
// },
33+
// {
34+
// name: 'webkit',
35+
// use: { ...devices['Desktop Safari'] },
36+
// },
37+
38+
/* Test against mobile viewports. */
39+
{
40+
name: 'Mobile Chrome',
41+
use: { ...devices['Pixel 5'] },
42+
},
43+
{
44+
name: 'Mobile Safari',
45+
use: { ...devices['iPhone 12'] },
46+
},
47+
48+
/* Test against branded browsers. */
49+
// {
50+
// name: 'Microsoft Edge',
51+
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
52+
// },
53+
// {
54+
// name: 'Google Chrome',
55+
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
56+
// },
57+
],
58+
59+
/* Run your local dev server before starting the tests */
60+
// webServer: [
61+
// {
62+
// command: 'pnpm db-local:run-app',
63+
// url: 'http://localhost:3000',
64+
// reuseExistingServer: !process.env.CI,
65+
// },
66+
// {
67+
// command: 'pnpm db-local:run-db',
68+
// url: 'http://localhost:3306',
69+
// reuseExistingServer: !process.env.CI,
70+
// },
71+
// ],
72+
})

0 commit comments

Comments
 (0)