UNPKG

js-mvc-app

Version:

A CLI tool to scaffold complete Node.js MVC projects with TypeScript, just like Laravel

117 lines (106 loc) 3.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getJestConfig = getJestConfig; exports.getTestSetup = getTestSetup; exports.getTestExample = getTestExample; function getJestConfig() { return `module.exports = { preset: 'ts-jest', testEnvironment: 'node', roots: ['<rootDir>/src', '<rootDir>/tests'], testMatch: [ '**/__tests__/**/*.ts', '**/?(*.)+(spec|test).ts' ], transform: { '^.+\\.ts$': 'ts-jest' }, collectCoverageFrom: [ 'src/**/*.ts', '!src/**/*.d.ts', '!src/app.ts' ], coverageDirectory: 'coverage', coverageReporters: [ 'text', 'lcov', 'html' ], setupFilesAfterEnv: ['<rootDir>/tests/setup.ts'], testTimeout: 10000 }; `; } function getTestSetup() { return `import { connectDatabase, disconnectDatabase } from '../src/config/database'; // Setup database connection for tests beforeAll(async () => { // You might want to use a separate test database process.env.NODE_ENV = 'test'; await connectDatabase(); }); // Cleanup after tests afterAll(async () => { await disconnectDatabase(); }); // Clean up after each test afterEach(async () => { // Clear collections/tables if needed for isolation // This depends on your database choice }); `; } function getTestExample() { return `import request from 'supertest'; import app from '../src/app'; describe('API Health Check', () => { it('should return 200 for health endpoint', async () => { const response = await request(app) .get('/health') .expect(200); expect(response.body).toHaveProperty('status', 'ok'); expect(response.body).toHaveProperty('timestamp'); expect(response.body).toHaveProperty('uptime'); }); }); describe('Authentication Endpoints', () => { const testUser = { name: 'Test User', email: 'test@example.com', password: 'password123' }; it('should register a new user', async () => { const response = await request(app) .post('/api/auth/register') .send(testUser) .expect(201); expect(response.body).toHaveProperty('message', 'User registered successfully'); expect(response.body).toHaveProperty('token'); expect(response.body.user).toHaveProperty('email', testUser.email); expect(response.body.user).not.toHaveProperty('password'); }); it('should login with valid credentials', async () => { const response = await request(app) .post('/api/auth/login') .send({ email: testUser.email, password: testUser.password }) .expect(200); expect(response.body).toHaveProperty('message', 'Login successful'); expect(response.body).toHaveProperty('token'); expect(response.body.user).toHaveProperty('email', testUser.email); }); it('should fail login with invalid credentials', async () => { await request(app) .post('/api/auth/login') .send({ email: testUser.email, password: 'wrongpassword' }) .expect(401); }); }); `; } //# sourceMappingURL=testing.js.map