diff --git a/jest.config.ts b/jest.config.ts new file mode 100644 index 0000000..33ea88f --- /dev/null +++ b/jest.config.ts @@ -0,0 +1,32 @@ +import type { Config } from '@jest/types'; + +const config: Config.InitialOptions = { + preset: 'ts-jest', + verbose: true, + moduleFileExtensions: ['js', 'json', 'ts'], + rootDir: '.', + roots: ['/src/'], + testRegex: '.*\\.spec\\.ts$', + transform: { + '^.+\\.(t|j)s$': 'ts-jest', + }, + collectCoverageFrom: ['/src/**/*.(t|j)s'], + coveragePathIgnorePatterns: [ + '.*.controller.ts', + '.*.module.ts', + '.*.entity.ts', + '.*.dto.ts', + '.*.spec.ts', + '.*.module-definition.ts', + '.*.configuration.ts', + '.*.configuration.model.ts', + '.*./main.ts', + 'node_modules', + ], + coverageDirectory: './coverage', + testEnvironment: 'node', + moduleNameMapper: { + '@/(.*)': '/src/$1', + }, +}; +export default config; diff --git a/package.json b/package.json index 8ad79ce..2a781ec 100644 --- a/package.json +++ b/package.json @@ -20,8 +20,7 @@ "test": "jest", "test:watch": "jest --watch", "test:cov": "jest --coverage", - "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", - "test:e2e": "jest --config ./test/jest-e2e.json" + "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand" }, "dependencies": { "@nestjs/common": "^9.0.0", @@ -66,23 +65,6 @@ "webpack": "^5.91.0", "webpack-node-externals": "^3.0.0" }, - "jest": { - "moduleFileExtensions": [ - "js", - "json", - "ts" - ], - "rootDir": "src", - "testRegex": ".*\\.spec\\.ts$", - "transform": { - "^.+\\.(t|j)s$": "ts-jest" - }, - "collectCoverageFrom": [ - "**/*.(t|j)s" - ], - "coverageDirectory": "../coverage", - "testEnvironment": "node" - }, "lint-staged": { "*.ts": [ "eslint --fix", diff --git a/src/app.controller.spec.ts b/src/app.controller.spec.ts index 6c11a50..9f13938 100644 --- a/src/app.controller.spec.ts +++ b/src/app.controller.spec.ts @@ -1,6 +1,7 @@ import { Test, TestingModule } from '@nestjs/testing'; import { AppController } from '@/app.controller'; import { AppService } from '@/app.service'; +import { ServiceStatus } from '@/common/enum'; describe('AppController', () => { let appController: AppController; @@ -14,9 +15,7 @@ describe('AppController', () => { appController = app.get(AppController); }); - describe('root', () => { - it('should return "Hello World!"', () => { - expect(appController.getHello()).toBe('Hello World!'); - }); + it(`should return "${ServiceStatus.HEALTHY}"`, () => { + expect(appController.getHealth()).toBe(ServiceStatus.HEALTHY); }); }); diff --git a/src/app.controller.ts b/src/app.controller.ts index ae6ba65..91597a1 100644 --- a/src/app.controller.ts +++ b/src/app.controller.ts @@ -5,8 +5,8 @@ import { AppService } from '@/app.service'; export class AppController { constructor(private readonly appService: AppService) {} - @Get() - getHello(): string { - return this.appService.getHello(); + @Get('/health') + getHealth(): string { + return this.appService.getHealth(); } } diff --git a/src/app.service.ts b/src/app.service.ts index 5b6a7be..e84b478 100644 --- a/src/app.service.ts +++ b/src/app.service.ts @@ -1,8 +1,9 @@ import { Injectable } from '@nestjs/common'; +import { ServiceStatus } from '@/common/enum'; @Injectable() export class AppService { - getHello(): string { - return 'Hello World!!'; + getHealth(): string { + return ServiceStatus.HEALTHY; } } diff --git a/src/common/enum.ts b/src/common/enum.ts new file mode 100644 index 0000000..9052c44 --- /dev/null +++ b/src/common/enum.ts @@ -0,0 +1,3 @@ +export enum ServiceStatus { + HEALTHY = 'HEALTHY', +} diff --git a/test/app.e2e-spec.ts b/test/app.e2e-spec.ts deleted file mode 100644 index 255c318..0000000 --- a/test/app.e2e-spec.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { INestApplication } from '@nestjs/common'; -import * as request from 'supertest'; -import { AppModule } from '@/app.module'; - -describe('AppController (e2e)', () => { - let app: INestApplication; - - beforeEach(async () => { - const moduleFixture: TestingModule = await Test.createTestingModule({ - imports: [AppModule], - }).compile(); - - app = moduleFixture.createNestApplication(); - await app.init(); - }); - - it('/ (GET)', () => { - return request(app.getHttpServer()) - .get('/') - .expect(200) - .expect('Hello World!!'); - }); -}); diff --git a/test/jest-e2e.json b/test/jest-e2e.json deleted file mode 100644 index e9d912f..0000000 --- a/test/jest-e2e.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "moduleFileExtensions": ["js", "json", "ts"], - "rootDir": ".", - "testEnvironment": "node", - "testRegex": ".e2e-spec.ts$", - "transform": { - "^.+\\.(t|j)s$": "ts-jest" - } -}