@@ -18,73 +18,79 @@ const testConfig = {
1818 system : {
1919 memoryLimitMB : 0 ,
2020 hostname : '' ,
21- instanceStartInterval : 2000
21+ instanceStartInterval : 2000 ,
2222 } ,
2323 objects : {
2424 type : 'file' ,
2525 host : '127.0.0.1' ,
2626 port : 19011 ,
27- dataDir : path . join ( testDir , 'objects' )
27+ dataDir : path . join ( testDir , 'objects' ) ,
2828 } ,
2929 states : {
30- type : 'file' ,
30+ type : 'file' ,
3131 host : '127.0.0.1' ,
3232 port : 19010 ,
33- dataDir : path . join ( testDir , 'states' )
33+ dataDir : path . join ( testDir , 'states' ) ,
3434 } ,
3535 log : {
3636 level : 'warn' ,
3737 noStdout : true ,
3838 transport : {
3939 file1 : {
4040 type : 'file' ,
41- enabled : false
42- }
43- }
41+ enabled : false ,
42+ } ,
43+ } ,
4444 } ,
4545 dataDir : testDir ,
46- plugins : { }
46+ plugins : { } ,
4747} ;
4848
4949/**
5050 * Helper function to run CLI commands for lifecycle tests
51+ *
52+ * @param args - CLI command arguments to pass
53+ * @param timeout - Command timeout in milliseconds
5154 */
52- function runCliCommand ( args : string [ ] , timeout = 45000 ) : Promise < { exitCode : number | null ; stdout : string ; stderr : string } > {
53- return new Promise ( ( resolve ) => {
55+ function runCliCommand (
56+ args : string [ ] ,
57+ timeout = 45000 ,
58+ ) : Promise < { exitCode : number | null ; stdout : string ; stderr : string } > {
59+ return new Promise ( resolve => {
5460 const nodeExecutable = process . execPath ;
5561 const cliScript = path . join ( thisDir , '../../controller/iobroker.js' ) ;
56-
62+
5763 // Set environment variable for test config
5864 const env = { ...process . env , IOB_CONF_FILE : testConfigPath } ;
59-
65+
6066 const child = spawn ( nodeExecutable , [ cliScript , ...args ] , {
6167 env,
6268 cwd : path . join ( thisDir , '../..' ) ,
63- stdio : [ 'pipe' , 'pipe' , 'pipe' ]
69+ stdio : [ 'pipe' , 'pipe' , 'pipe' ] ,
6470 } ) ;
6571
6672 let stdout = '' ;
6773 let stderr = '' ;
6874
69- child . stdout ?. on ( 'data' , ( data ) => {
75+ child . stdout ?. on ( 'data' , data => {
7076 stdout += data . toString ( ) ;
7177 } ) ;
7278
73- child . stderr ?. on ( 'data' , ( data ) => {
79+ child . stderr ?. on ( 'data' , data => {
7480 stderr += data . toString ( ) ;
7581 } ) ;
7682
7783 const timeoutId = setTimeout ( ( ) => {
7884 child . kill ( 'SIGTERM' ) ;
79- resolve ( { exitCode : - 1 , stdout, stderr : stderr + ' \nTIMEOUT' } ) ;
85+ resolve ( { exitCode : - 1 , stdout, stderr : ` ${ stderr } \nTIMEOUT` } ) ;
8086 } , timeout ) ;
8187
82- child . on ( 'close' , ( exitCode ) => {
88+ child . on ( 'close' , exitCode => {
8389 clearTimeout ( timeoutId ) ;
8490 resolve ( { exitCode, stdout, stderr } ) ;
8591 } ) ;
8692
87- child . on ( 'error' , ( error ) => {
93+ child . on ( 'error' , error => {
8894 clearTimeout ( timeoutId ) ;
8995 resolve ( { exitCode : - 1 , stdout, stderr : stderr + error . message } ) ;
9096 } ) ;
@@ -133,7 +139,7 @@ describe('Adapter Lifecycle Tests', function () {
133139
134140 it ( 'should list adapters and show installed adapters' , async function ( ) {
135141 const result = await runCliCommand ( [ 'list' , 'adapters' ] ) ;
136-
142+
137143 expect ( result . exitCode ) . to . equal ( 0 ) ;
138144 // Should not timeout or crash
139145 expect ( result . stderr ) . to . not . include ( 'TIMEOUT' ) ;
@@ -142,14 +148,14 @@ describe('Adapter Lifecycle Tests', function () {
142148 it ( 'should create an adapter instance (if adapter is available)' , async function ( ) {
143149 // First check if adapter exists
144150 const listResult = await runCliCommand ( [ 'list' , 'adapters' ] ) ;
145-
151+
146152 if ( listResult . stdout . includes ( testAdapter ) ) {
147153 // Try to create an instance
148154 const result = await runCliCommand ( [ 'add' , testAdapter , '--enabled' , 'false' ] ) ;
149-
155+
150156 // The command should complete without crashing
151157 expect ( result . stderr ) . to . not . include ( 'TIMEOUT' ) ;
152-
158+
153159 // If successful, should show in instance list
154160 if ( result . exitCode === 0 ) {
155161 const instancesResult = await runCliCommand ( [ 'list' , 'instances' ] ) ;
@@ -165,26 +171,26 @@ describe('Adapter Lifecycle Tests', function () {
165171
166172 it ( 'should list instances and show created instances' , async function ( ) {
167173 const result = await runCliCommand ( [ 'list' , 'instances' ] ) ;
168-
174+
169175 expect ( result . exitCode ) . to . equal ( 0 ) ;
170176 expect ( result . stderr ) . to . not . include ( 'TIMEOUT' ) ;
171177 } ) ;
172178
173179 it ( 'should delete adapter instance (if one exists)' , async function ( ) {
174180 // List existing instances first
175181 const listResult = await runCliCommand ( [ 'list' , 'instances' ] ) ;
176-
182+
177183 if ( listResult . stdout . includes ( `${ testAdapter } .` ) ) {
178184 // Extract instance number from output (assuming format adapter.X)
179185 const instanceMatch = listResult . stdout . match ( new RegExp ( `${ testAdapter } \\.(\\d+)` ) ) ;
180-
186+
181187 if ( instanceMatch ) {
182188 const instanceNum = instanceMatch [ 1 ] ;
183189 const result = await runCliCommand ( [ 'del' , `${ testAdapter } .${ instanceNum } ` ] ) ;
184-
190+
185191 // Should complete without crashing
186192 expect ( result . stderr ) . to . not . include ( 'TIMEOUT' ) ;
187-
193+
188194 // Verify deletion by listing instances again
189195 const afterDeleteResult = await runCliCommand ( [ 'list' , 'instances' ] ) ;
190196 expect ( afterDeleteResult . exitCode ) . to . equal ( 0 ) ;
@@ -197,7 +203,7 @@ describe('Adapter Lifecycle Tests', function () {
197203
198204 it ( 'should handle attempt to delete non-existent instance gracefully' , async function ( ) {
199205 const result = await runCliCommand ( [ 'del' , 'non-existent-adapter.99' ] ) ;
200-
206+
201207 // Should not crash or timeout
202208 expect ( result . stderr ) . to . not . include ( 'TIMEOUT' ) ;
203209 // Should return with some error indication but not crash
@@ -206,7 +212,7 @@ describe('Adapter Lifecycle Tests', function () {
206212
207213 it ( 'should handle attempt to add non-existent adapter gracefully' , async function ( ) {
208214 const result = await runCliCommand ( [ 'add' , 'definitely-non-existent-adapter-xyz123' ] ) ;
209-
215+
210216 // Should not crash or timeout
211217 expect ( result . stderr ) . to . not . include ( 'TIMEOUT' ) ;
212218 // Should return error code for non-existent adapter
@@ -232,4 +238,4 @@ describe('Adapter Lifecycle Tests', function () {
232238 console . log ( `States directory contains ${ stateFiles . length } files` ) ;
233239 } ) ;
234240 } ) ;
235- } ) ;
241+ } ) ;
0 commit comments