@iobroker/legacy-testing 0.3.3 → 0.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/package.json +1 -1
- package/setup.js +25 -77
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ Legacy test modules for ioBroker
|
|
|
11
11
|
|
|
12
12
|
## Changelog
|
|
13
13
|
<!-- ### **WORK IN PROGRESS** -->
|
|
14
|
-
### 0.3.
|
|
14
|
+
### 0.3.5 (2023-05-08)
|
|
15
15
|
* (bluefox) Added possibility to install additional adapters at start
|
|
16
16
|
* (bluefox) Added setOfflineState/getOfflineState
|
|
17
17
|
|
package/package.json
CHANGED
package/setup.js
CHANGED
|
@@ -262,8 +262,13 @@ async function installAdapter(customAdapterName, cb) {
|
|
|
262
262
|
cb = customAdapterName;
|
|
263
263
|
customAdapterName = null;
|
|
264
264
|
}
|
|
265
|
-
customAdapterName
|
|
266
|
-
|
|
265
|
+
console.log(`[${customAdapterName || pkg.name}] Install adapter...`);
|
|
266
|
+
|
|
267
|
+
// if own adapter
|
|
268
|
+
if (!customAdapterName) {
|
|
269
|
+
installCustomAdapter(pkg.name); // force install from the current directory
|
|
270
|
+
customAdapterName = pkg.name;
|
|
271
|
+
}
|
|
267
272
|
|
|
268
273
|
if (customAdapterName.includes('@')) {
|
|
269
274
|
installCustomAdapter(customAdapterName);
|
|
@@ -288,29 +293,7 @@ async function installAdapter(customAdapterName, cb) {
|
|
|
288
293
|
|
|
289
294
|
const name = (customAdapterName.split('@')[0]).split('.').pop(); // extract from iobroker.adaptername@version => adaptername
|
|
290
295
|
|
|
291
|
-
|
|
292
|
-
await checkIsAdapterInstalledAsync(null, name);
|
|
293
|
-
} catch (err) {
|
|
294
|
-
console.warn(`[${customAdapterName}] Adapter not installed: ${err}`);
|
|
295
|
-
// try workaround
|
|
296
|
-
installCustomAdapter(customAdapterName);
|
|
297
|
-
// make first install
|
|
298
|
-
if (debug) {
|
|
299
|
-
cp.execSync(`node ${startFile} add ${customAdapterName} --enabled false`, {
|
|
300
|
-
cwd: `${rootDir}tmp`,
|
|
301
|
-
stdio: [0, 1, 2],
|
|
302
|
-
});
|
|
303
|
-
} else {
|
|
304
|
-
// add controller
|
|
305
|
-
const _pid = cp.fork(startFile, ['add', customAdapterName, '--enabled', 'false'], {
|
|
306
|
-
cwd: `${rootDir}tmp`,
|
|
307
|
-
stdio: [0, 1, 2, 'ipc'],
|
|
308
|
-
});
|
|
309
|
-
|
|
310
|
-
await waitForEndAsync(_pid);
|
|
311
|
-
}
|
|
312
|
-
await checkIsAdapterInstalledAsync(null, name);
|
|
313
|
-
}
|
|
296
|
+
await checkIsAdapterInstalledAsync(null, name);
|
|
314
297
|
console.log(`[${customAdapterName}] Adapter installed.`);
|
|
315
298
|
cb && cb();
|
|
316
299
|
}
|
|
@@ -320,25 +303,6 @@ function installAdapterAsync(customAdapterName) {
|
|
|
320
303
|
installAdapter(customAdapterName, () => resolve()));
|
|
321
304
|
}
|
|
322
305
|
|
|
323
|
-
function waitForEnd(_pid, cb) {
|
|
324
|
-
if (!_pid) {
|
|
325
|
-
cb(-1, -1);
|
|
326
|
-
} else {
|
|
327
|
-
_pid.on('exit', (code, signal) => {
|
|
328
|
-
if (_pid) {
|
|
329
|
-
_pid = null;
|
|
330
|
-
cb(code, signal);
|
|
331
|
-
}
|
|
332
|
-
});
|
|
333
|
-
_pid.on('close', (code, signal) => {
|
|
334
|
-
if (_pid) {
|
|
335
|
-
_pid = null;
|
|
336
|
-
cb(code, signal);
|
|
337
|
-
}
|
|
338
|
-
});
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
|
|
342
306
|
function waitForEndAsync(_pid) {
|
|
343
307
|
if (!_pid) {
|
|
344
308
|
return {code: -1, signal: -1};
|
|
@@ -414,13 +378,14 @@ async function installJsController(preInstalledAdapters, cb) {
|
|
|
414
378
|
stdio: [0, 1, 2, 'ipc']
|
|
415
379
|
});
|
|
416
380
|
}
|
|
417
|
-
await
|
|
381
|
+
await waitForEndAsync(__pid);
|
|
418
382
|
await checkIsControllerInstalledAsync();
|
|
419
383
|
} else {
|
|
420
384
|
// check if port 9000 is free, else admin adapter will be added to running instance
|
|
421
385
|
const {Socket} = require('net')
|
|
422
386
|
const client = new Socket();
|
|
423
387
|
client.on('error', () => {
|
|
388
|
+
// ignore
|
|
424
389
|
});
|
|
425
390
|
client.connect(9000, '127.0.0.1', () => {
|
|
426
391
|
console.error('Cannot initiate the first run of test, because one instance of application is running on this PC. Stop it and repeat.');
|
|
@@ -452,7 +417,7 @@ async function installJsController(preInstalledAdapters, cb) {
|
|
|
452
417
|
stdio: [0, 1, 2, 'ipc'],
|
|
453
418
|
});
|
|
454
419
|
}
|
|
455
|
-
await
|
|
420
|
+
await waitForEndAsync(__pid);
|
|
456
421
|
}
|
|
457
422
|
|
|
458
423
|
// let npm install admin and run setup
|
|
@@ -498,7 +463,7 @@ async function installJsController(preInstalledAdapters, cb) {
|
|
|
498
463
|
function copyAdapterToController() {
|
|
499
464
|
console.log('Copy adapter...');
|
|
500
465
|
// Copy adapter to tmp/node_modules/appName.adapter
|
|
501
|
-
copyFolderRecursiveSync(rootDir, `${rootDir}tmp/node_modules/`, ['.github', '.idea', 'test', 'tmp', '.git', 'src', 'src-widgets', `${appName}.js-controller`]);
|
|
466
|
+
copyFolderRecursiveSync(rootDir, `${rootDir}tmp/node_modules/`, ['node_modules', '.github', '.idea', 'test', 'tmp', '.git', 'src', 'src-widgets', `${appName}.js-controller`]);
|
|
502
467
|
console.log('Adapter copied.');
|
|
503
468
|
}
|
|
504
469
|
|
|
@@ -709,9 +674,11 @@ function startController(isStartAdapter, onObjectChange, onStateChange, callback
|
|
|
709
674
|
onObjectChange = undefined;
|
|
710
675
|
}
|
|
711
676
|
|
|
712
|
-
if (pids
|
|
677
|
+
if (pids.controller) {
|
|
713
678
|
console.error('Controller is already started!');
|
|
714
679
|
} else {
|
|
680
|
+
pids.controller = true;
|
|
681
|
+
|
|
715
682
|
console.log('startController...');
|
|
716
683
|
try {
|
|
717
684
|
const config = require(`${rootDir}tmp/${appName}-data/${appName}.json`);
|
|
@@ -762,7 +729,7 @@ function startController(isStartAdapter, onObjectChange, onStateChange, callback
|
|
|
762
729
|
|
|
763
730
|
// Just open in memory DB itself
|
|
764
731
|
const statePath = require.resolve(`@iobroker/db-states-${config.states.type}`, {
|
|
765
|
-
paths: [
|
|
732
|
+
paths: [`${rootDir}tmp/node_modules`, rootDir, `${rootDir}tmp/node_modules/${appName}.js-controller`],
|
|
766
733
|
});
|
|
767
734
|
console.log(`States Path: ${statePath}`);
|
|
768
735
|
const States = require(statePath).Server;
|
|
@@ -815,34 +782,13 @@ function startController(isStartAdapter, onObjectChange, onStateChange, callback
|
|
|
815
782
|
}
|
|
816
783
|
}
|
|
817
784
|
|
|
818
|
-
function stopAdapter(cb) {
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
console.error('Controller is not running!');
|
|
822
|
-
cb && setTimeout(() => cb(false), 0);
|
|
823
|
-
} else {
|
|
824
|
-
adaptersStarted[id] = false;
|
|
825
|
-
pids[id].on('exit', (code, signal) => {
|
|
826
|
-
if (pids[id]) {
|
|
827
|
-
console.log(`child process terminated due to receipt of signal ${signal}`);
|
|
828
|
-
cb && cb();
|
|
829
|
-
pids[id] = null;
|
|
830
|
-
}
|
|
831
|
-
});
|
|
832
|
-
|
|
833
|
-
pids[id].on('close', (/* code, signal */) => {
|
|
834
|
-
if (pids[id]) {
|
|
835
|
-
cb && cb();
|
|
836
|
-
pids[id] = null;
|
|
837
|
-
}
|
|
838
|
-
});
|
|
839
|
-
|
|
840
|
-
pids[id].kill('SIGTERM');
|
|
841
|
-
}
|
|
785
|
+
async function stopAdapter(cb) {
|
|
786
|
+
await stopCustomAdapter();
|
|
787
|
+
cb && cb();
|
|
842
788
|
}
|
|
843
789
|
|
|
844
790
|
function stopCustomAdapter(adapterName, adapterInstance) {
|
|
845
|
-
const id = `${adapterName}.${adapterInstance || 0}`;
|
|
791
|
+
const id = `${adapterName || pkg.name.split('.')[1]}.${adapterInstance || 0}`;
|
|
846
792
|
if (!pids[id]) {
|
|
847
793
|
console.error(`Adapter instance ${id} is not running!`);
|
|
848
794
|
return Promise.resolve();
|
|
@@ -881,10 +827,11 @@ function _stopController() {
|
|
|
881
827
|
}
|
|
882
828
|
|
|
883
829
|
function stopController(cb) {
|
|
830
|
+
const id = `${pkg.name.split('.')[1]}.0`;
|
|
884
831
|
let timeout;
|
|
885
832
|
if (objects) {
|
|
886
|
-
console.log(`Set system.adapter.${
|
|
887
|
-
objects.setObject(`system.adapter.${
|
|
833
|
+
console.log(`Set system.adapter.${id}`);
|
|
834
|
+
objects.setObject(`system.adapter.${id}`, {
|
|
888
835
|
common: {
|
|
889
836
|
enabled: false,
|
|
890
837
|
},
|
|
@@ -903,6 +850,7 @@ function stopController(cb) {
|
|
|
903
850
|
cb(true);
|
|
904
851
|
cb = null;
|
|
905
852
|
}
|
|
853
|
+
pids.controller = null;
|
|
906
854
|
});
|
|
907
855
|
|
|
908
856
|
timeout = setTimeout(() => {
|
|
@@ -915,7 +863,7 @@ function stopController(cb) {
|
|
|
915
863
|
cb(false);
|
|
916
864
|
cb = null;
|
|
917
865
|
}
|
|
918
|
-
pids
|
|
866
|
+
pids.controller = null;
|
|
919
867
|
}, 5000);
|
|
920
868
|
}
|
|
921
869
|
|