-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.config.js
More file actions
115 lines (92 loc) · 2.85 KB
/
jest.config.js
File metadata and controls
115 lines (92 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// Jest Configuration (v30+)
// 🎯 Analogia: O "Laboratório de Testes" - define como os testes são executados
// Configuração moderna para Jest 30 com ES Modules e JSDOM
export default {
// Ambiente de execução: jsdom simula um browser
testEnvironment: 'jsdom',
// Transformações: como processar diferentes tipos de arquivo
transform: {
'^.+\\.js$': 'babel-jest', // Usa Babel para transpilar JS
},
// Mapeamento de módulos: como resolver imports de arquivos não-JS
moduleNameMapper: {
// CSS imports retornam um objeto vazio
'\\.(css|less|scss|sass)$': 'identity-obj-proxy',
// Imagens retornam string com o path
'\\.(jpg|jpeg|png|gif|svg|webp)$': '<rootDir>/__mocks__/fileMock.js',
},
// Coleta de cobertura de código
collectCoverageFrom: [
'src/**/*.js', // Testa tudo em src/
'!src/**/*.test.js', // Exceto os próprios testes
'!src/**/*.spec.js', // Exceto specs
'!src/main.js', // Exceto entry point
'!src/setup-structure.js', // Exceto script de setup
],
// Thresholds de cobertura (ajustado temporariamente - aumentar gradualmente)
coverageThreshold: {
global: {
statements: 15,
branches: 17,
functions: 13,
lines: 15,
},
},
// Diretório de saída do coverage
coverageDirectory: 'coverage',
// Reporters de coverage
coverageReporters: [
'text', // Exibe no terminal
'text-summary', // Resumo no terminal
'html', // Gera HTML navegável
'lcov', // Para Codecov
'json', // Para ferramentas externas
],
// Configuração pós-ambiente
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
// Padrões de arquivos de teste
testMatch: [
'**/__tests__/**/*.js', // Arquivos em pastas __tests__
'**/?(*.)+(spec|test).js', // Arquivos *.test.js ou *.spec.js
],
// Ignora arquivos que não são testes unitários
testPathIgnorePatterns: [
'/node_modules/',
'/e2e/', // ← Ignora testes E2E
'/playwright-report/',
'/test-results/',
],
// Timeout para testes (ms)
testTimeout: 10000,
// Limpa mocks automaticamente entre testes
clearMocks: true,
// Restaura mocks automaticamente entre testes
restoreMocks: true,
// Reseta mocks automaticamente entre testes
resetMocks: true,
// Verbose: mostra cada teste individualmente
verbose: true,
};
/*
📚 COMANDOS ÚTEIS:
npm run test # Roda testes em watch mode
npm run test:ci # Roda todos os testes uma vez (para CI)
npm run test:coverage # Roda e gera relatório de cobertura
npm run test:unit # Roda apenas testes unitários
🎯 ESTRUTURA DE TESTES:
src/
core/
NavigationController.js
__tests__/
NavigationController.test.js
utils/
Randomizer.js
__tests__/
Randomizer.test.js
OU
src/
core/
NavigationController.js
NavigationController.test.js
Ambas as estruturas funcionam!
*/