Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

wip #672

Merged
merged 1 commit into from
Jul 9, 2024
Merged

wip #672

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ npm run test
```js
npm run check
```

ou

```js
Expand Down Expand Up @@ -190,3 +191,52 @@ The timers are decreased to:
- 60s for DISCO_TIMER
- 60s for START_GAME_TIMER
The .env file should be handled by the provider.

#### Application

```sh
cp .env.example .env
docker-compose up
```

or

```sh
make start
```

#### Units Tests

##### Backend

###### Docker Container

```sh
backend-test
```

Then into container:

```sh
npm run rm:prod
npm install
npm build
npx jest --detectOpenHandles --config jest.config.ts
```

Don't forget to :

```sh
npm run rm:prod
```

after each testing session.

###### Host Environment

```sh
make backend-test-without-docker
make backend-test-cmd
```

##### Frontend
1 change: 0 additions & 1 deletion backend/.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ logs/

# Test
src/tests/coverage-reports
jest.config.ts
jest.onlyTest.config.ts

# Config
Expand Down
2 changes: 1 addition & 1 deletion backend/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const config: Config = {
name: 'RED-TETRIS Backend',
color: 'cyan',
},
testTimeout: 250,
testTimeout: 30000,
roots: ['<rootDir>/src/'],
setupFilesAfterEnv: ['<rootDir>/src/tests/utils/expect.ts'],
injectGlobals: true,
Expand Down
10 changes: 7 additions & 3 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"main": "app.js",
"scripts": {
"start": "TZ='UTC' node dist/src/app.js",
"env": "npx ts-node configSetup.ts",
"build": "npx tsc --build",
"env": "npx ts-node configSetup.ts",
"start:prod:without:docker": "unset DEV UNITSTESTS && npm run env && npm run build && TZ='UTC' node dist/src/app.js",
"dev": "npm run dev:backend",
"install:frontend": "npm install -C ../frontend",
Expand All @@ -27,13 +27,17 @@
"logs:rm": "rm -rf ./logs/*.txt",
"tests:rm": "rm -rf ./src/tests/output.txt",
"rm": " npm run env:rm && npm run tests:rm ",
"rm:prod": " npm run env:rm && npm run tests:rm && npm run logs:rm && npm run rm:sqlite && rm -rf node_modules dist",
"rm:sqlite": "rm -rf data/leaderboard.sqlite",
"test:noCovDebug": "npm run rm:sqlite && UNITSTESTS='1' && export DEBUG=engine,socket* && npm run env && jest --detectOpenHandles --config jest.onlyTest.config.ts",
"test:noCov": "npm run rm:sqlite && export UNITSTESTS='1' && npm run env && npm run format && npm run build && jest --detectOpenHandles --config jest.onlyTest.config.ts",
"test:Cov": "npm run rm:sqlite && export UNITSTESTS='1' && npm run env && npm run format && npm run build && jest --detectOpenHandles --config jest.config.ts",
"test:cov:prod": "jest --detectOpenHandles --config jest.config.ts",
"test:Cov": "npm run rm:sqlite && export UNITSTESTS='1' && npm run env && npm run build && jest --detectOpenHandles --config jest.config.ts",
"test:fmt:Cov": "npm run rm:sqlite && export UNITSTESTS='1' && npm run env && npm run format && npm run build && jest --detectOpenHandles --config jest.config.ts",
"test": "npm run rm:sqlite && export UNITSTESTS='1' && npm run env && npm run format && npm run build && jest --detectOpenHandles > src/tests/output.txt --config jest.config.ts",
"test:rm": "npm run rm:sqlite && npm run test && npm run tests:rm",
"test:open": "open src/tests/coverage-reports/lcov-report/index.html"
"test:open": "open src/tests/coverage-reports/lcov-report/index.html",
"test:prod": "npm run rm:prod && npm install && npm run build && npm run test:cov:prod"
},
"license": "ISC",
"devDependencies": {
Expand Down
94 changes: 45 additions & 49 deletions backend/src/tests/EnterRoomAndDisconnectSocket.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,57 +436,53 @@ describe('* Disconnect Players State', () => {
});
});

test(
`${config(username2).client} should listen the countdown 2 times then unset as ready\
, ${config('disconnect').eventI} -> [${config('join').eventO}] events`,
async () => {
client2 = datasClients[1].clients[2];
await testSeveralOutgoingEventsSeveralTimes(
client2,
createIncomingAction('undefined', undefined),
[
{
event: 'gameStart',
times: 2,
payloads: [
{
roomName: room1,
reason: 'time',
message: 'The game will start in 3 seconds.',
},
{
reason: 'time',
message: 'The game will start in 2 seconds.',
roomName: room1,
},
],
},
],
test(`${config(username2).client} should listen the countdown 2 times then unset as ready\
, ${config('disconnect').eventI} -> [${config('join').eventO}] events`, async () => {
client2 = datasClients[1].clients[2];
await testSeveralOutgoingEventsSeveralTimes(
client2,
createIncomingAction('undefined', undefined),
[
{
name: room1,
toWatch: [client2.id ?? ''],
event: 'gameStart',
times: 2,
payloads: [
{
roomName: room1,
reason: 'time',
message: 'The game will start in 3 seconds.',
},
{
reason: 'time',
message: 'The game will start in 2 seconds.',
roomName: room1,
},
],
},
);
// clt2 se unset ready
await testSeveralOutgoingEvents(client2, createIncomingAction('ready', room1), [
createOutgoingAction('playerChange', {
reason: 'ready',
player: {
...player2,
roomsState: [
createRoomState({
name: room1,
status: 'idle',
readys: 1,
leads: false,
}),
],
},
}),
]);
},
destroyTimer + 1000,
);
],
{
name: room1,
toWatch: [client2.id ?? ''],
},
);
// clt2 se unset ready
await testSeveralOutgoingEvents(client2, createIncomingAction('ready', room1), [
createOutgoingAction('playerChange', {
reason: 'ready',
player: {
...player2,
roomsState: [
createRoomState({
name: room1,
status: 'idle',
readys: 1,
leads: false,
}),
],
},
}),
]);
});
});

describe(`Client 3 should income in room ${room1}, set as ready, leave room, disconnect and reconnect`, () => {
Expand Down
2 changes: 1 addition & 1 deletion backend/src/tests/PlayGame.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ ${config('gameChange').eventI} -> [${config('roomChange: new winner').eventO}] e
...playerExpect5,
}),
]);
}, 500);
});
});

describe('A Fifth Player enters in Room 1, after Third Game started', () => {
Expand Down
14 changes: 14 additions & 0 deletions dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM node:18-bookworm-slim

WORKDIR /tmp
COPY . /tmp

RUN apt-get update && apt-get install -y \
vim \
curl \
&& npx playwright install \
&& npx playwright install-deps \
&& cd backend && npm install \
&& cd ../frontend && cp .env.example .env && npm install

CMD ["/bin/bash"]
2 changes: 1 addition & 1 deletion frontend/tests/updateChannelList.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ test('Update Channel List', async ({ context, browser }) => {
await page.getByRole('button', { name: 'send' }).click();
await page.waitForTimeout(1000);
await page.goto('/');
expect(await page.title()).toEqual('ListRoom | Red Tetris');
await page.waitForTimeout(1000);
expect(await page.title()).toEqual('ListRoom | Red Tetris');

const newContext = await browser.newContext();
const newPage = await newContext.newPage();
Expand Down
4 changes: 4 additions & 0 deletions test42.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/bash

docker build -t test42 .
docker run -it test42 /bin/bash