Fix Promise scope issues and adopt proven integration testing patterns#41
Fix Promise scope issues and adopt proven integration testing patterns#41DutchmanNL merged 5 commits intomainfrom
Conversation
Co-authored-by: DutchmanNL <7318445+DutchmanNL@users.noreply.github.com>
Co-authored-by: DutchmanNL <7318445+DutchmanNL@users.noreply.github.com>
There was a problem hiding this comment.
Pull Request Overview
This PR corrects Promise handling in the integration testing examples within template.md to ensure proper error propagation and test failure behavior.
- Add reject to Promise constructors and replace resolve on errors with reject(err)
- Add error checks in nested state callbacks and reject on failures
- Update CHANGELOG with a WIP entry documenting the fix
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| template.md | Fix Promise executor signatures and error handling in testing examples to prevent false-positive test passes. |
| CHANGELOG.md | Add WIP entry describing the Promise scope/error handling fix (Fixes #15). |
template.md
Outdated
| } | ||
| resolve(); | ||
| }); | ||
| }, 15000); // Allow time for API calls |
There was a problem hiding this comment.
[nitpick] 15000 is a magic number; consider extracting these timeouts to a named constant (e.g., const STATE_CHECK_DELAY_MS = 15000) and using it consistently (also at line 223 which uses 10000) to make intent clear and reduce flakiness relative to the overall test timeout.
|
@copilot Passe die Besipiele nach diesem spezifischen funktionierenden Intergrationtest an - Dabei beachten das es eine generische Anweisung sein soll. https://github.com/ticaki/ioBroker.brightsky/blob/main/test/integration-brightsky.js |
|
@ticaki please review
@copilot adopt suggestion |
Co-authored-by: DutchmanNL <7318445+DutchmanNL@users.noreply.github.com>
I've updated the integration testing examples in the template to match the proven working patterns from ticaki's brightsky adapter. The changes include:
The examples now demonstrate real-world patterns that are proven to work in production adapters. Commit: da27dfc |
| resolve(); | ||
| console.log('🔍 Step 1: Fetching adapter object...'); | ||
| const obj = await new Promise((res, rej) => { | ||
| harness.objects.getObject('system.adapter.your-adapter.0', (err, o) => { |
There was a problem hiding this comment.
Multiple references use 'your-adapter' while the main example uses 'brightsky'. All adapter references should be consistent - either use a placeholder like 'your-adapter' throughout or use 'brightsky' throughout the examples.
|
|
||
| console.log('🔍 Step 1: Fetching adapter object...'); | ||
| const obj = await new Promise((res, rej) => { | ||
| harness.objects.getObject('system.adapter.your-adapter.0', (err, o) => { |
There was a problem hiding this comment.
Multiple references use 'your-adapter' while the main example uses 'brightsky'. All adapter references should be consistent - either use a placeholder like 'your-adapter' throughout or use 'brightsky' throughout the examples.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
man sollte von hand noch nach brightsky.0 suchen und das durch your-adapter.0 ersetzen oder so |
The integration testing examples in
template.mdcontained JavaScript scope issues that were correctly identified in PR #12 review comments, and have been updated to adopt proven working patterns from real ioBroker adapters.Original Issues Fixed
rejectparameter: Promise constructors usednew Promise(async (resolve) => {...})instead ofnew Promise(async (resolve, reject) => {...})resolve()instead ofreject(err), making tests pass when they should failrejectfunction wasn't available in nested async callbacksAdopted Proven Patterns
Based on feedback from @DutchmanNL and @ticaki, the examples have been updated to match the working integration test patterns from ticaki's brightsky adapter:
Enhanced Test Structure:
Key Pattern Improvements:
function()instead of arrow functions for better timeout handlingharness.dbConnection.getStateIDs()to validate all created statesawait harness.stopAdapter()is calledUpdated Test Examples:
All automated tests continue to pass, and the JavaScript syntax validation confirms the integration testing examples now follow production-ready patterns that are proven to work in real ioBroker adapters.
Fixes #15.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.