@iobroker/legacy-testing 0.3.2 → 0.3.4

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.
Files changed (3) hide show
  1. package/README.md +1 -1
  2. package/package.json +1 -1
  3. package/setup.js +15 -32
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.2 (2023-05-08)
14
+ ### 0.3.4 (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
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.3.2",
2
+ "version": "0.3.4",
3
3
  "name": "@iobroker/legacy-testing",
4
4
  "main": "setup.js",
5
5
  "files": [
package/setup.js CHANGED
@@ -664,7 +664,7 @@ function startAdapter(objects, states, callback) {
664
664
 
665
665
  function startCustomAdapter(adapterName, adapterInstance) {
666
666
  adapterInstance = adapterInstance || 0;
667
- const id = `${adapterName || pkg.name}.${adapterInstance}`;
667
+ const id = `${adapterName || pkg.name.split('.')[1]}.${adapterInstance}`;
668
668
  if (adaptersStarted[id]) {
669
669
  console.log(`Adapter ${id} already started ...`);
670
670
  return;
@@ -672,7 +672,7 @@ function startCustomAdapter(adapterName, adapterInstance) {
672
672
  adaptersStarted[id] = true;
673
673
  console.log(`startAdapter ${id} ...`);
674
674
  const _pkg = adapterName ? require(`${rootDir}tmp/node_modules/iobroker.${adapterName}/package.json`) : pkg;
675
- adapterName = adapterName || pkg.name;
675
+ adapterName = adapterName || pkg.name.split('.')[1];
676
676
  if (fs.existsSync(`${rootDir}tmp/node_modules/iobroker.${adapterName}/${_pkg.main || 'main.js'}`)) {
677
677
  try {
678
678
  if (debug) {
@@ -709,9 +709,11 @@ function startController(isStartAdapter, onObjectChange, onStateChange, callback
709
709
  onObjectChange = undefined;
710
710
  }
711
711
 
712
- if (pids[`${pkg.name}.0`]) {
712
+ if (pids.controller) {
713
713
  console.error('Controller is already started!');
714
714
  } else {
715
+ pids.controller = true;
716
+
715
717
  console.log('startController...');
716
718
  try {
717
719
  const config = require(`${rootDir}tmp/${appName}-data/${appName}.json`);
@@ -762,7 +764,7 @@ function startController(isStartAdapter, onObjectChange, onStateChange, callback
762
764
 
763
765
  // Just open in memory DB itself
764
766
  const statePath = require.resolve(`@iobroker/db-states-${config.states.type}`, {
765
- paths: [ `${rootDir}tmp/node_modules`, rootDir, `${rootDir}tmp/node_modules/${appName}.js-controller`]
767
+ paths: [`${rootDir}tmp/node_modules`, rootDir, `${rootDir}tmp/node_modules/${appName}.js-controller`],
766
768
  });
767
769
  console.log(`States Path: ${statePath}`);
768
770
  const States = require(statePath).Server;
@@ -815,34 +817,13 @@ function startController(isStartAdapter, onObjectChange, onStateChange, callback
815
817
  }
816
818
  }
817
819
 
818
- function stopAdapter(cb) {
819
- const id = `${pkg.name}.0`;
820
- if (!pids[id]) {
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
- }
820
+ async function stopAdapter(cb) {
821
+ await stopCustomAdapter();
822
+ cb && cb();
842
823
  }
843
824
 
844
825
  function stopCustomAdapter(adapterName, adapterInstance) {
845
- const id = `${adapterName}.${adapterInstance || 0}`;
826
+ const id = `${adapterName || pkg.name.split('.')[1]}.${adapterInstance || 0}`;
846
827
  if (!pids[id]) {
847
828
  console.error(`Adapter instance ${id} is not running!`);
848
829
  return Promise.resolve();
@@ -881,10 +862,11 @@ function _stopController() {
881
862
  }
882
863
 
883
864
  function stopController(cb) {
865
+ const id = `${pkg.name.split('.')[1]}.0`;
884
866
  let timeout;
885
867
  if (objects) {
886
- console.log(`Set system.adapter.${pkg.name}.0`);
887
- objects.setObject(`system.adapter.${pkg.name}.0`, {
868
+ console.log(`Set system.adapter.${id}`);
869
+ objects.setObject(`system.adapter.${id}`, {
888
870
  common: {
889
871
  enabled: false,
890
872
  },
@@ -903,6 +885,7 @@ function stopController(cb) {
903
885
  cb(true);
904
886
  cb = null;
905
887
  }
888
+ pids.controller = null;
906
889
  });
907
890
 
908
891
  timeout = setTimeout(() => {
@@ -915,7 +898,7 @@ function stopController(cb) {
915
898
  cb(false);
916
899
  cb = null;
917
900
  }
918
- pids[`${pkg.name}.0`] = null;
901
+ pids.controller = null;
919
902
  }, 5000);
920
903
  }
921
904