Skip to content

Commit 07cc8b3

Browse files
committed
yarn upgrade-interactive
1 parent 0a543e0 commit 07cc8b3

File tree

3 files changed

+497
-350
lines changed

3 files changed

+497
-350
lines changed

.codegenie/customizations/test.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# Unit Testing Cheat Sheet for Codebase
2+
3+
## Testing Libraries and Frameworks
4+
- Jest (assumed, as PowerMock is mentioned which is often used with Jest)
5+
- PowerMock (for invasive mocking, discouraged in the article)
6+
7+
## Mocking and Stubbing
8+
1. Avoid using PowerMock for invasive mocking
9+
2. Prefer dependency injection through constructors for easier mocking
10+
3. Use Ports & Adapters pattern to isolate dependencies
11+
4. Mock dependencies, not statements
12+
5. Avoid `when-then` statements in tests
13+
14+
Example of bad mocking (to avoid):
15+
```java
16+
Whitebox.setInternalState(...);
17+
when(...).then(...);
18+
doNothing().when(...);
19+
```
20+
21+
## Fake Implementations
22+
- Use fake adapters for testing instead of real implementations
23+
- Implement interfaces (ports) with test-specific adapters
24+
25+
## Testing Strategies
26+
1. Black-box Unit Testing
27+
- Test component behavior without knowing internals
28+
- Focus on inputs and outputs, not implementation details
29+
30+
2. Behavior-driven Testing
31+
- Emphasize behavior coverage over statement coverage
32+
33+
3. Ports & Adapters Architecture
34+
- Use interfaces (ports) to define dependencies
35+
- Implement adapters for production and test environments
36+
37+
Example:
38+
```java
39+
public interface PokemonRepository {
40+
List<Pokemon> findAll();
41+
}
42+
43+
public class FakePokemonRepository implements PokemonRepository {
44+
@Override
45+
public List<Pokemon> findAll() {
46+
// Return test data
47+
}
48+
}
49+
```
50+
51+
## Best Practices
52+
1. Avoid void methods in tested components
53+
2. Avoid static methods that mutate state or have side effects
54+
3. Always inject dependencies through the constructor
55+
4. Design components with testability in mind
56+
5. Use Ports & Adapters to interact with legacy code indirectly
57+
6. Focus on behavior documentation in tests
58+
7. Treat unit tests as the first client of your component
59+
60+
## Anti-patterns to Avoid
61+
1. Using PowerMock or similar invasive tools
62+
2. Tightly coupling tests to implementation details
63+
3. Breaking encapsulation in tests
64+
4. Mocking internal state or private methods
65+
5. Focusing on statement coverage instead of behavior coverage
66+
67+
## Testing Legacy Code
68+
1. Introduce a level of indirection using Ports & Adapters
69+
2. Create interfaces for legacy dependencies
70+
3. Implement fake adapters for testing
71+
4. Inject fake adapters during tests
72+
73+
## Code Structure for Testability
74+
1. Separate domain logic from side effects
75+
2. Use dependency injection
76+
3. Create interfaces for external dependencies
77+
4. Implement adapters for different environments (prod, test)
78+
79+
Example of a testable component structure:
80+
```java
81+
public class PokemonCollector {
82+
private final PokemonRepository repository;
83+
private final PokemonValidator validator;
84+
85+
public PokemonCollector(PokemonRepository repository, PokemonValidator validator) {
86+
this.repository = repository;
87+
this.validator = validator;
88+
}
89+
90+
public List<Pokemon> collectValidPokemon() {
91+
return repository.findAll().stream()
92+
.filter(validator::isValid)
93+
.collect(Collectors.toList());
94+
}
95+
}
96+
```

package.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
"dependencies": {
2222
"@mdx-js/react": "^3.1.0",
2323
"bluebird": "^3.7.2",
24-
"eslint-plugin-react-hooks": "^5.1.0",
25-
"firebase": "^11.3.0",
24+
"eslint-plugin-react-hooks": "^5.2.0",
25+
"firebase": "^11.4.0",
2626
"gatsby": "^5.14.1",
2727
"gatsby-plugin-catch-links": "^5.14.0",
2828
"gatsby-plugin-cname": "^1.0.0",
@@ -59,31 +59,31 @@
5959
"metascraper-title": "^5.46.5",
6060
"metascraper-url": "^5.46.5",
6161
"moment": "^2.30.1",
62-
"postcss": "^8.5.1",
63-
"prismjs": "^1.29.0",
62+
"postcss": "^8.5.3",
63+
"prismjs": "^1.30.0",
6464
"prop-types": "^15.8.1",
6565
"react": "^19.0.0",
6666
"react-disqus-comments": "^1.4.0",
6767
"react-dom": "^19.0.0",
6868
"react-helmet": "^6.1.0",
69-
"react-toastify": "^11.0.3",
70-
"sass": "^1.84.0",
69+
"react-toastify": "^11.0.5",
70+
"sass": "^1.85.1",
7171
"sharp": "^0.33.5",
7272
"styled-components": "^6.1.15"
7373
},
7474
"devDependencies": {
75-
"@babel/core": "^7.26.8",
76-
"@babel/eslint-parser": "^7.26.8",
77-
"@babel/eslint-plugin": "^7.25.9",
75+
"@babel/core": "^7.26.10",
76+
"@babel/eslint-parser": "^7.26.10",
77+
"@babel/eslint-plugin": "^7.26.10",
7878
"@babel/plugin-syntax-flow": "^7.26.0",
7979
"@babel/plugin-transform-flow-strip-types": "^7.26.5",
8080
"@babel/plugin-transform-react-jsx": "^7.25.9",
8181
"@types/eslint": "^9.6.1",
8282
"babel-preset-gatsby-package": "^3.14.0",
83-
"eslint": "^9.20.0",
83+
"eslint": "^9.22.0",
8484
"eslint-config-airbnb": "^19.0.4",
8585
"eslint-config-google": "^0.14.0",
86-
"eslint-config-prettier": "^10.0.1",
86+
"eslint-config-prettier": "^10.1.1",
8787
"eslint-plugin-babel": "^5.3.1",
8888
"eslint-plugin-filenames": "^1.3.2",
8989
"eslint-plugin-flowtype": "^8.0.3",
@@ -95,7 +95,7 @@
9595
"gh-pages": "^6.3.0",
9696
"lost": "^9.0.2",
9797
"postcss-pxtorem": "^6.1.0",
98-
"prettier": "^3.4.2"
98+
"prettier": "^3.5.3"
9999
},
100100
"resolutions": {
101101
"gatsby-plugin-sharp/probe-image-size": "^7.0.0"

0 commit comments

Comments
 (0)