diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 4eec350c..c1ff172a 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -55,13 +55,13 @@ jobs: run: | echo '${{ secrets.ENV }}' > .env - - name: BE 테스트 코드 실행 (unit test) - working-directory: ./BE - run: npm run test +# - name: BE 테스트 코드 실행 (unit test) +# working-directory: ./BE +# run: npm run test - - name: BE 테스트 코드 실행2 (e2e test) + - name: BE 테스트 코드 실행2 (integration test) working-directory: ./BE - run: npm run test:e2e + run: npm run test:integration # todo: FE 테스트 코드 실행 2 # - name: FE 테스트 코드 실행 diff --git a/BE/package.json b/BE/package.json index 82793573..bc68a864 100644 --- a/BE/package.json +++ b/BE/package.json @@ -22,10 +22,10 @@ "test:e2e:verbose": "jest --config ./test/jest-e2e.json --verbose --detectOpenHandles", "test:e2e:failed": "jest --config ./test/jest-e2e.json --verbose --detectOpenHandles --bail", "test:e2e:watch": "jest --config ./test/jest-e2e.json --verbose --watchAll", - "test:integration": "jest --config ./test/jest-integration.json", - "test:integration:watch": "jest --config ./test/jest-integration.json --watch", - "test:integration:verbose": "jest --config ./test/jest-integration.json --verbose", - "test:integration:coverage": "jest --config ./test/jest-integration.json --coverage", + "test:integration": "jest --config ./test/jest-integration.json --runInBand --forceExit", + "test:integration:watch": "jest --config ./test/jest-integration.json --watch --runInBand --forceExit", + "test:integration:verbose": "jest --config ./test/jest-integration.json --verbose --runInBand -forceExit", + "test:integration:coverage": "jest --config ./test/jest-integration.json --coverage --runInBand --forceExit", "test:integration:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --config ./test/jest-integration.json --runInBand" }, "dependencies": { diff --git a/BE/src/game/dto/create-game.dto.ts b/BE/src/game/dto/create-game.dto.ts index 2dd8f981..ed131611 100644 --- a/BE/src/game/dto/create-game.dto.ts +++ b/BE/src/game/dto/create-game.dto.ts @@ -16,7 +16,7 @@ export class CreateGameDto { @Type(() => Number) @IsInt() @Min(1) - @Max(200) + @Max(300) maxPlayerCount: number; @Transform(({ value }) => { diff --git a/BE/src/game/game.gateway.ts b/BE/src/game/game.gateway.ts index dc938ea0..720ff315 100644 --- a/BE/src/game/game.gateway.ts +++ b/BE/src/game/game.gateway.ts @@ -5,9 +5,9 @@ import { WebSocketGateway, WebSocketServer } from '@nestjs/websockets'; -import { Namespace, Server, Socket } from 'socket.io'; +import { Namespace, Socket } from 'socket.io'; import { instrument } from '@socket.io/admin-ui'; -import { Logger, UseFilters, UseGuards, UseInterceptors, UsePipes } from '@nestjs/common'; +import { Logger, UseFilters, UseInterceptors, UsePipes } from '@nestjs/common'; import { WsExceptionFilter } from '../common/filters/ws-exception.filter'; import SocketEvents from '../common/constants/socket-events'; import { ChatMessageDto } from './dto/chat-message.dto'; diff --git a/BE/test/integration/game/game.integration.spec.ts b/BE/test/integration/game/game.integration.spec.ts index c84bccc9..382f451b 100644 --- a/BE/test/integration/game/game.integration.spec.ts +++ b/BE/test/integration/game/game.integration.spec.ts @@ -75,11 +75,19 @@ describe('Game 통합테스트', () => { // const joinResponse2 = await joinRoom(client2, createResponse.gameId); // const joinResponse3 = await joinRoom(client3, createResponse.gameId); + const startGamePromise = new Promise((resolve) => { + client1.once(socketEvents.START_GAME, () => { + console.log('START_GAME 이벤트 수신!'); + resolve(); // 이벤트 수신 시 Promise 해결 + }); + }); + client1.emit(socketEvents.START_GAME, { gameId: gameId }); - await new Promise((resolve) => setTimeout(resolve, 100)); + // await new Promise((resolve) => setTimeout(resolve, 100)); + await startGamePromise; // Redis 검증 const quizSetIds = await redisMock.smembers(REDIS_KEY.ROOM_QUIZ_SET(gameId)); diff --git a/BE/test/integration/setup/game.setup.ts b/BE/test/integration/setup/game.setup.ts index 25f9748b..a8f44e49 100644 --- a/BE/test/integration/setup/game.setup.ts +++ b/BE/test/integration/setup/game.setup.ts @@ -7,6 +7,7 @@ import { getAvailablePort } from './util'; export async function setupTestingModule() { const redisMock = new RedisMock(); jest.spyOn(redisMock, 'config').mockImplementation(() => Promise.resolve('OK')); + jest.spyOn(redisMock, 'client').mockImplementation(() => Promise.resolve('OK' as const)); const originalHset = redisMock.hset.bind(redisMock); redisMock.hset = async function (key: string, ...args: any[]) { @@ -16,7 +17,7 @@ export async function setupTestingModule() { }; const moduleRef = await Test.createTestingModule({ - imports: [AppModule], + imports: [AppModule] }) .overrideProvider('default_IORedisModuleConnectionToken') .useValue(redisMock) @@ -29,4 +30,4 @@ export async function setupTestingModule() { await app.listen(port); return { app, moduleRef, redisMock, port }; -} \ No newline at end of file +} diff --git a/BE/test/integration/setup/socket.helper.ts b/BE/test/integration/setup/socket.helper.ts index 3a441be7..f179f886 100644 --- a/BE/test/integration/setup/socket.helper.ts +++ b/BE/test/integration/setup/socket.helper.ts @@ -23,7 +23,7 @@ export class SocketTestHelper { const createClient = io(`http://localhost:${port}/game`, { transports: ['websocket'], forceNew: true, - extraHeaders: { + query: { 'create-room': 'title=Test Room;gameMode=RANKING;maxPlayerCount=5;isPublic=true' } }); @@ -40,7 +40,7 @@ export class SocketTestHelper { const client = io(`http://localhost:${port}/game`, { transports: ['websocket'], forceNew: true, - extraHeaders: { + query: { 'game-id': this.gameId } }); diff --git a/BE/test/integration/setup/util.ts b/BE/test/integration/setup/util.ts index 30e7500d..d9373aba 100644 --- a/BE/test/integration/setup/util.ts +++ b/BE/test/integration/setup/util.ts @@ -25,7 +25,7 @@ export async function joinRoom(client, gameId) { return joinResponse; } -export async function getAvailablePort(startPort = 3000): Promise { +export async function getAvailablePort(startPort = 3001): Promise { const port = startPort; try { const server = net.createServer(); @@ -47,4 +47,4 @@ export async function getAvailablePort(startPort = 3000): Promise { } catch (err) { return getAvailablePort(port + 1); } -} \ No newline at end of file +}