Skip to content

Commit

Permalink
feat: ✨ add e2e tests Github Actions worflow
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmy-guzman committed Dec 7, 2023
1 parent 64b0fd1 commit 39c2a95
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 25 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: preview

on: [deployment_status]

jobs:
e2e:
if: github.event.deployment_status.state == 'success'
runs-on: ubuntu-latest

steps:
- name: 🏗 Setup Repository
uses: actions/checkout@v3

- name: 📦 Install
uses: ./.github/actions/install
with:
node-version: 20
pnpm-version: 8.10.5

- name: 📦 Install Playwright Deps
run: pnpm exec playwright install --with-deps

- name: ✅ e2e
run: pnpm e2e
env:
BASE_URL: ${{ github.event.deployment_status.environment_url }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ storybook-static

# eslint
.eslintcache

# env
.env*
4 changes: 2 additions & 2 deletions e2e/app.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { expect, test } from '@playwright/test'

test('has title', async ({ page }) => {
await page.goto('http://localhost:5173/')
await page.goto('/')

await expect(page).toHaveTitle(/React Starter/)
})

test.describe('external links', () => {
test.beforeEach(async ({ page }) => {
await page.goto('http://localhost:5173/')
await page.goto('/')
})

test('opened vite docs', async ({ page, context }) => {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"@vitest/coverage-v8": "1.0.2",
"autoprefixer": "10.4.16",
"daisyui": "4.4.19",
"dotenv": "16.3.1",
"eslint": "8.55.0",
"eslint-config-prettier": "9.1.0",
"eslint-import-resolver-typescript": "3.6.1",
Expand Down
7 changes: 6 additions & 1 deletion playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import 'dotenv/config'

import { defineConfig, devices } from '@playwright/test'

const PORT = process.env.PORT ?? 5173
const BASE_URL = process.env.BASE_URL ?? `http://localhost:${PORT}`

export default defineConfig({
forbidOnly: Boolean(process.env.CI),
fullyParallel: true,
Expand All @@ -22,6 +27,6 @@ export default defineConfig({
reporter: 'html',
retries: process.env.CI ? 2 : 0,
testDir: './e2e',
use: { trace: 'on-first-retry' },
use: { trace: 'on-first-retry', baseURL: BASE_URL },
workers: process.env.CI ? 1 : undefined,
})
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 29 additions & 22 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,36 @@
import path from 'node:path'

import react from '@vitejs/plugin-react-swc'
import { defineConfig } from 'vite'
import { defineConfig, loadEnv } from 'vite'
import { configDefaults } from 'vitest/config'

export default defineConfig({
plugins: [react()],
resolve: { alias: { '@': path.resolve(__dirname, './src') } },
test: {
coverage: {
reporter: ['html', 'text-summary'],
exclude: [
'**/*.d.ts',
'storybook-static/**',
'.storybook/**',
'**/*.stories.*',
'**/main.tsx',
'{tailwind,postcss,playwright}.config.*',
'.{eslint,prettier}rc.{?(c|m)js,yml}',
'node_modules/.pnpm/**',
],
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), '')

return {
plugins: [react()],
resolve: { alias: { '@': path.resolve(__dirname, './src') } },
server: {
port: parseInt(env.PORT),
},
test: {
coverage: {
reporter: ['html', 'text-summary'],
exclude: [
'**/*.d.ts',
'storybook-static/**',
'.storybook/**',
'**/*.stories.*',
'**/main.tsx',
'{tailwind,postcss,playwright}.config.*',
'.{eslint,prettier}rc.{?(c|m)js,yml}',
'node_modules/.pnpm/**',
],
},
environment: 'happy-dom',
exclude: [...configDefaults.exclude, 'e2e/*'],
globals: true,
setupFiles: './src/test/setup.ts',
},
environment: 'happy-dom',
exclude: [...configDefaults.exclude, 'e2e/*'],
globals: true,
setupFiles: './src/test/setup.ts',
},
}
})

1 comment on commit 39c2a95

@vercel
Copy link

@vercel vercel bot commented on 39c2a95 Dec 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.