Commit e122474
authored
feat: address mocking failures (#235)
* feat(native-spy): add getMockImplementation method to retrieve current mock implementation
- Implemented `getMockImplementation` method in the mock function to allow users to access the current mock implementation.
- Updated the `Mock` interface in `types.ts` to include the new method.
- Added tests to verify the functionality of `getMockImplementation`, ensuring it returns the correct implementation or undefined when none is set.
* feat(electron): bind getMockImplementation method to wrapperMock for improved mock access
* feat(tauri): bind getMockImplementation method to wrapperMock for enhanced mock functionality
* feat(native-spy): add test for initial implementation retrieval in mock function
- Introduced a new test case to verify that the mock function returns the initial implementation passed to it.
- This enhances the testing coverage for the `getMockImplementation` method, ensuring it behaves as expected.
* chore: standardize package.json files array formatting across multiple packages
* test(electron): add mocking.spec.ts to the test suite for enhanced coverage
* test(e2e): update test configurations to exclude specific tests for electron and tauri environments
- Added exclusion for window and deeplink tests in electron configuration.
- Updated tauri configurations to maintain exclusion of window and deeplink tests, removing mocking tests from the exclusion list.
- Ensured consistency across test specifications for improved test execution.
* feat(native-spy): enhance mock function with original implementation support
- Added `FnOptions` interface to allow passing an original function to the mock.
- Updated the `fn` function to call the original function if provided, improving mock behavior.
- Adjusted mock restoration to revert to the original function when available.
* feat(electron): enhance restore functionality for mocked Electron APIs
- Improved the `restoreElectronFunctionality` method to handle mock restoration more robustly, including fallback to original functions stored in `globalThis.originalApi`.
- Updated the `createMock` function to capture and store original functions for better restoration capabilities.
- Enhanced logging to provide detailed results of the restoration process, aiding in debugging and verification.
* fix(native-spy): improve mock function behavior and state management
- Enhanced the `fn` function to better handle mock restoration and state tracking.
- Introduced a `mockRestored` flag to manage the restoration state of mocks.
- Updated the implementation logic to ensure correct handling of resolved and rejected values.
- Cleared implementation queue during mock resets to prevent unintended behavior.
* feat(electron-service): enhance mock function logging and implementation handling
- Added debug logging to track calls to inner mock functions, improving traceability during testing.
- Refined the implementation logic in `createMock` to ensure proper handling of function implementations, enhancing mock behavior.
* feat(native-spy): enhance mock function state management and last call tracking
- Updated the `fn` function to include a non-enumerable `lastCall` property on the state, allowing for better tracking of the most recent call arguments.
- Added a `lastCall` property to the mock function, making it enumerable for easier access.
- Refined comments for clarity and alignment with vitest's approach to state management.
* feat(electron-service): add lastCall property to mock for improved call tracking
- Introduced a computed `lastCall` property on the mock function, providing convenient access to the most recent call made.
- Enhanced the mock's state management capabilities, aligning with previous improvements in tracking and logging.
* test(electron): add restoreMocks capability to Electron configuration and update mocking tests
- Introduced a `restoreMocks` property in the Electron capabilities configuration to enable automatic restoration of mocks.
- Updated the mocking tests to remove clipboard state management, ensuring that mocks are restored to their original state after execution.
* refactor(electron-service): streamline mock restoration logic and improve call tracking
- Simplified the `restoreElectronFunctionality` method to enhance clarity and efficiency in restoring mocks.
- Updated the fallback restoration logic to ensure consistent behavior and improved return values.
- Refined the `createMock` function to enhance call tracking and logging, ensuring better traceability during testing.
* refactor(native-spy): remove redundant implementation reset in mock functions
- Eliminated unnecessary resetting of the implementation function in `mockReturnValueOnce` and `mockResolvedValueOnce`, streamlining the mock behavior.
- Improved clarity and efficiency in the mock function's state management.
* feat(e2e-apps): add 'Show Dialog' button and functionality to invoke dialog
- Introduced a new button in the Electron app's UI to trigger a dialog.
- Implemented event listener to invoke the 'show-open-dialog' API when the button is clicked, enhancing user interaction.
* feat(electron): enhance mock functionality and error handling
- Introduced a new `createPrototypeMock` function to facilitate mocking of class methods, improving flexibility in mock creation.
- Enhanced error handling in the `execute` function to throw descriptive errors when script execution fails, improving debugging capabilities.
- Updated the `mock` method signature to support both class and function mocking, streamlining the API for users.
- Improved the `mockRejectedValue` method to handle Error instances more effectively, ensuring accurate error propagation.
* test(e2e): improve type handling and mock behavior in tests
- Updated type handling in mock implementations to ensure proper type assertions, enhancing type safety.
- Adjusted test expectations to reflect accurate call counts for mocked methods, improving test reliability.
- Refined mock restoration logic to verify original class names instead of instances, ensuring consistency in mock behavior.
* refactor(electron): extract mock creation into factory
- Added `createClassMock` function to facilitate mocking of Electron classes, allowing for dynamic method creation based on class prototypes.
- Implemented `createPrototypeMock` to streamline the mocking of individual class methods, improving flexibility in mock creation.
- Introduced `mockFactory` to centralize mock method handling, enhancing maintainability and clarity.
- Updated tests to validate new mocking capabilities and ensure accurate behavior of class and prototype mocks.
* docs(electron): improve ElectronClassMock jsdoc
- Enhanced the type definition for ElectronClassMock to better separate lifecycle members from dynamic method mocks.
- Clarified the return types for core mock methods and improved type safety for dynamic method access.
- Updated comments to provide a clearer understanding of the design rationale behind the type structure.
* refactor(e2e): improve type handling for Electron Tray mock
- Updated the Tray constructor calls in tests to correctly handle additional arguments, enhancing type safety with TypeScript.
- Adjusted method chaining for setTitle and setToolTip to reflect accurate return types, ensuring proper mock behavior in tests.
* feat(fixtures): add 'Show Dialog' button and event listener to forge e2e fixture
- Added a new button to the Electron app's UI for triggering a dialog.
- Implemented an event listener to invoke the 'show-open-dialog' API when the button is clicked, enhancing user interaction.
* test(native-spy): add tests for mockReturnValue, mockResolvedValue, and mockRejectedValue after mockRestore
- Added new test cases to verify that mockReturnValue, mockResolvedValue, and mockRejectedValue can be called after mockRestore, ensuring correct behavior of mock functions.
- Enhanced test coverage for the native-spy package by validating the restoration and reconfiguration of mock functions.
* fix(native-spy): correct mock return value handling
- Updated the mock function to ensure that the `defaultReturnValue` is correctly returned when defined, improving the accuracy of mock behavior.
- Removed redundant code that previously handled `defaultReturnValue`, streamlining the logic for returning values in mock functions.
* refactor(electron-service): remove restoreElectronFunctionality call from mockRestore
- Eliminated the call to restoreElectronFunctionality in the mockRestore method, simplifying the mock restoration process.
- Updated import statements to reflect the removal of unused functionality, enhancing code clarity.
* feat(tauri): enhance mock functionality and synchronization
- Improved the Tauri mocking implementation by simplifying the mock call tracking and synchronization process.
- Updated the `isMockFunction` method to accept both command names and mock function objects, enhancing usability.
- Added automatic synchronization of mock calls after executing commands, ensuring accurate call tracking.
- Enhanced error handling for undefined responses in the execute function, allowing for better handling of edge cases.
- Introduced tests to validate the new synchronization behavior and the updated `isMockFunction` logic, improving overall test coverage.
* refactor(electron-service): improve mockRejectedValue handling in mockFactory
- Simplified the logic in `mockRejectedValue` and `mockRejectedValueOnce` methods to handle Error instances more effectively.
- Enhanced type handling for both API and class method mocks, ensuring consistent behavior across different mock types.
- Improved error message propagation when rejecting promises, providing clearer context for error handling in tests.
* refactor(tauri-plugin): simplify invoke interception logic
- Removed complex proxy-based interception strategies for the invoke method, streamlining the setup process.
- Updated logging to reflect the fallback to mock routing via window.__wdio_mocks__ when defineProperty fails, improving clarity on interception status.
- Enhanced code readability by eliminating unnecessary fallback strategies while maintaining mock functionality.
* fix(tauri): correct return type for mockReturnThis method
- Updated the return type of the `mockReturnThis` method in the TauriMockInstance interface to return `Promise<TauriMock>` instead of `Promise<unknown>`, improving type safety and clarity.
- Adjusted the implementation in the `createMock` function to ensure consistent return type handling, enhancing overall mock functionality.
* fix(tauri): restore synchronous mockClear for consistent state management
- Temporarily reverted the mockClear function to synchronous behavior to prevent race conditions during state clearing in the createMock function.
- Ensured that outerMockClear is called immediately before outerMockReset, maintaining the integrity of mock state management.
* fix(tauri): update resetAllMocks and restoreAllMocks to handle undefined context
- Modified the `resetAllMocks` and `restoreAllMocks` functions to accept an optional `TauriServiceContext`, ensuring compatibility with undefined context scenarios.
- Adjusted the execution calls in both functions to replace `undefined` with an empty string when no command prefix is provided, improving consistency in mock handling.
- Updated related tests to reflect these changes, ensuring accurate expectations for the execution calls.
* chore(actions): update cache restore action to v5 and clean up whitespace
- Upgraded the cache restore action from v4 to v5 for improved performance and features.
- Removed unnecessary whitespace in the script for better readability and consistency.
* fix(e2e): increase mocha timeout for improved test stability
- Updated the mocha timeout setting from 60 seconds to 120 seconds to accommodate longer-running tests, enhancing overall test reliability.
* refactor(e2e): adjust clipboard mock handling in restoreAllMocks test
- Removed the clipboard write operation from the beforeEach hook to ensure mocks are restored before any clipboard interactions.
- Moved the clipboard write operation to after the restoreAllMocks call, clarifying the test flow and ensuring accurate mock state during execution.
* fix(e2e): enforce sequential test execution in embedded mode
- Set maxInstances to 1 for embedded mode tests to ensure that the shared Tauri app instance is properly managed.
- Added comments to clarify the need for sequential execution due to global shared state across workers, preventing potential conflicts during test runs.
* chore(actions): update vscode-server-action to v1.4.0 for improved debugging
- Upgraded the vscode-server-action from v1.3.0 to v1.4.0 across multiple workflow files to enhance debugging capabilities during test failures.
- Ensured consistent timeout settings for the debugging sessions in the respective workflows.
* fix(e2e): simplify title verification in main window test
- Replaced the manual title retrieval and expectation with a more concise matcher using `toHaveTitle`, improving readability and maintainability of the test code.
- Ensured that the test still accurately verifies the application window title for the Electron E2E test app.
* chore(actions): upgrade cache save action to v5 for enhanced performance
- Updated the cache save action from v4 to v5 to leverage improved features and performance.
- Ensured compatibility with the latest caching mechanisms in the workflow configuration.
* fix(tauri): enhance error handling in mock rejection methods
- Updated `mockRejectedValue` and `mockRejectedValueOnce` to differentiate between `Error` instances and other values, ensuring that error messages are properly passed when an `Error` is rejected.
- Improved type handling in the mock functions to enhance clarity and maintainability of the code.
* fix(e2e): enhance error message preservation in Tauri mocking tests
- Added new test cases to verify that `mockRejectedValue` and `mockRejectedValueOnce` correctly preserve error messages when rejecting with `Error` objects.
- Ensured that the error messages are accurately returned in the execution context, improving the robustness of error handling in the mocking framework.
* chore(actions): upgrade vscode-server-action to v1.5.0 for enhanced debugging
- Updated the vscode-server-action from v1.4.0 to v1.5.0 across multiple workflow files to improve debugging capabilities during test failures.
- Ensured consistent timeout settings for the debugging sessions in the respective workflows.
* fix(electron): ensure synchronous mockClear behavior in class and mock methods
- Temporarily restored synchronous behavior for mockClear in both createClassMock and buildMockMethods to prevent race conditions with async operations.
- Updated comments for clarity on the purpose of these changes, enhancing maintainability and understanding of the code flow.
* fix(tauri): clear stale mocks at session start for embedded driver provider
- Implemented logic to reset `window.__wdio_mocks__` at the beginning of each session when using the embedded driver provider, ensuring a clean state for tests.
- Added tests to verify the clearing of stale mocks for embedded providers and confirm that non-embedded providers do not clear mocks.
- Enhanced error handling to gracefully manage failures during the clearing process.1 parent 9dfa3a0 commit e122474
45 files changed
Lines changed: 2017 additions & 900 deletions
File tree
- .github/workflows
- actions
- download-archive
- upload-archive
- e2e
- test
- electron
- standalone
- tauri
- fixtures/e2e-apps
- electron-forge/src/renderer
- electron-script/src/renderer
- packages
- electron-cdp-bridge
- electron-service
- src
- commands
- test
- native-spy
- src
- test
- native-types
- src
- native-utils
- tauri-plugin
- guest-js
- __tests__
- src
- tauri-service
- src
- commands
- test
- commands
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
539 | 539 | | |
540 | 540 | | |
541 | 541 | | |
542 | | - | |
| 542 | + | |
543 | 543 | | |
544 | 544 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
253 | 253 | | |
254 | 254 | | |
255 | 255 | | |
256 | | - | |
| 256 | + | |
257 | 257 | | |
258 | 258 | | |
259 | 259 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
241 | 241 | | |
242 | 242 | | |
243 | 243 | | |
244 | | - | |
| 244 | + | |
245 | 245 | | |
246 | 246 | | |
247 | 247 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | | - | |
| 63 | + | |
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
| |||
194 | 194 | | |
195 | 195 | | |
196 | 196 | | |
197 | | - | |
| 197 | + | |
198 | 198 | | |
199 | 199 | | |
200 | 200 | | |
201 | | - | |
| 201 | + | |
202 | 202 | | |
203 | 203 | | |
204 | 204 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
236 | 236 | | |
237 | 237 | | |
238 | 238 | | |
239 | | - | |
| 239 | + | |
240 | 240 | | |
241 | 241 | | |
242 | 242 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
275 | 275 | | |
276 | 276 | | |
277 | 277 | | |
278 | | - | |
279 | | - | |
280 | | - | |
281 | | - | |
282 | | - | |
283 | | - | |
284 | 278 | | |
285 | 279 | | |
286 | 280 | | |
| |||
291 | 285 | | |
292 | 286 | | |
293 | 287 | | |
294 | | - | |
295 | | - | |
296 | 288 | | |
297 | 289 | | |
298 | 290 | | |
| |||
896 | 888 | | |
897 | 889 | | |
898 | 890 | | |
899 | | - | |
900 | | - | |
| 891 | + | |
| 892 | + | |
901 | 893 | | |
902 | 894 | | |
903 | 895 | | |
| |||
952 | 944 | | |
953 | 945 | | |
954 | 946 | | |
955 | | - | |
| 947 | + | |
956 | 948 | | |
957 | | - | |
958 | | - | |
959 | | - | |
| 949 | + | |
960 | 950 | | |
961 | 951 | | |
962 | | - | |
| 952 | + | |
963 | 953 | | |
964 | 954 | | |
965 | 955 | | |
| |||
969 | 959 | | |
970 | 960 | | |
971 | 961 | | |
972 | | - | |
973 | | - | |
974 | | - | |
975 | | - | |
| 962 | + | |
| 963 | + | |
976 | 964 | | |
| 965 | + | |
977 | 966 | | |
978 | 967 | | |
979 | 968 | | |
| |||
1043 | 1032 | | |
1044 | 1033 | | |
1045 | 1034 | | |
| 1035 | + | |
1046 | 1036 | | |
1047 | 1037 | | |
1048 | 1038 | | |
| |||
1059 | 1049 | | |
1060 | 1050 | | |
1061 | 1051 | | |
1062 | | - | |
| 1052 | + | |
| 1053 | + | |
1063 | 1054 | | |
1064 | 1055 | | |
1065 | 1056 | | |
| |||
1069 | 1060 | | |
1070 | 1061 | | |
1071 | 1062 | | |
1072 | | - | |
1073 | | - | |
| 1063 | + | |
| 1064 | + | |
1074 | 1065 | | |
1075 | 1066 | | |
1076 | 1067 | | |
| |||
1087 | 1078 | | |
1088 | 1079 | | |
1089 | 1080 | | |
1090 | | - | |
1091 | | - | |
1092 | | - | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
1093 | 1084 | | |
1094 | | - | |
1095 | | - | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
1096 | 1088 | | |
1097 | 1089 | | |
1098 | 1090 | | |
| |||
1149 | 1141 | | |
1150 | 1142 | | |
1151 | 1143 | | |
1152 | | - | |
| 1144 | + | |
1153 | 1145 | | |
1154 | 1146 | | |
1155 | 1147 | | |
| |||
1164 | 1156 | | |
1165 | 1157 | | |
1166 | 1158 | | |
1167 | | - | |
1168 | | - | |
1169 | | - | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
1170 | 1162 | | |
1171 | 1163 | | |
1172 | 1164 | | |
| |||
1177 | 1169 | | |
1178 | 1170 | | |
1179 | 1171 | | |
| 1172 | + | |
1180 | 1173 | | |
1181 | 1174 | | |
1182 | 1175 | | |
| |||
1201 | 1194 | | |
1202 | 1195 | | |
1203 | 1196 | | |
1204 | | - | |
| 1197 | + | |
1205 | 1198 | | |
1206 | 1199 | | |
1207 | 1200 | | |
| |||
1285 | 1278 | | |
1286 | 1279 | | |
1287 | 1280 | | |
1288 | | - | |
| 1281 | + | |
1289 | 1282 | | |
1290 | 1283 | | |
1291 | 1284 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
| 27 | + | |
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
55 | | - | |
56 | | - | |
57 | | - | |
| 55 | + | |
58 | 56 | | |
59 | 57 | | |
60 | 58 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | 126 | | |
133 | 127 | | |
134 | 128 | | |
| |||
138 | 132 | | |
139 | 133 | | |
140 | 134 | | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
141 | 140 | | |
142 | 141 | | |
143 | 142 | | |
| |||
165 | 164 | | |
166 | 165 | | |
167 | 166 | | |
168 | | - | |
169 | 167 | | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
| 168 | + | |
176 | 169 | | |
177 | 170 | | |
178 | 171 | | |
179 | | - | |
| 172 | + | |
180 | 173 | | |
181 | 174 | | |
182 | 175 | | |
| |||
296 | 289 | | |
297 | 290 | | |
298 | 291 | | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
299 | 307 | | |
300 | 308 | | |
301 | 309 | | |
| |||
331 | 339 | | |
332 | 340 | | |
333 | 341 | | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
334 | 363 | | |
335 | 364 | | |
336 | 365 | | |
| |||
558 | 587 | | |
559 | 588 | | |
560 | 589 | | |
561 | | - | |
| 590 | + | |
562 | 591 | | |
563 | 592 | | |
564 | 593 | | |
565 | | - | |
566 | | - | |
567 | | - | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
568 | 602 | | |
569 | 603 | | |
570 | | - | |
| 604 | + | |
571 | 605 | | |
572 | 606 | | |
573 | 607 | | |
574 | 608 | | |
575 | | - | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
576 | 622 | | |
577 | 623 | | |
578 | 624 | | |
| |||
0 commit comments