Commit 3f55fb9
test: unit & integration testing improvements (#213)
* test(electron): test improvements
- Modified assertions in `bridge.spec.ts` to expect `client.close()` to resolve to `undefined` instead of not throwing an error.
- Updated error messages in `getDebuggerEndpoint` tests in `bridge.spec.ts` to be more specific.
- Changed `describe` blocks in various test files from async to synchronous for consistency.
- Removed outdated test files and added new tests for mock operations to enhance coverage and maintainability.
* test(electron): enhance test coverage and error handling
- Added new tests in `launcher.spec.ts` to verify behavior when only `appEntryPoint` is provided and to handle unexpected errors from `getBinaryPath`.
- Introduced tests in `pathResolver.spec.ts` for `getElectronBinaryPath`, covering successful resolution, package.json not found, and binary path resolution failures.
- Improved mock implementations in `mock.spec.ts` and `triggerDeeplink.spec.ts` to ensure accurate behavior and error handling during tests.
- Updated assertions and added caching logic for userDataDir detection in `triggerDeeplink.spec.ts` to enhance reliability.
* fix: update command execution for cross-platform compatibility
- Modified the command execution in `build-package.ts` to use `cmd.exe` on Windows and `pnpm` on other platforms, ensuring proper invocation of the build process.
- Adjusted arguments for the spawn function to accommodate the changes in command structure, enhancing compatibility across different operating systems.
* fix(electron): resolve TypeScript errors in test suite
Fix pre-existing TS errors: vitest module augmentation shadowing, wrong
import source for waitUntilWindowAvailable, missing Result type narrowing
guards, and mismatched Assertion type parameters.
Co-Authored-By: Claude Opus 4.6 <[email protected]>
* test(electron): add coverage tests for mockAll, isMockFunction, mock, and pathResolver
Add tests for execute params/callback in mockAll, class mock path in
mock command, and getElectronBinaryPath resolution in pathResolver.
Co-Authored-By: Claude Opus 4.6 <[email protected]>
* test: update mock function types for better TypeScript compatibility
Refine the type definitions for mocked functions in the mockOperations test suite to allow for both function return types and string return types, enhancing type safety and clarity in the tests.
* chore: remove redundant mock definitions
Removed redundant mock definitions for appBuildInfo, binaryPath, and electronVersion, simplifying the test setup in pathResolver.spec.ts. This change enhances clarity and maintainability of the test suite.
* test(electron): extract MockApiMethod type for mock operation test stubs
Replace inline Record union type with a named MockApiMethod type that
explicitly declares getMockName, making the required property visible
at the type level.
Co-Authored-By: Claude Opus 4.6 <[email protected]>
* test(native-spy): enhance mock function tests with new scenarios
Added multiple test cases to improve coverage for mock functions, including scenarios for `mockResolvedValueOnce`, `mockRejectedValueOnce`, `mockRestore`, and context tracking. These additions ensure better validation of mock behavior and state management in various use cases.
* test(native-utils): add URL support for cwd in readPackageUp and readPackageUpSync
Enhanced tests for `readPackageUp` and `readPackageUpSync` to validate functionality when a URL is provided as the `cwd`. This includes checks for both asynchronous and synchronous methods, ensuring that the package JSON is correctly read from the specified URL. Additionally, improved error handling tests in `selectExecutable` to cover scenarios with empty paths and errors without message properties.
* test(electron): update mock cleanup method in tests
Replaced `vi.resetAllMocks()` with `vi.clearAllMocks()` in the mock operations test suite to ensure a more precise reset of mock states after each test, improving test isolation and reliability.
* test(native-spy): standardise test descriptions for mock function behavior
Updated test descriptions in `spy.spec.ts` to follow a consistent format, enhancing clarity and readability. Each test now begins with "should" to clearly define the expected behavior of the mock functions.
* test(native-spy): add new test cases for error handling and instance tracking
Introduced additional test scenarios in `spy.spec.ts` to enhance coverage for mock functions. New tests include tracking results for queued implementations that throw errors and verifying the tracking of instances, ensuring comprehensive validation of mock behavior.
---------
Co-authored-by: Claude Opus 4.6 <[email protected]>1 parent 34e5b4c commit 3f55fb9
24 files changed
Lines changed: 704 additions & 289 deletions
File tree
- @types/vitest
- packages
- electron-cdp-bridge/test
- electron-service/test
- commands
- native-spy/test
- native-utils/test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
1 | 3 | | |
2 | 4 | | |
3 | 5 | | |
| 6 | + | |
4 | 7 | | |
5 | | - | |
| 8 | + | |
6 | 9 | | |
7 | 10 | | |
8 | | - | |
9 | | - | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
284 | 284 | | |
285 | 285 | | |
286 | 286 | | |
287 | | - | |
| 287 | + | |
288 | 288 | | |
289 | 289 | | |
290 | 290 | | |
291 | 291 | | |
292 | 292 | | |
293 | 293 | | |
294 | | - | |
| 294 | + | |
295 | 295 | | |
296 | 296 | | |
297 | 297 | | |
| |||
313 | 313 | | |
314 | 314 | | |
315 | 315 | | |
316 | | - | |
| 316 | + | |
317 | 317 | | |
318 | 318 | | |
319 | 319 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
159 | 159 | | |
160 | 160 | | |
161 | 161 | | |
| 162 | + | |
162 | 163 | | |
163 | 164 | | |
164 | 165 | | |
| |||
195 | 196 | | |
196 | 197 | | |
197 | 198 | | |
| 199 | + | |
198 | 200 | | |
| 201 | + | |
199 | 202 | | |
200 | 203 | | |
201 | 204 | | |
| |||
209 | 212 | | |
210 | 213 | | |
211 | 214 | | |
| 215 | + | |
212 | 216 | | |
| 217 | + | |
213 | 218 | | |
214 | 219 | | |
215 | 220 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
| 42 | + | |
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
54 | | - | |
| 54 | + | |
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
73 | | - | |
| 73 | + | |
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
| |||
Lines changed: 0 additions & 45 deletions
This file was deleted.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
85 | | - | |
| 85 | + | |
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
| |||
Lines changed: 0 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | 1 | | |
3 | 2 | | |
4 | 3 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
69 | 70 | | |
70 | 71 | | |
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 | + | |
72 | 96 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | 1 | | |
3 | 2 | | |
4 | 3 | | |
5 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
6 | 8 | | |
7 | 9 | | |
8 | 10 | | |
| |||
21 | 23 | | |
22 | 24 | | |
23 | 25 | | |
24 | | - | |
| 26 | + | |
25 | 27 | | |
26 | 28 | | |
27 | 29 | | |
| |||
36 | 38 | | |
37 | 39 | | |
38 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
39 | 58 | | |
Lines changed: 54 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 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 | + | |
0 commit comments