@@ -52,43 +52,76 @@ bun run prepare
5252
5353## Architecture and Code Structure
5454
55- ### Core API
55+ ### Core API (v2.0.0)
5656
5757The library exports a single file ` lib/flutter_hooks_test.dart ` containing:
5858
59- 1 . ** ` buildHook<T, P> ` ** - Main function to test hooks
59+ 1 . ** ` buildHook<T>() ` ** - Test hooks without props
6060 - Generic ` T ` : Return type of the hook
61- - Generic ` P ` : Props type for parameterized hooks
62- - Returns ` _HookTestingAction<T> ` with methods:
61+ - Returns ` HookResult<T> ` with methods:
6362 - ` current ` : Access current hook value
64- - ` rebuild([props] ) ` : Trigger rebuild with optional new props
63+ - ` rebuild() ` : Trigger rebuild and update history
6564 - ` unmount() ` : Unmount the hook
65+ - ` all ` : Build history for debugging
66+ - ` buildCount ` : Number of builds
6667
67- 2 . ** ` act ` ** - Wraps state changes to ensure proper Flutter test lifecycle
68+ 2 . ** ` buildHookWithProps<T, P>() ` ** - Test hooks with props
69+ - Generic ` T ` : Return type, ` P ` : Props type
70+ - Returns ` HookResultWithProps<T, P> ` with additional:
71+ - ` rebuildWithProps(P props) ` : Rebuild with new props
72+
73+ 3 . ** ` act ` ** - Wraps state changes to ensure proper Flutter test lifecycle
74+
75+ 4 . ** ` waitFor ` utilities** - Async testing helpers
76+ - ` waitFor(condition) ` : Wait for condition to be true
77+ - ` waitForValueToChange(getValue) ` : Wait for value change
78+ - ` result.waitForNextUpdate() ` : Wait for hook rebuild
79+ - ` result.waitForValueToMatch(predicate) ` : Wait for specific condition
6880 - Similar to React's ` act ` function
6981 - Required when changing hook state
7082
71- ### Testing Pattern
83+ ### Testing Patterns (v2.0.0)
7284
7385``` dart
74- // Basic hook test structure
75- final result = await buildHook((_ ) => useMyHook());
86+ // Basic hook test (no props)
87+ final result = await buildHook(() => useMyHook());
7688await act(() => result.current.doSomething());
7789expect(result.current.value, expectedValue);
7890
91+ // Hook with props
92+ final result = await buildHookWithProps(
93+ (count) => useCounter(count),
94+ initialProps: 5,
95+ );
96+ await result.rebuildWithProps(10);
97+ expect(result.current.value, 10);
98+
7999// With wrapper widget
80100final result = await buildHook(
81- (_ ) => useMyHook(),
101+ () => useMyHook(),
82102 wrapper: (child) => Provider(child: child),
83103);
104+
105+ // Async testing with waitFor
106+ await act(() => result.current.startAsync());
107+ await waitFor(() => !result.current.isLoading);
108+ expect(result.current.data, isNotNull);
109+
110+ // History tracking
111+ expect(result.buildCount, 1);
112+ expect(result.all.length, 1);
113+ await result.rebuild();
114+ expect(result.buildCount, 2);
84115```
85116
86- ### Internal Implementation
117+ ### Internal Implementation (v2.0.0)
87118
88119- Uses ` TestWidgetsFlutterBinding ` for test environment
89- - Creates a minimal widget tree with ` HookBuilder `
90- - Manages completer-based async operations for mount/unmount
91- - Preserves hook state across rebuilds using keys
120+ - Creates minimal widget tree with ` HookBuilder `
121+ - ` _BaseHookResult<T> ` base class eliminates code duplication
122+ - Build history tracking with automatic value capture
123+ - Separate result classes for hooks with/without props
124+ - Helper functions (` _applyWrapper ` ) and constants (` _kEmptyWidget ` )
92125
93126## Testing Approach
94127
@@ -104,40 +137,46 @@ final result = await buildHook(
104137- Pre-commit hooks format code automatically
105138- CI runs on Ubuntu with asdf version management
106139
107- ## Important Conventions
140+ ## Important Conventions (v2.0.0)
108141
109- 1 . ** Type Safety** : Always specify generic types when using ` buildHook `
110- 2 . ** Act Wrapper** : Always wrap state changes in ` act() `
111- 3 . ** Async Handling** : Most operations return Futures - use ` await `
112- 4 . ** Testing** : Test both happy paths and edge cases (mount/unmount/rebuild)
142+ 1 . ** API Selection** : Use ` buildHook() ` for hooks without props, ` buildHookWithProps() ` for hooks with props
143+ 2 . ** Type Safety** : Generic types are automatically inferred in most cases
144+ 3 . ** Act Wrapper** : Always wrap state changes in ` act() `
145+ 4 . ** Async Testing** : Use ` waitFor ` utilities for async operations
146+ 5 . ** History Tracking** : Use ` result.all ` and ` result.buildCount ` for debugging
147+ 6 . ** Rebuilds** : Call ` rebuild() ` after state changes to update history
148+ 7 . ** Testing** : Test mount/unmount/rebuild scenarios and async state changes
113149
114150## Version Requirements
115151
116152- Dart SDK: ` >=2.17.0 <4.0.0 `
117153- Flutter: ` >=3.20.0 `
118154- Uses Flutter hooks ` ^0.21.2 `
119155
120- ## Release Process
156+ ## Release Process (v2.0.0+)
121157
122- Releases are fully automated via GitHub Actions:
158+ Releases are fully automated via GitHub Actions with OIDC authentication :
123159
124160### Creating a Release
125161
1261621 . ** Update version** : Update version in ` pubspec.yaml `
127- 2 . ** Update changelog** : Run ` git cliff --unreleased --tag v1.0.1 --output CHANGELOG.md `
128- 3 . ** Commit changes** : ` git commit -am "chore(release): prepare for v1.0.1" `
129- 4 . ** Create tag** : ` git tag v1.0.1 `
130- 5 . ** Push** : ` git push origin main --tags `
163+ 2 . ** Commit changes** : ` git commit -am "chore: bump version to v2.0.1" `
164+ 3 . ** Create tag** : ` git tag v2.0.1 `
165+ 4 . ** Push** : ` git push origin main --tags `
166+
167+ Changelog is automatically generated from conventional commits.
131168
132169### Automated Release Steps
133170
134171When a tag matching ` v[0-9]+.[0-9]+.[0-9]+* ` is pushed:
135172
136- 1 . ** CI Validation** : All tests, formatting, and analysis must pass
137- 2 . ** Dry Run** : Package publication is tested
138- 3 . ** Release Notes** : Auto-generated using git-cliff from conventional commits
139- 4 . ** GitHub Release** : Created with generated release notes
140- 5 . ** pub.dev Publication** : Package is published automatically
173+ 1 . ** Environment Setup** : Flutter, Dart, Bun, and Melos
174+ 2 . ** Dependencies** : Install and bootstrap packages with Melos and Bun
175+ 3 . ** CI Validation** : All tests, formatting, and analysis must pass
176+ 4 . ** Dry Run** : Package publication tested with OIDC authentication
177+ 5 . ** Release Notes** : Auto-generated using git-cliff from conventional commits
178+ 6 . ** GitHub Release** : Created with generated release notes
179+ 7 . ** pub.dev Publication** : Published automatically with OIDC (no token required)
141180
142181### Commit Convention
143182
0 commit comments