Skip to content

Commit

Permalink
Merge pull request #48 from boostcampwm-2024/chore/test-env-be
Browse files Browse the repository at this point in the history
🐛 fix: 통합, E2E, Unit 테스트 환경 구축
  • Loading branch information
Jo-Minseok authored Nov 7, 2024
2 parents 13acbca + abf5ce3 commit e079ae7
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 25 deletions.
18 changes: 8 additions & 10 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,21 @@ jobs:
key: ${{ secrets.SSH_KEY }}
port: ${{ secrets.PORT }}
script: |
node -v
export NVM_DIR=~/.nvm
source ~/.nvm/nvm.sh
node -v
cd /root/web05-Denamu
git pull origin main
cd server/
mkdir -p src/configs
mkdir -p configs
echo "DB_TYPE=mysql" > src/configs/.env.db.production
echo "DB_DATABASE=${{ secrets.PRODUCT_DB_DATABASE }}" >> src/configs/.env.db.production
echo "DB_HOST=${{ secrets.PRODUCT_DB_HOST }}" >> src/configs/.env.db.production
echo "DB_PORT=${{ secrets.PRODUCT_DB_PORT }}" >> src/configs/.env.db.production
echo "DB_USERNAME=${{ secrets.PRODUCT_DB_USERNAME }}" >>src/configs/.env.db.production
echo "DB_PASSWORD=${{ secrets.PRODUCT_DB_PASSWORD }}" >> src/configs/.env.db.production
echo "DB_TYPE=mysql" > configs/.env.db.production
echo "DB_DATABASE=${{ secrets.PRODUCT_DB_DATABASE }}" >> configs/.env.db.production
echo "DB_HOST=${{ secrets.PRODUCT_DB_HOST }}" >> configs/.env.db.production
echo "DB_PORT=${{ secrets.PRODUCT_DB_PORT }}" >> configs/.env.db.production
echo "DB_USERNAME=${{ secrets.PRODUCT_DB_USERNAME }}" >> configs/.env.db.production
echo "DB_PASSWORD=${{ secrets.PRODUCT_DB_PASSWORD }}" >> configs/.env.db.production
npm ci
npm build
npm run build
nohup npm run start > server.log 2>&1 &
File renamed without changes.
3 changes: 2 additions & 1 deletion server/test/jest-e2e.json → server/jest-e2e.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
"testRegex": ".e2e-spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
}
},
"coverageDirectory": "coverage"
}
11 changes: 11 additions & 0 deletions server/jest-unit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"moduleFileExtensions": ["js", "json", "ts"],
"rootDir": "..",
"testEnvironment": "node",
"testPathIgnorePatterns": [".e2e-spec.ts$"],
"testRegex": ".spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"coverageDirectory": "coverage"
}
11 changes: 7 additions & 4 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
"start:dev": "cross-env NODE_ENV=development nest start --watch",
"start:debug": "cross-env NODE_ENV=development nest start --debug --watch",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test:unit": "cross-env NODE_ENV=test jest --config jest-unit.json",
"test:unit:cov": "cross-env NODE_ENV=test jest --config jest-unit.json --coverage",
"test:e2e": "cross-env NODE_ENV=test jest --config jest-e2e.json",
"test:e2e:cov": "cross-env NODE_ENV=test jest --config jest-e2e.json --coverage",
"test": "cross-env NODE_ENV=test jest",
"test:watch": "cross-env NODE_ENV=test jest --watch",
"test:cov": "cross-env NODE_ENV=test jest --coverage",
"test:debug": "cross-env NODE_ENV=test node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "cross-env NODE_ENV=test jest --config ./test/jest-e2e.json"
"test:debug": "cross-env NODE_ENV=test node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand"
},
"dependencies": {
"@nestjs/common": "^10.0.0",
Expand Down Expand Up @@ -65,8 +68,8 @@
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".*\\.spec\\.ts$",
"rootDir": "test",
"testRegex": ".*\\.(e2e-spec|spec)\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
Expand Down
2 changes: 1 addition & 1 deletion server/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { loadDBSetting } from './common/database/load.config';
winstonModule,
ConfigModule.forRoot({
isGlobal: true,
envFilePath: `${__dirname}/src/configs/.env.db.${process.env.NODE_ENV === 'test' ? 'test' : 'production'}`,
envFilePath: `${process.cwd()}/configs/.env.db.${process.env.NODE_ENV === 'test' ? 'test' : 'production'}`,
}),
TypeOrmModule.forRootAsync({
imports: [ConfigModule],
Expand Down
4 changes: 2 additions & 2 deletions server/src/blog/blog.entity.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Feed } from 'src/feed/feed.entity';
import { RssInformation } from 'src/rss/rss.entity';
import { Feed } from '../feed/feed.entity';
import { RssInformation } from '../rss/rss.entity';
import { Entity, OneToMany } from 'typeorm';

@Entity({
Expand Down
2 changes: 1 addition & 1 deletion server/src/common/database/load.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function loadDBSetting(configService: ConfigService) {
const port = configService.get<number>('DB_PORT');
const username = configService.get<string>('DB_USERNAME');
const password = configService.get<string>('DB_PASSWORD');
const entities = [__dirname + '/../**/*.entity.{js,ts}'];
const entities = [`${__dirname}/../../**/*.entity.{js,ts}`];
const synchronize = true;
const logging = process.env.NODE_ENV === 'production' ? false : true;

Expand Down
4 changes: 2 additions & 2 deletions server/src/feed/feed.entity.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Blog } from 'src/blog/blog.entity';
import {
BaseEntity,
Column,
Expand All @@ -7,6 +6,7 @@ import {
ManyToOne,
PrimaryGeneratedColumn,
} from 'typeorm';
import { Blog } from '../blog/blog.entity';

@Entity({ name: 'feed' })
export class Feed extends BaseEntity {
Expand All @@ -15,7 +15,7 @@ export class Feed extends BaseEntity {

@Column({
name: 'created_at',
type: 'timestamp',
type: 'datetime',
nullable: false,
})
createdAt: Date;
Expand Down
6 changes: 3 additions & 3 deletions server/test/app.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Test, TestingModule } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import * as request from 'supertest';
import { AppModule } from './../src/app.module';
import { AppModule } from '../src/app.module';

describe('AppController (e2e)', () => {
let app: INestApplication;
Expand All @@ -18,7 +18,7 @@ describe('AppController (e2e)', () => {
it('/ (GET)', () => {
return request(app.getHttpServer())
.get('/')
.expect(200)
.expect('Hello World!');
.expect(404)
.expect('Not Found');
});
});
7 changes: 7 additions & 0 deletions server/test/test.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { add } from '../src/test';

describe('test', () => {
test('1', () => {
expect(add(1, 1)).toBe(2);
});
});
2 changes: 1 addition & 1 deletion server/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"target": "ES2021",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
"baseUrl": "..",
"incremental": true,
"skipLibCheck": true,
"strictNullChecks": false,
Expand Down

0 comments on commit e079ae7

Please sign in to comment.