integration testing with sqlite

This commit is contained in:
Maxime Cannoodt 2022-07-09 12:26:49 +02:00
parent 2be7bfcaee
commit 5e2da1db6d
7 changed files with 2058 additions and 6 deletions

1
server/.env.test Normal file
View File

@ -0,0 +1 @@
DATABASE_URL="file:./test.sqlite"

1
server/.gitignore vendored
View File

@ -1,2 +1,3 @@
node_modules node_modules
build build
!.env.test

2045
server/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -6,6 +6,11 @@
"scripts": { "scripts": {
"test-watch": "vitest", "test-watch": "vitest",
"test": "vitest run", "test": "vitest run",
"test:unit": "vitest run unit",
"test:integration": "run-s db:test:migrate test:integration:test db:test:cleanup",
"test:integration:test": "dotenv -e .env.test -- vitest run integration --coverage --no-threads",
"db:test:migrate": "dotenv -e .env.test -- npx prisma db push",
"db:test:cleanup": "rm ./prisma/test.sqlite",
"coverage": "vitest run --coverage", "coverage": "vitest run --coverage",
"build": "npx tsc", "build": "npx tsc",
"dev": "npx nodemon ./server.ts | npx pino-colada" "dev": "npx nodemon ./server.ts | npx pino-colada"
@ -28,7 +33,10 @@
"@types/node": "^18.0.0", "@types/node": "^18.0.0",
"@types/sqlite3": "^3.1.8", "@types/sqlite3": "^3.1.8",
"@types/supertest": "^2.0.12", "@types/supertest": "^2.0.12",
"c8": "^7.11.3",
"dotenv-cli": "^6.0.0",
"nodemon": "^2.0.18", "nodemon": "^2.0.18",
"npm-run-all": "^4.1.5",
"pino-colada": "^2.2.2", "pino-colada": "^2.2.2",
"prisma": "^4.0.0", "prisma": "^4.0.0",
"supertest": "^6.2.3", "supertest": "^6.2.3",

View File

@ -1,14 +1,14 @@
import "dotenv/config"; import "dotenv/config";
import express, { Express, Request } from "express"; import express, { Express, Request } from "express";
import { PrismaClient, EncryptedNote } from "@prisma/client"; import { EncryptedNote } from "@prisma/client";
import { addDays } from "./util"; import { addDays } from "./util";
import helmet from "helmet"; import helmet from "helmet";
import rateLimit from "express-rate-limit"; import rateLimit from "express-rate-limit";
import pinoHttp from "pino-http"; import pinoHttp from "pino-http";
import logger from "./logger"; import logger from "./logger";
import prisma from "./client";
// Initialize middleware clients // Initialize middleware clients
const prisma = new PrismaClient();
const app: Express = express(); const app: Express = express();
app.use(express.json()); app.use(express.json());

5
server/src/client.ts Normal file
View File

@ -0,0 +1,5 @@
import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();
export default prisma;