-
Notifications
You must be signed in to change notification settings - Fork 2
Fix Promise scope issues and adopt proven integration testing patterns #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
051635a
b6ca52d
da27dfc
fe6858b
49c5519
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -93,12 +93,12 @@ tests.integration(path.join(__dirname, '..'), { | |
| harness = getHarness(); | ||
| }); | ||
|
|
||
| it('should configure and start adapter', () => new Promise(async (resolve) => { | ||
| it('should configure and start adapter', () => new Promise(async (resolve, reject) => { | ||
| // Get adapter object and configure | ||
| harness.objects.getObject('system.adapter.brightsky.0', async (err, obj) => { | ||
| if (err) { | ||
| console.error('Error getting adapter object:', err); | ||
| resolve(); | ||
| reject(err); | ||
| return; | ||
| } | ||
|
|
||
|
|
@@ -119,10 +119,16 @@ tests.integration(path.join(__dirname, '..'), { | |
| setTimeout(() => { | ||
| // Verify states were created | ||
| harness.states.getState('brightsky.0.info.connection', (err, state) => { | ||
| if (err) { | ||
| reject(err); | ||
| return; | ||
| } | ||
| if (state && state.val === true) { | ||
| console.log('✅ Adapter started successfully'); | ||
| resolve(); | ||
| } else { | ||
| reject(new Error('Adapter failed to start - connection state is not true')); | ||
| } | ||
| resolve(); | ||
| }); | ||
| }, 15000); // Allow time for API calls | ||
|
||
| }); | ||
|
|
@@ -138,16 +144,16 @@ tests.integration(path.join(__dirname, '..'), { | |
|
|
||
| ```javascript | ||
| // Example: Testing successful configuration | ||
| it('should configure and start adapter with valid configuration', () => new Promise(async (resolve) => { | ||
| it('should configure and start adapter with valid configuration', () => new Promise(async (resolve, reject) => { | ||
| // ... successful configuration test as shown above | ||
| })).timeout(30000); | ||
|
|
||
| // Example: Testing failure scenarios | ||
| it('should fail gracefully with invalid configuration', () => new Promise(async (resolve) => { | ||
| it('should fail gracefully with invalid configuration', () => new Promise(async (resolve, reject) => { | ||
| harness.objects.getObject('system.adapter.brightsky.0', async (err, obj) => { | ||
| if (err) { | ||
| console.error('Error getting adapter object:', err); | ||
DutchmanNL marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| resolve(); | ||
| reject(err); | ||
| return; | ||
| } | ||
|
|
||
|
|
@@ -163,12 +169,17 @@ it('should fail gracefully with invalid configuration', () => new Promise(async | |
| setTimeout(() => { | ||
| // Verify adapter handled the error properly | ||
| harness.states.getState('brightsky.0.info.connection', (err, state) => { | ||
| if (err) { | ||
| reject(err); | ||
| return; | ||
| } | ||
| if (state && state.val === false) { | ||
| console.log('✅ Adapter properly failed with invalid configuration'); | ||
| resolve(); | ||
| } else { | ||
| console.log('❌ Adapter should have failed but connection shows true'); | ||
| reject(new Error('Adapter should have failed with invalid configuration')); | ||
| } | ||
| resolve(); | ||
| }); | ||
| }, 15000); | ||
| } catch (error) { | ||
|
|
@@ -179,11 +190,11 @@ it('should fail gracefully with invalid configuration', () => new Promise(async | |
| })).timeout(30000); | ||
|
|
||
| // Example: Testing missing required configuration | ||
| it('should fail when required configuration is missing', () => new Promise(async (resolve) => { | ||
| it('should fail when required configuration is missing', () => new Promise(async (resolve, reject) => { | ||
| harness.objects.getObject('system.adapter.brightsky.0', async (err, obj) => { | ||
| if (err) { | ||
| console.error('Error getting adapter object:', err); | ||
DutchmanNL marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| resolve(); | ||
| reject(err); | ||
| return; | ||
| } | ||
|
|
||
|
|
@@ -197,12 +208,17 @@ it('should fail when required configuration is missing', () => new Promise(async | |
|
|
||
| setTimeout(() => { | ||
| harness.states.getState('brightsky.0.info.connection', (err, state) => { | ||
| if (err) { | ||
| reject(err); | ||
| return; | ||
| } | ||
| if (!state || state.val === false) { | ||
| console.log('✅ Adapter properly failed with missing required configuration'); | ||
| resolve(); | ||
| } else { | ||
| console.log('❌ Adapter should have failed but connection shows true'); | ||
| reject(new Error('Adapter should have failed with missing configuration')); | ||
| } | ||
| resolve(); | ||
| }); | ||
| }, 10000); | ||
| } catch (error) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.