Skip to content

Commit

Permalink
Merge pull request #8 from gonta1026/feature/set_up
Browse files Browse the repository at this point in the history
feat: prismaのsetup, e2eテストのsetup,
  • Loading branch information
gonta1026 authored Jul 20, 2024
2 parents 81bd13f + 9cdd507 commit 553a5d2
Show file tree
Hide file tree
Showing 18 changed files with 489 additions and 12 deletions.
7 changes: 7 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Environment variables declared in this file are automatically made available to Prisma.
# See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema

# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings

DATABASE_URL="postgresql://root:password@localhost:5434/next-template?schema=public"
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ yarn-error.log*
# typescript
*.tsbuildinfo
next-env.d.ts

## 以下追加分
test-results
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ npm install -g git-cz

```
git cz
```
```

### db set up
15 changes: 15 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: "3.8"
services:
dev-postgres:
image: postgres:16.3-alpine
ports:
- 5434:5432
environment:
POSTGRES_USER: root
POSTGRES_PASSWORD: password
POSTGRES_DB: next-template
restart: always
networks:
- lesson
networks:
lesson:
2 changes: 1 addition & 1 deletion lefthook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pre-push:
run: yarn tsc
test:
tags: test
run: yarn test run
run: yarn test:vitest

pre-commit:
parallel: true
Expand Down
19 changes: 16 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,38 @@
"start": "next start",
"format": "biome format . --write",
"lint": "biome lint ./src/**",
"test": "vitest"
"test:e2e": "playwright test",
"test:vitest": "vitest run",
"test": "npm-run-all --parallel --continue-on-error --print-name test:*",
"seed": "ts-node --compiler-options '{\"module\":\"CommonJS\"}' prisma/seed.ts",
"seed2": "ts-node prisma/seed.mjs",
"reset": "ts-node prisma/reset.ts"
},
"dependencies": {
"@heroicons/react": "^2.1.5",
"@prisma/client": "^5.16.2",
"date-fns": "^3.6.0",
"next": "14.2.5",
"react": "^18",
"react-dom": "^18"
"react-dom": "^18",
"zod": "^3.23.8"
},
"devDependencies": {
"@biomejs/biome": "1.8.3",
"@playwright/test": "^1.45.1",
"@testing-library/dom": "^10.3.1",
"@testing-library/jest-dom": "^6.4.6",
"@testing-library/react": "^16.0.0",
"@types/node": "^20",
"@types/node": "^20.14.11",
"@types/react": "^18",
"@types/react-dom": "^18",
"@vitejs/plugin-react": "^4.3.1",
"jsdom": "^24.1.0",
"lefthook": "^1.7.2",
"npm-run-all2": "^6.2.2",
"prisma": "^5.16.2",
"sass": "^1.77.8",
"ts-node": "^10.9.2",
"typescript": "5.5.3",
"vitest": "^2.0.2"
}
Expand Down
68 changes: 68 additions & 0 deletions playwright-report/index.html

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import type { PlaywrightTestConfig } from '@playwright/test'
// biome-ignore lint/style/useNodejsImportProtocol: <explanation>
import path from 'path'

const PORT = process.env.PORT || 3000
const baseURL = `http://localhost:${PORT}`

const config: PlaywrightTestConfig = {
timeout: 5 * 1000,
testDir: path.join(__dirname, 'src/e2e'),
retries: 0,
webServer: {
command: 'npm start',
url: baseURL,
timeout: 120 * 1000,
reuseExistingServer: true,
},
// globalSetup: './e2e/config/globalSetup.ts',
use: {
baseURL,
// storageState: './e2e/config/storageState.json',
},
// reporter: [['html', { open: 'always' }]],
// projects: [
// {
// name: 'Desktop Chrome',
// use: {
// ...devices['Desktop Chrome'],
// },
// },
// ],
}
export default config
12 changes: 12 additions & 0 deletions prisma/migrations/20240720143513_init/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- CreateTable
CREATE TABLE "User" (
"id" SERIAL NOT NULL,
"email" TEXT NOT NULL,
"name" TEXT NOT NULL,
"hashedPassword" TEXT NOT NULL,

CONSTRAINT "User_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "User_email_key" ON "User"("email");
3 changes: 3 additions & 0 deletions prisma/migrations/migration_lock.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
provider = "postgresql"
5 changes: 5 additions & 0 deletions prisma/reset.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { PrismaClient } from '@prisma/client'

export const reset = async (prisma: PrismaClient) => {
await prisma.user.deleteMany({})
}
16 changes: 16 additions & 0 deletions prisma/schema/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init

generator client {
provider = "prisma-client-js"
previewFeatures = ["prismaSchemaFolder"]
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}

6 changes: 6 additions & 0 deletions prisma/schema/user.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
model User {
id Int @id @default(autoincrement())
email String @unique
name String
hashedPassword String
}
26 changes: 26 additions & 0 deletions prisma/seed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { PrismaClient } from '@prisma/client'
import { reset } from './reset'

const prisma = new PrismaClient()

async function main() {
await reset(prisma)
await prisma.user.create({
data: {
id: 1,
name: '東京駅内の店',
email: 'test@example.com',
hashedPassword: 'ssss',
},
})
}

main()
.then(async () => {
await prisma.$disconnect()
})
.catch(async (e) => {
console.error(e)
await prisma.$disconnect()
process.exit(1)
})
5 changes: 5 additions & 0 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ import Image from 'next/image'
import Link from 'next/link'
import styles from './page.module.scss'

export const metadata = {
title: 'e2e lesson',
}

export default function Home() {
return (
<main className={styles.main}>
<h1>Hello World🚀</h1>
<div className={styles.description}>
<p>
Get started by editing&nbsp;
Expand Down
7 changes: 7 additions & 0 deletions src/e2e/index-page.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { test, expect } from '@playwright/test'

test('Shall render hello world', async ({ page }) => {
await page.goto('/')
await expect(page).toHaveTitle('e2e lesson')
await expect(page.locator('h1')).toHaveText('Hello World🚀')
})
1 change: 1 addition & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default defineConfig({
test: {
environment: 'jsdom',
setupFiles: './vitest.setup.ts',
include: ['./src/**/*.test.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
},
resolve: {
alias: [{ find: '@', replacement: resolve(__dirname, './src') }],
Expand Down
Loading

0 comments on commit 553a5d2

Please sign in to comment.