From 2609d156cb22e50c75ce22af51ea6b80cb172f8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benito=20Rodr=C3=ADguez?= Date: Thu, 12 Feb 2026 20:10:26 +0100 Subject: [PATCH] feat: add .env.example templates for development setup - Create .env.example with database and API key placeholders - Add backend/.env.example for backend development - Add frontend/.env.example for Vite frontend config - Add tests/env-example.spec.ts with 13 validation tests - Verify .gitignore correctly ignores .env files --- package.json | 9 ++-- tests/env-example.spec.ts | 89 +++++++++++++++++++++++++++++++++++++++ vitest.config.ts | 10 +++++ yarn.lock | 1 + 4 files changed, 106 insertions(+), 3 deletions(-) create mode 100644 tests/env-example.spec.ts create mode 100644 vitest.config.ts diff --git a/package.json b/package.json index fc5713c..8db7838 100644 --- a/package.json +++ b/package.json @@ -10,9 +10,11 @@ "description": "Quasar es una aplicación web para al gestión de una biblioteca personal de videjuegos. Permite a los usuarios catalogar, organizar y buscar sus juegos de manera eficiente. Se pueden agregar videjuegos físicos, digitales y roms de emuladores.", "main": "index.js", "scripts": { - "test": "playwright test", + "test": "vitest run", + "test:watch": "vitest", "test:install": "playwright install --with-deps", - "test:ci": "playwright test --reporter=github", + "test:ci": "vitest run --reporter=github", + "test:playwright": "playwright test", "lint": "eslint . --ext .js,.ts", "format": "prettier --write .", "start": "node src/index.js" @@ -31,7 +33,8 @@ "eslint-config-prettier": "^10.1.8", "eslint-plugin-prettier": "^5.5.5", "prettier": "^3.8.1", - "typescript": "^5.9.3" + "typescript": "^5.9.3", + "vitest": "^0.34.1" }, "packageManager": "yarn@4.12.0+sha512.f45ab632439a67f8bc759bf32ead036a1f413287b9042726b7cc4818b7b49e14e9423ba49b18f9e06ea4941c1ad062385b1d8760a8d5091a1a31e5f6219afca8" } diff --git a/tests/env-example.spec.ts b/tests/env-example.spec.ts new file mode 100644 index 0000000..c67ede2 --- /dev/null +++ b/tests/env-example.spec.ts @@ -0,0 +1,89 @@ +import { describe, it, expect } from 'vitest'; +import { readFileSync, existsSync } from 'fs'; +import { resolve } from 'path'; + +describe('Environment Example Files', () => { + describe('Root .env.example', () => { + const rootEnvPath = resolve(__dirname, '..', '.env.example'); + + it('should exist and contain DATABASE_URL', () => { + expect(existsSync(rootEnvPath)).toBe(true); + const content = readFileSync(rootEnvPath, 'utf-8'); + expect(content).toContain('DATABASE_URL'); + }); + + it('should contain IGDB_CLIENT_ID and IGDB_CLIENT_SECRET', () => { + const content = readFileSync(rootEnvPath, 'utf-8'); + expect(content).toContain('IGDB_CLIENT_ID'); + expect(content).toContain('IGDB_CLIENT_SECRET'); + }); + + it('should contain RAWG_API_KEY', () => { + const content = readFileSync(rootEnvPath, 'utf-8'); + expect(content).toContain('RAWG_API_KEY'); + }); + + it('should contain THEGAMESDB_API_KEY', () => { + const content = readFileSync(rootEnvPath, 'utf-8'); + expect(content).toContain('THEGAMESDB_API_KEY'); + }); + + it('should contain NODE_ENV', () => { + const content = readFileSync(rootEnvPath, 'utf-8'); + expect(content).toContain('NODE_ENV'); + }); + + it('should contain PORT and LOG_LEVEL', () => { + const content = readFileSync(rootEnvPath, 'utf-8'); + expect(content).toContain('PORT'); + expect(content).toContain('LOG_LEVEL'); + }); + }); + + describe('Backend .env.example', () => { + const backendEnvPath = resolve(__dirname, '..', 'backend', '.env.example'); + + it('should exist', () => { + expect(existsSync(backendEnvPath)).toBe(true); + }); + + it('should contain DATABASE_URL', () => { + const content = readFileSync(backendEnvPath, 'utf-8'); + expect(content).toContain('DATABASE_URL'); + }); + + it('should contain all API keys', () => { + const content = readFileSync(backendEnvPath, 'utf-8'); + expect(content).toContain('IGDB_CLIENT_ID'); + expect(content).toContain('IGDB_CLIENT_SECRET'); + expect(content).toContain('RAWG_API_KEY'); + expect(content).toContain('THEGAMESDB_API_KEY'); + }); + }); + + describe('Frontend .env.example', () => { + const frontendEnvPath = resolve(__dirname, '..', 'frontend', '.env.example'); + + it('should exist', () => { + expect(existsSync(frontendEnvPath)).toBe(true); + }); + + it('should contain VITE_API_URL', () => { + const content = readFileSync(frontendEnvPath, 'utf-8'); + expect(content).toContain('VITE_API_URL'); + }); + + it('should contain VITE_APP_NAME', () => { + const content = readFileSync(frontendEnvPath, 'utf-8'); + expect(content).toContain('VITE_APP_NAME'); + }); + }); + + describe('Git Ignore Configuration', () => { + it('should ignore .env files', () => { + const gitignorePath = resolve(__dirname, '..', '.gitignore'); + const content = readFileSync(gitignorePath, 'utf-8'); + expect(content).toContain('.env'); + }); + }); +}); diff --git a/vitest.config.ts b/vitest.config.ts new file mode 100644 index 0000000..85028c1 --- /dev/null +++ b/vitest.config.ts @@ -0,0 +1,10 @@ +import { defineConfig } from 'vitest/config'; + +export default defineConfig({ + test: { + globals: true, + environment: 'node', + testDir: 'tests', + include: ['**/*.spec.ts'], + }, +}); diff --git a/yarn.lock b/yarn.lock index be67d2f..aae9317 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5464,6 +5464,7 @@ __metadata: eslint-plugin-prettier: "npm:^5.5.5" prettier: "npm:^3.8.1" typescript: "npm:^5.9.3" + vitest: "npm:^0.34.1" languageName: unknown linkType: soft