From d9b845974aa80986bb2b83ea7fba9654f3a038df Mon Sep 17 00:00:00 2001 From: susumu tomita Date: Thu, 16 May 2024 07:17:07 +0900 Subject: [PATCH] update test setup --- .github/workflows/ci.yml | 18 ++++++++++++++++++ .husky/pre-commit | 1 + jest.config.js | 1 + jest.setup.ts | 13 +++++++++++++ 4 files changed, 33 insertions(+) create mode 100644 jest.setup.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9de7aa8a..28a1c922 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 @@ -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 diff --git a/.husky/pre-commit b/.husky/pre-commit index 97c08f54..f2838d53 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -4,3 +4,4 @@ npm run lint-staged npm run format npm run textlint +npm run test diff --git a/jest.config.js b/jest.config.js index 64285879..d899c434 100644 --- a/jest.config.js +++ b/jest.config.js @@ -2,6 +2,7 @@ module.exports = { preset: 'ts-jest', coverageReporters: ['lcov'], testEnvironment: 'node', + setupFilesAfterEnv: ['/jest.setup.ts'], testPathIgnorePatterns: ['/.next/', '/node_modules/'], moduleNameMapper: { '\\.(css)$': '/node_modules/jest-css-modules', diff --git a/jest.setup.ts b/jest.setup.ts new file mode 100644 index 00000000..933ac09a --- /dev/null +++ b/jest.setup.ts @@ -0,0 +1,13 @@ +import { PrismaClient } from '@prisma/client'; + +const prisma = new PrismaClient(); + +beforeAll(async () => { + await prisma.$connect(); + // 必要に応じてデータベースの初期化やセットアップ +}); + +afterAll(async () => { + await prisma.$disconnect(); + // 必要に応じてデータベースのクリーンアップ +});