Skip to content

Commit

Permalink
feat(test): switch from jest to vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
ErickCReis committed Feb 11, 2024
1 parent 61f40e7 commit 5d971e6
Show file tree
Hide file tree
Showing 15 changed files with 3,915 additions and 4,979 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
node-version: '18'
cache: 'npm'
- run: npm ci
- run: npm run dev & npx jest --runInBand
- run: npm run dev & npx vitest run

- name: Stop containers
if: always()
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Caso queira manter os serviços e testes rodando enquanto desenvolve (e rodando
npm run test:watch:services
```

Os logs do Serviço Web e Jest (dos testes) irão se misturar, então caso queira rodar eles de forma separada, abra dois terminais separados e rode o seguinte:
Os logs do Serviço Web e Vitest (dos testes) irão se misturar, então caso queira rodar eles de forma separada, abra dois terminais separados e rode o seguinte:

```bash
# Terminal 1
Expand Down
12 changes: 0 additions & 12 deletions jest.config.js

This file was deleted.

1 change: 1 addition & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"compilerOptions": {
"baseUrl": ".",
"types": ["vitest/globals"],
"paths": {
"@/*": ["pages/interface/components/*"]
}
Expand Down
8,654 changes: 3,782 additions & 4,872 deletions package-lock.json

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"@commitlint/cli": "18.6.0",
"@commitlint/config-conventional": "18.6.0",
"@faker-js/faker": "8.4.1",
"@vitejs/plugin-react": "4.2.1",
"autoprefixer": "10.4.17",
"concurrently": "8.2.2",
"cross-fetch": "4.0.0",
Expand All @@ -64,12 +65,12 @@
"eslint-plugin-jsx-a11y": "6.8.0",
"eslint-plugin-primer-react": "4.1.0",
"husky": "9.0.10",
"jest": "29.7.0",
"kill-port": "1.6.1",
"lint-staged": "15.2.2",
"prettier": "3.2.5",
"react-email": "2.0.0",
"retry-cli": "0.7.0"
"retry-cli": "0.7.0",
"vitest": "1.2.2"
},
"scripts": {
"dev": "npm run services:seed && npm run next && npm run services:stop",
Expand All @@ -84,10 +85,10 @@
"services:stop": "npm run docker:compose -- stop",
"services:down": "npm run docker:compose -- down",
"docker:compose": "docker compose --env-file .env -f infra/docker-compose.development.yml",
"concurrently": "kill-port 3000 && npm run services:up && concurrently -s -k -n next,jest \"npm run next\"",
"test": "npm run concurrently -- \"jest --runInBand\" --hide next --verbose || npm run services:stop",
"test:watch": "jest --runInBand --watchAll",
"test:watch:services": "npm run concurrently -- \"jest --runInBand --watchAll\" || npm run services:stop",
"concurrently": "kill-port 3000 && npm run services:up && concurrently -s -k -n next,vitest \"npm run next\"",
"test": "npm run concurrently -- \"vitest run\" --hide next --verbose || npm run services:stop",
"test:watch": "vitest",
"test:watch:services": "npm run concurrently -- \"vitest\" || npm run services:stop",
"lint": "npm run lint:next && npm run lint:prettier",
"lint:next": "next lint --max-warnings=0 --dir .",
"lint:prettier": "prettier --check .",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe('GET /api/v1/contents/[username]/[slug]/thumbnail', () => {
username: 'abc',
});

jest.useFakeTimers({
vi.useFakeTimers({
now: Date.parse('2022-01-01T12:00:00.000Z'),
advanceTimers: true,
});
Expand All @@ -93,7 +93,7 @@ describe('GET /api/v1/contents/[username]/[slug]/thumbnail', () => {
status: 'published',
});

jest.useRealTimers();
vi.useRealTimers();

const response = await fetch(
`${orchestrator.webserverUrl}/api/v1/contents/${defaultUser.username}/${rootContent.slug}/thumbnail`,
Expand Down Expand Up @@ -125,7 +125,7 @@ describe('GET /api/v1/contents/[username]/[slug]/thumbnail', () => {
username: 'ThisUsernameHas30Characterssss',
});

jest.useFakeTimers({
vi.useFakeTimers({
now: Date.parse('2022-06-06T12:00:00.000Z'),
advanceTimers: true,
});
Expand All @@ -137,7 +137,7 @@ describe('GET /api/v1/contents/[username]/[slug]/thumbnail', () => {
status: 'published',
});

jest.useRealTimers();
vi.useRealTimers();

const response = await fetch(
`${orchestrator.webserverUrl}/api/v1/contents/${defaultUser.username}/${rootContent.slug}/thumbnail`,
Expand Down Expand Up @@ -169,7 +169,7 @@ describe('GET /api/v1/contents/[username]/[slug]/thumbnail', () => {
username: 'ThisUsernameHas30Charactersss2',
});

jest.useFakeTimers({
vi.useFakeTimers({
now: Date.parse('2022-07-01T12:00:00.000Z'),
advanceTimers: true,
});
Expand All @@ -181,7 +181,7 @@ describe('GET /api/v1/contents/[username]/[slug]/thumbnail', () => {
status: 'published',
});

jest.useRealTimers();
vi.useRealTimers();

const childContent1 = await orchestrator.createContent({
parent_id: rootContent.id,
Expand Down Expand Up @@ -233,7 +233,7 @@ describe('GET /api/v1/contents/[username]/[slug]/thumbnail', () => {
status: 'published',
});

jest.useFakeTimers({
vi.useFakeTimers({
now: Date.parse('2022-02-02T12:00:00.000Z'),
advanceTimers: true,
});
Expand All @@ -245,7 +245,7 @@ describe('GET /api/v1/contents/[username]/[slug]/thumbnail', () => {
status: 'published',
});

jest.useRealTimers();
vi.useRealTimers();

const response = await fetch(
`${orchestrator.webserverUrl}/api/v1/contents/${defaultUser.username}/${childContent.slug}/thumbnail`,
Expand Down Expand Up @@ -284,7 +284,7 @@ describe('GET /api/v1/contents/[username]/[slug]/thumbnail', () => {
status: 'published',
});

jest.useFakeTimers({
vi.useFakeTimers({
now: Date.parse('2022-10-10T12:00:00.000Z'),
advanceTimers: true,
});
Expand All @@ -296,7 +296,7 @@ describe('GET /api/v1/contents/[username]/[slug]/thumbnail', () => {
status: 'published',
});

jest.useRealTimers();
vi.useRealTimers();

const response = await fetch(
`${orchestrator.webserverUrl}/api/v1/contents/${defaultUser.username}/${childContent.slug}/thumbnail`,
Expand Down Expand Up @@ -334,7 +334,7 @@ describe('GET /api/v1/contents/[username]/[slug]/thumbnail', () => {
status: 'published',
});

jest.useFakeTimers({
vi.useFakeTimers({
now: Date.parse('2022-02-02T12:00:00.000Z'),
advanceTimers: true,
});
Expand All @@ -353,7 +353,7 @@ describe('GET /api/v1/contents/[username]/[slug]/thumbnail', () => {
status: 'published',
});

jest.useRealTimers();
vi.useRealTimers();

const response = await fetch(
`${orchestrator.webserverUrl}/api/v1/contents/${defaultUser.username}/${contentLevel3.slug}/thumbnail`,
Expand Down Expand Up @@ -391,7 +391,7 @@ describe('GET /api/v1/contents/[username]/[slug]/thumbnail', () => {
status: 'published',
});

jest.useFakeTimers({
vi.useFakeTimers({
now: Date.parse('2022-02-02T12:00:00.000Z'),
advanceTimers: true,
});
Expand All @@ -410,7 +410,7 @@ describe('GET /api/v1/contents/[username]/[slug]/thumbnail', () => {
status: 'published',
});

jest.useRealTimers();
vi.useRealTimers();

const response = await fetch(
`${orchestrator.webserverUrl}/api/v1/contents/${defaultUser.username}/${contentLevel3.slug}/thumbnail`,
Expand Down
37 changes: 18 additions & 19 deletions tests/integration/api/v1/contents/get.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ describe('GET /api/v1/contents', () => {
vary: ['Accept-Encoding'],
date: responseHeaders.date,
connection: [expect.stringMatching(/close|keep-alive/)],
'keep-alive': expect.objectContaining([]),
});
});

Expand Down Expand Up @@ -389,7 +388,7 @@ describe('GET /api/v1/contents', () => {
const numberOfContents = 60;
const contentList = [];

jest.useFakeTimers({
vi.useFakeTimers({
now: new Date(Date.now() - 1000 * 60 * 60 * 24 * 10), // 10 days ago
advanceTimers: true,
});
Expand All @@ -402,7 +401,7 @@ describe('GET /api/v1/contents', () => {
}),
);

jest.useRealTimers();
vi.useRealTimers();

await orchestrator.createContent({
owner_id: firstUser.id,
Expand All @@ -417,7 +416,7 @@ describe('GET /api/v1/contents', () => {
amount: 10, // -> with recent comment, but same user
});

jest.useFakeTimers({
vi.useFakeTimers({
now: new Date(Date.now() - 1000 * 60 * 60 * 24 * 9), // 9 days ago
advanceTimers: true,
});
Expand All @@ -430,7 +429,7 @@ describe('GET /api/v1/contents', () => {
}),
);

jest.useRealTimers();
vi.useRealTimers();

await orchestrator.createContent({
owner_id: secondUser.id,
Expand All @@ -445,7 +444,7 @@ describe('GET /api/v1/contents', () => {
amount: 10, // -> score = 33, more than 7 days ago, but with recent comment
});

jest.useFakeTimers({
vi.useFakeTimers({
now: new Date(Date.now() - 1000 * 60 * 60 * 24 * 8), // 8 days ago
advanceTimers: true,
});
Expand All @@ -458,7 +457,7 @@ describe('GET /api/v1/contents', () => {
}),
);

jest.useRealTimers();
vi.useRealTimers();

await orchestrator.createContent({
owner_id: secondUser.id,
Expand All @@ -473,7 +472,7 @@ describe('GET /api/v1/contents', () => {
amount: 9, // -> score = 30, more than 7 days ago, but with recent comment
});

jest.useFakeTimers({
vi.useFakeTimers({
now: new Date(Date.now() - 1000 * 60 * 60 * 24 * 7), // 7 days ago
advanceTimers: true,
});
Expand All @@ -486,15 +485,15 @@ describe('GET /api/v1/contents', () => {
}),
);

jest.useRealTimers();
vi.useRealTimers();

await orchestrator.createBalance({
balanceType: 'content:tabcoin',
recipientId: contentList[3].id, // Conteúdo #4
amount: 9, // -> score = 30, but more than 7 days ago
});

jest.useFakeTimers({
vi.useFakeTimers({
now: new Date(Date.now() - 1000 * 60 * 60 * 24 * 3), // 3 days ago
advanceTimers: true,
});
Expand All @@ -507,15 +506,15 @@ describe('GET /api/v1/contents', () => {
}),
);

jest.useRealTimers();
vi.useRealTimers();

await orchestrator.createBalance({
balanceType: 'content:tabcoin',
recipientId: contentList[4].id, // Conteúdo #5
amount: 8, // -> score = 27 and 3 days ago -> group_6
});

jest.useFakeTimers({
vi.useFakeTimers({
now: new Date(Date.now() - 1000 * 60 * 60 * 35), // 35 hours ago
advanceTimers: true,
});
Expand All @@ -528,15 +527,15 @@ describe('GET /api/v1/contents', () => {
}),
);

jest.useRealTimers();
vi.useRealTimers();

await orchestrator.createBalance({
balanceType: 'content:tabcoin',
recipientId: contentList[5].id, // Conteúdo #6
amount: 3, // score = 12 and less than 36 hours -> group_4
});

jest.useFakeTimers({
vi.useFakeTimers({
now: new Date(Date.now() - 1000 * 60 * 60 * 37), // 37 hours ago
advanceTimers: true,
});
Expand All @@ -549,15 +548,15 @@ describe('GET /api/v1/contents', () => {
}),
);

jest.useRealTimers();
vi.useRealTimers();

await orchestrator.createBalance({
balanceType: 'content:tabcoin',
recipientId: contentList[6].id, // Conteúdo #7
amount: 4, // score = 15 and more than 37 hours -> group_5
});

jest.useFakeTimers({
vi.useFakeTimers({
now: new Date(Date.now() - 1000 * 60 * 60 * 36), // 36 hours ago
advanceTimers: true,
});
Expand All @@ -570,15 +569,15 @@ describe('GET /api/v1/contents', () => {
}),
);

jest.useRealTimers();
vi.useRealTimers();

await orchestrator.createBalance({
balanceType: 'content:tabcoin',
recipientId: contentList[7].id, // Conteúdo #8
amount: 4, // score = 15 and more than 36 hours -> group_5
});

jest.useFakeTimers({
vi.useFakeTimers({
now: new Date(Date.now() - 1000 * 60 * 60 * 24), // 24 hours ago
advanceTimers: true,
});
Expand All @@ -591,7 +590,7 @@ describe('GET /api/v1/contents', () => {
}),
);

jest.useRealTimers();
vi.useRealTimers();

await orchestrator.createBalance({
balanceType: 'content:tabcoin',
Expand Down
Loading

0 comments on commit 5d971e6

Please sign in to comment.