diff --git a/apps/auth/src/auth.controller.spec.ts b/apps/auth/src/auth.controller.spec.ts new file mode 100644 index 0000000..d59df3e --- /dev/null +++ b/apps/auth/src/auth.controller.spec.ts @@ -0,0 +1,22 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { AuthController } from './auth.controller'; +import { AuthService } from './auth.service'; + +describe('AuthController', () => { + let authController: AuthController; + + beforeEach(async () => { + const app: TestingModule = await Test.createTestingModule({ + controllers: [AuthController], + providers: [AuthService], + }).compile(); + + authController = app.get(AuthController); + }); + + describe('root', () => { + it('should return "Hello World!"', () => { + expect(authController.getHello()).toBe('Hello World!'); + }); + }); +}); diff --git a/apps/auth/src/auth.controller.ts b/apps/auth/src/auth.controller.ts new file mode 100644 index 0000000..758fe3b --- /dev/null +++ b/apps/auth/src/auth.controller.ts @@ -0,0 +1,12 @@ +import { Controller, Get } from '@nestjs/common'; +import { AuthService } from './auth.service'; + +@Controller() +export class AuthController { + constructor(private readonly authService: AuthService) {} + + @Get() + getHello(): string { + return this.authService.getHello(); + } +} diff --git a/apps/auth/src/auth.module.ts b/apps/auth/src/auth.module.ts new file mode 100644 index 0000000..03810e7 --- /dev/null +++ b/apps/auth/src/auth.module.ts @@ -0,0 +1,10 @@ +import { Module } from '@nestjs/common'; +import { AuthController } from './auth.controller'; +import { AuthService } from './auth.service'; + +@Module({ + imports: [], + controllers: [AuthController], + providers: [AuthService], +}) +export class AuthModule {} diff --git a/apps/auth/src/auth.service.ts b/apps/auth/src/auth.service.ts new file mode 100644 index 0000000..53400c8 --- /dev/null +++ b/apps/auth/src/auth.service.ts @@ -0,0 +1,8 @@ +import { Injectable } from '@nestjs/common'; + +@Injectable() +export class AuthService { + getHello(): string { + return 'Hello World!'; + } +} diff --git a/apps/auth/src/main.ts b/apps/auth/src/main.ts new file mode 100644 index 0000000..9572bdb --- /dev/null +++ b/apps/auth/src/main.ts @@ -0,0 +1,8 @@ +import { NestFactory } from '@nestjs/core'; +import { AuthModule } from './auth.module'; + +async function bootstrap() { + const app = await NestFactory.create(AuthModule); + await app.listen(6001); +} +bootstrap(); diff --git a/apps/auth/test/app.e2e-spec.ts b/apps/auth/test/app.e2e-spec.ts new file mode 100644 index 0000000..6eb0624 --- /dev/null +++ b/apps/auth/test/app.e2e-spec.ts @@ -0,0 +1,24 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { INestApplication } from '@nestjs/common'; +import * as request from 'supertest'; +import { AuthModule } from './../src/auth.module'; + +describe('AuthController (e2e)', () => { + let app: INestApplication; + + beforeEach(async () => { + const moduleFixture: TestingModule = await Test.createTestingModule({ + imports: [AuthModule], + }).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/apps/auth/test/jest-e2e.json similarity index 100% rename from test/jest-e2e.json rename to apps/auth/test/jest-e2e.json diff --git a/apps/auth/tsconfig.app.json b/apps/auth/tsconfig.app.json new file mode 100644 index 0000000..01d9c9a --- /dev/null +++ b/apps/auth/tsconfig.app.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "declaration": false, + "outDir": "../../dist/apps/auth" + }, + "include": ["src/**/*"], + "exclude": ["node_modules", "dist", "test", "**/*spec.ts"] +} diff --git a/src/app.controller.spec.ts b/apps/backend/src/app.controller.spec.ts similarity index 100% rename from src/app.controller.spec.ts rename to apps/backend/src/app.controller.spec.ts diff --git a/src/app.controller.ts b/apps/backend/src/app.controller.ts similarity index 100% rename from src/app.controller.ts rename to apps/backend/src/app.controller.ts diff --git a/src/app.module.ts b/apps/backend/src/app.module.ts similarity index 100% rename from src/app.module.ts rename to apps/backend/src/app.module.ts diff --git a/src/app.service.ts b/apps/backend/src/app.service.ts similarity index 100% rename from src/app.service.ts rename to apps/backend/src/app.service.ts diff --git a/src/main.ts b/apps/backend/src/main.ts similarity index 87% rename from src/main.ts rename to apps/backend/src/main.ts index 13cad38..add741b 100644 --- a/src/main.ts +++ b/apps/backend/src/main.ts @@ -3,6 +3,6 @@ import { AppModule } from './app.module'; async function bootstrap() { const app = await NestFactory.create(AppModule); - await app.listen(3000); + await app.listen(6000); } bootstrap(); diff --git a/test/app.e2e-spec.ts b/apps/backend/test/app.e2e-spec.ts similarity index 100% rename from test/app.e2e-spec.ts rename to apps/backend/test/app.e2e-spec.ts diff --git a/apps/backend/test/jest-e2e.json b/apps/backend/test/jest-e2e.json new file mode 100644 index 0000000..e9d912f --- /dev/null +++ b/apps/backend/test/jest-e2e.json @@ -0,0 +1,9 @@ +{ + "moduleFileExtensions": ["js", "json", "ts"], + "rootDir": ".", + "testEnvironment": "node", + "testRegex": ".e2e-spec.ts$", + "transform": { + "^.+\\.(t|j)s$": "ts-jest" + } +} diff --git a/apps/backend/tsconfig.app.json b/apps/backend/tsconfig.app.json new file mode 100644 index 0000000..ffc1047 --- /dev/null +++ b/apps/backend/tsconfig.app.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "declaration": false, + "outDir": "../../dist/apps/backend" + }, + "include": ["src/**/*"], + "exclude": ["node_modules", "dist", "test", "**/*spec.ts"] +} diff --git a/nest-cli.json b/nest-cli.json index f9aa683..61952b0 100644 --- a/nest-cli.json +++ b/nest-cli.json @@ -1,8 +1,32 @@ { "$schema": "https://json.schemastore.org/nest-cli", "collection": "@nestjs/schematics", - "sourceRoot": "src", + "sourceRoot": "apps/backend/src", "compilerOptions": { - "deleteOutDir": true + "deleteOutDir": true, + "webpack": true, + "tsConfigPath": "apps/backend/tsconfig.app.json" + }, + "monorepo": true, + "root": "apps/backend", + "projects": { + "backend": { + "type": "application", + "root": "apps/backend", + "entryFile": "main", + "sourceRoot": "apps/backend/src", + "compilerOptions": { + "tsConfigPath": "apps/backend/tsconfig.app.json" + } + }, + "auth": { + "type": "application", + "root": "apps/auth", + "entryFile": "main", + "sourceRoot": "apps/auth/src", + "compilerOptions": { + "tsConfigPath": "apps/auth/tsconfig.app.json" + } + } } -} +} \ No newline at end of file diff --git a/package.json b/package.json index b2a4ee7..497acf1 100644 --- a/package.json +++ b/package.json @@ -7,17 +7,17 @@ "license": "UNLICENSED", "scripts": { "build": "nest build", - "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", + "format": "prettier --write \"apps/**/*.ts\" \"libs/**/*.ts\"", "start": "nest start", "start:dev": "nest start --watch", "start:debug": "nest start --debug --watch", - "start:prod": "node dist/main", + "start:prod": "node dist/apps/backend/main", "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", "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:e2e": "jest --config ./apps/backend/test/jest-e2e.json" }, "dependencies": { "@nestjs/common": "^10.0.0", @@ -55,7 +55,7 @@ "json", "ts" ], - "rootDir": "src", + "rootDir": ".", "testRegex": ".*\\.spec\\.ts$", "transform": { "^.+\\.(t|j)s$": "ts-jest" @@ -63,7 +63,10 @@ "collectCoverageFrom": [ "**/*.(t|j)s" ], - "coverageDirectory": "../coverage", - "testEnvironment": "node" + "coverageDirectory": "./coverage", + "testEnvironment": "node", + "roots": [ + "/apps/" + ] } -} +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 95f5641..0828aa1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -16,6 +16,7 @@ "noImplicitAny": false, "strictBindCallApply": false, "forceConsistentCasingInFileNames": false, - "noFallthroughCasesInSwitch": false + "noFallthroughCasesInSwitch": false, + "paths": {} } -} +} \ No newline at end of file