Skip to content

Commit

Permalink
update test setup
Browse files Browse the repository at this point in the history
  • Loading branch information
susumutomita committed May 15, 2024
1 parent 4b71582 commit d9b8459
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@ jobs:
build:
name: Build and Test
runs-on: ubuntu-latest

services:
postgres:
image: postgres:latest
env:
POSTGRES_USER: user
POSTGRES_PASSWORD: password
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U user"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Check out code
uses: actions/checkout@v4
Expand All @@ -34,6 +49,9 @@ jobs:
- name: Run ESLint
run: npm run lint

- name: Setup database
run: npm run db:setup

- name: Run tests with coverage
run: npm run test:coverage

Expand Down
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
npm run lint-staged
npm run format
npm run textlint
npm run test
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module.exports = {
preset: 'ts-jest',
coverageReporters: ['lcov'],
testEnvironment: 'node',
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
testPathIgnorePatterns: ['<rootDir>/.next/', '<rootDir>/node_modules/'],
moduleNameMapper: {
'\\.(css)$': '<rootDir>/node_modules/jest-css-modules',
Expand Down
13 changes: 13 additions & 0 deletions jest.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { PrismaClient } from '@prisma/client';

const prisma = new PrismaClient();

beforeAll(async () => {
await prisma.$connect();
// 必要に応じてデータベースの初期化やセットアップ
});

afterAll(async () => {
await prisma.$disconnect();
// 必要に応じてデータベースのクリーンアップ
});

0 comments on commit d9b8459

Please sign in to comment.