Skip to content

Commit

Permalink
feat: E2E 테스트가 병렬적으로 수행될 수 있도록 구현
Browse files Browse the repository at this point in the history
- E2E 테스트 속도 54.32% 증가
- 각 테스트가 uuid값으로 임시 테스트 데이터베이스를 생성하고 테스트 완료 후 삭제
- test:e2e명령어 runInBand(순차적 테스트 실행)삭제
  • Loading branch information
choyoungwoo9 committed Aug 12, 2024
1 parent f111794 commit 7defc0f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"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 --runInBand"
"test:e2e": "jest --config ./test/jest-e2e.json"
},
"dependencies": {
"@nestjs/common": "^10.0.0",
Expand Down
28 changes: 28 additions & 0 deletions backend/test/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { io } from 'socket.io-client';
import { Member } from 'src/member/entity/member.entity';
import { MemberService } from 'src/member/service/member.service';
import * as portfinder from 'portfinder';
import { v4 as uuidv4 } from 'uuid';

export let app: INestApplication;
export let githubApiService: GithubApiService;
Expand Down Expand Up @@ -178,7 +179,33 @@ export const listenAppAndSetPortEnv = async (app) => {
process.env.PORT = port.toString();
};

const createDatabase = async (dbName: string) => {
const normalDataSource = getDataSource();
await normalDataSource.initialize();
await normalDataSource.query(`CREATE DATABASE \`${dbName}\`;`);
await normalDataSource.destroy();
};

const dropDatabase = async (dbName: string) => {
const normalDataSource = getDataSource();
await normalDataSource.initialize();
await normalDataSource.query(`DROP DATABASE IF EXISTS \`${dbName}\`;`);
await normalDataSource.destroy();
};

const getDataSource = () => {
return new DataSource({
type: 'mysql',
host: process.env.DATABASE_HOST,
port: +process.env.DATABASE_PORT,
username: process.env.DATABASE_USER,
password: process.env.DATABASE_PASSWORD,
});
};

beforeAll(async () => {
process.env.DATABASE_NAME = uuidv4();
await createDatabase(process.env.DATABASE_NAME);
await appInit();
});

Expand All @@ -195,4 +222,5 @@ beforeEach(async () => {

afterAll(async () => {
await app.close();
await dropDatabase(process.env.DATABASE_NAME);
});

0 comments on commit 7defc0f

Please sign in to comment.