Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/vitest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: 'vitest test'
on:
pull_request:
paths:
- "**/*.spec.ts"

jobs:
Component-test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Node.js and pnpm
uses: ./.github/actions/pnpm-setup-node

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: run vitest
run: pnpm test
6 changes: 6 additions & 0 deletions apps/web/app/_utils/sum/sum.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { expect, test } from 'vitest'
import sum from './sum'

test('adds 1 + 2 to equal 3', () => {
expect(sum(1, 2)).toBe(3)
})
4 changes: 4 additions & 0 deletions apps/web/app/_utils/sum/sum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Todo: test용으로 이후 sum 폴더 전체 삭제

const sum = (a: number, b: number) => a + b
export default sum
14 changes: 12 additions & 2 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"build": "next build",
"start": "next start",
"lint": "next lint --max-warnings 0",
"check-types": "tsc --noEmit"
"check-types": "tsc --noEmit",
"test": "vitest run",
"test:watch": "vitest --watch"
},
"dependencies": {
"@repo/ui": "workspace:*",
Expand All @@ -27,13 +29,21 @@
"@repo/tailwind-config": "workspace:*",
"@repo/typescript-config": "workspace:*",
"@tailwindcss/postcss": "^4.1.5",
"@testing-library/dom": "^10.4.1",
"@testing-library/jest-dom": "^6.6.4",
"@testing-library/react": "^16.3.0",
"@testing-library/user-event": "^14.6.1",
"@types/node": "^22.15.30",
"@types/react": "^19.1.0",
"@types/react-dom": "^19.1.1",
"@vitejs/plugin-react": "^4.7.0",
"autoprefixer": "^10.4.20",
"eslint": "^9.32.0",
"jsdom": "^26.1.0",
"postcss": "^8.5.3",
"tailwindcss": "^4.1.5",
"typescript": "5.8.2"
"typescript": "5.8.2",
"vite-tsconfig-paths": "^5.1.4",
"vitest": "^3.2.4"
}
}
13 changes: 11 additions & 2 deletions apps/web/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,23 @@
{
"name": "next"
}
]
],
"types": ["vitest/globals","vitest/jsdom"],
/* alias */
"baseUrl": ".",
"paths": {
"@/*": ["src/*"]
}
},
"include": [
"**/*.ts",
"**/*.tsx",
"next-env.d.ts",
"next.config.ts",
".next/types/**/*.ts"
".next/types/**/*.ts",
"vitest.config.ts",
"vitest.setup.ts"
],

"exclude": ["node_modules"]
}
12 changes: 12 additions & 0 deletions apps/web/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { defineConfig } from 'vitest/config'
import react from '@vitejs/plugin-react'
import tsconfigPaths from 'vite-tsconfig-paths'

export default defineConfig({
plugins: [tsconfigPaths(), react()],
test: {
globals: true,
environment: 'jsdom',
setupFiles: './vitest.setup.ts',
},
})
16 changes: 16 additions & 0 deletions apps/web/vitest.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import '@testing-library/jest-dom/vitest'

// https://github.com/vitest-dev/vitest/issues/821
Object.defineProperty(window, 'matchMedia', {
writable: true,
value: vi.fn().mockImplementation((query) => ({
matches: false,
media: query,
onchange: null,
addListener: vi.fn(), // deprecated
removeListener: vi.fn(), // deprecated
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
dispatchEvent: vi.fn(),
})),
})
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"dev": "turbo run dev",
"lint": "turbo run lint",
"check-types": "turbo run check-types",
"format": "prettier --write \"**/*.{ts,tsx,md}\""
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
"test": "turbo run test",
"test:watch": "turbo run test:watch"
},
"devDependencies": {
"@commitlint/cli": "^19.8.1",
Expand Down
Loading