Skip to content

Commit

Permalink
* change jest setting (jest 설정 변경)
Browse files Browse the repository at this point in the history
  • Loading branch information
geunyoungno committed Mar 4, 2024
1 parent f55e665 commit b0c24d1
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 60 deletions.
11 changes: 3 additions & 8 deletions .prettierrc
Expand Up @@ -12,15 +12,10 @@
}
},
{
"files": [
".vscode/launch.json",
".vscode/settings.json",
"tsconfig.prod.json",
"tsconfig.json",
".prettierrc"
],
"files": [".vscode/launch.json", ".vscode/settings.json", "tsconfig.prod.json", "tsconfig.json", ".prettierrc"],
"options": {
"parser": "jsonc"
"parser": "json",
"trailingComma": "none"
}
}
]
Expand Down
2 changes: 1 addition & 1 deletion .vscode/launch.json
Expand Up @@ -9,6 +9,6 @@
"request": "attach",
"name": "Attach",
"port": 9229
},
}
]
}
4 changes: 2 additions & 2 deletions jest.config.ts
Expand Up @@ -22,7 +22,7 @@ const config: Config = {
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths , { prefix: '<rootDir>/' } ),

// The root directory that Jest should scan for tests and modules within
rootDir: "src",
// rootDir: "src",


// A list of paths to modules that run some code to configure or set up the testing framework before each test
Expand All @@ -44,7 +44,7 @@ const config: Config = {
],

// The regexp pattern or array of patterns that Jest uses to detect test files
"testRegex": ".*\\.spec\\.ts$",
// "testRegex": ".*\\.spec\\.ts$",

// A map from regular expressions to paths to transformers
transform: {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -13,7 +13,7 @@
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest --config ./jest.config.js",
"test": "jest --config ./jest.config.ts",
"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",
Expand Down
8 changes: 4 additions & 4 deletions src/controllers/healths/health.controller.spec.ts
@@ -1,24 +1,24 @@
import { AppModule } from '#app.module';
import { HealthController } from '#controllers/healths/health.controller';
import { ResHealthDto } from '#dtos/healths/ResHealthDto';
import { Test, TestingModule } from '@nestjs/testing';



describe('HealthController', () => {
let controller: HealthController;
const now = new Date();

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [HealthController],
imports: [AppModule]
}).compile();

jest.useFakeTimers();
jest.setSystemTime(now);

controller = module.get<HealthController>(HealthController);
});

it('should be "ResHealthDto"', () => {
expect(controller.getHealth()).toBe(new ResHealthDto({runMode: 'local', 'timestamp': now.toISOString()}));
expect(controller.getHealth()).toStrictEqual(new ResHealthDto({runMode: 'local', 'timestamp': now.toISOString()}));
});
});
2 changes: 1 addition & 1 deletion src/controllers/healths/health.controller.ts
Expand Up @@ -8,6 +8,6 @@ export class HealthController {

@Get('/')
getHealth(): ResHealthDto {
return this.healthService.read();
return new ResHealthDto(this.healthService.read());
}
}
3 changes: 2 additions & 1 deletion src/providers/healths/health.service.spec.ts
Expand Up @@ -11,13 +11,14 @@ describe('HealthService', () => {
providers: [HealthService],
}).compile();

jest.useFakeTimers();
jest.setSystemTime(now);

service = module.get<HealthService>(HealthService);
});

it('should be "IResHealthDto"', () => {
expect(service.read()).toBe({
expect(service.read()).toStrictEqual({
runMode: 'local',
timestamp: now.toISOString(),
} satisfies IResHealthDto);
Expand Down
49 changes: 7 additions & 42 deletions tsconfig.json
@@ -1,77 +1,42 @@
{
// 확장 설정: Node.js 20 환경을 기반으로 하는 tsconfig.json 확장
"extends": "@tsconfig/node20/tsconfig.json",
// ts-node 설정: 타입 체크 생략하여 실행 속도 향상
"ts-node": {
// 타입 체크 생략
"transpileOnly": true,
// 파일 사용 여부
"files": true,
"compilerOptions": {
// 여기에 지정된 compilerOptions는 아래에 선언된 옵션을 재정의하지만,
// 오직 ts-node에서만 적용됩니다.
// 하나의 tsconfig.json으로 ts-node와 tsc가 서로 다른 옵션을 사용하도록 하려면 유용합니다.
},
"compilerOptions": {}
},
// 컴파일러 옵션 설정
"compilerOptions": {
// "module": "commonjs",
// 사용할 라이브러리 추가
"module": "ESNext",
"moduleResolution": "Node",
"lib": ["ES2022"],
// 선언 파일 생성
"declaration": true,
// 주석 제거
"removeComments": true,
// 데코레이터 메타데이터 출력
"emitDecoratorMetadata": true,
// 실험적 데코레이터 활성화
"experimentalDecorators": true,
// 합성된 기본 가져오기 허용
"allowSyntheticDefaultImports": true,
// "target": "ES2021",
// 소스 맵 생성
"sourceMap": true,
// 출력 디렉터리 지정
"outDir": "./dist",
// baseUrl 설정
"baseUrl": "./",
// 증분 컴파일 활성화
"incremental": true,
// 라이브러리 검사 생략
"skipLibCheck": true,
// 엄격한 모드 활성화
"strict": true,
// null 체크 엄격화
"strictNullChecks": true,
// 암시적 any 금지
"noImplicitAny": false,
// 엄격한 함수 호출/바인딩/적용 규칙 미적용
"strictBindCallApply": false,
// 파일 이름에서 일관된 캐싱 강제 적용
"forceConsistentCasingInFileNames": true,
// switch 문에서 fallthrough 금지
"noFallthroughCasesInSwitch": true,
// 사용되지 않는 로컬 변수 사용 금지
"noUnusedLocals": true,
// 사용되지 않는 매개변수 사용 금지
"noUnusedParameters": true,
// 암시적 반환 금지
"noImplicitReturns": true,
// JSON 모듈 해석 활성화
"resolveJsonModule": true,
// path alias 설정
// #을 prefix 로 설정한 이유는 아래 내용을 참조하였습니다
// NOTE: https://github.com/nodejs/node/issues/49182
"paths": {
"#app.module": ["src/app.module"],
//

"#controllers/*": ["src/controllers/*"],
"#dtos/*": ["src/dtos/*"],
"#providers/*": ["src/providers/*"],
},
"#providers/*": ["src/providers/*"]
}
},
// 포함할 파일 경로 설정
"include": ["src/**/*"],
// 제외할 파일 경로 설정
"exclude": ["dist/**", "test/**"],
"exclude": ["dist/**", "test/**"]
}

0 comments on commit b0c24d1

Please sign in to comment.