@iobroker/legacy-testing 1.0.12 → 2.0.0

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 CHANGED
@@ -1,75 +1,106 @@
1
1
  # legacy-tests
2
+
2
3
  Legacy test modules for ioBroker
3
4
 
4
- **This is a legacy repository. Please use the new test framework `@iobroker/testing` for new adapters**
5
+ **This is a legacy repository. Please use the new test framework `@iobroker/testing` for new adapters**
5
6
 
6
7
  ## How to replace existing tests
7
- 1. add to package.json=>devDependencies: `"@iobroker/legacy-testing": "^0.0.4"`
8
+
9
+ 1. add to package.json=>devDependencies: `"@iobroker/legacy-testing": "^2.0.0"`
8
10
  2. Remove from package.json=>devDependencies: `chai`
9
11
  3. Replace in `tests/testAdapter.js` the code `const setup = require('./lib/setup');` with `const setup = require('@iobroker/legacy-testing');`
10
12
  4. Replace whole file `tests/testPackageFiles.js` with `require('@iobroker/legacy-testing/tests/testPackageFiles');`
11
13
 
12
- ## Usage of the specific js-controller version
14
+ ## Usage of the specific js-controller version
15
+
13
16
  Set process.env.JS_CONTROLLER_VERSION to version e.g. `5.0.5-alpha.0-20230617-464b0fd6`
14
17
 
15
18
  ## Changelog
19
+
16
20
  <!-- ### **WORK IN PROGRESS** -->
21
+ ### 2.0.0 (2024-11-05)
22
+
23
+ - (bluefox) Function names for GUI tests were changed: startIoBrokerAdmin => startIoBrokerAdapters, stopIoBrokerAdmin => stopIoBrokerAdapters
24
+
25
+ ### 1.0.13 (2024-08-18)
26
+
27
+ - (bluefox) Improved the GUI tests
28
+
17
29
  ### 1.0.12 (2024-04-27)
18
- * (bluefox) Allowed setting license into common.licenseInformation.license
30
+
31
+ - (bluefox) Allowed setting license into `common.licenseInformation.license`
19
32
 
20
33
  ### 1.0.11 (2024-04-14)
21
- * (bluefox) Added support for the once mode
34
+
35
+ - (bluefox) Added support for the once mode
22
36
 
23
37
  ### 1.0.10 (2024-04-10)
24
- * (bluefox) Added support for vis-2 testing
38
+
39
+ - (bluefox) Added support for vis-2 testing
25
40
 
26
41
  ### 1.0.9 (2023-12-19)
27
- * (foxriver76) create folder on initialization
42
+
43
+ - (foxriver76) create folder on initialization
28
44
 
29
45
  ### 1.0.8 (2023-12-19)
30
- * (foxriver76) use hardcoded appName instead of inference with a heuristic approach
46
+
47
+ - (foxriver76) use hardcoded appName instead of inference with a heuristic approach
31
48
 
32
49
  ### 1.0.7 (2023-12-19)
33
- * (foxriver76) allow re-initialization after config change
50
+
51
+ - (foxriver76) allow re-initialization after config change
34
52
 
35
53
  ### 1.0.6 (2023-12-19)
36
- * (foxriver76) allow specifying the `rootDir`
54
+
55
+ - (foxriver76) allow specifying the `rootDir`
37
56
 
38
57
  ### 1.0.5 (2023-12-15)
39
- * (bluefox) Added support for vis-1 testing
58
+
59
+ - (bluefox) Added support for vis-1 testing
40
60
 
41
61
  ### 1.0.4 (2023-12-15)
42
- * (bluefox) Allowed GUI tests for tab_m.html too
62
+
63
+ - (bluefox) Allowed GUI tests for tab_m.html too
43
64
 
44
65
  ### 1.0.3 (2023-10-26)
45
- * (bluefox) Added helper files to test react admin GUI
66
+
67
+ - (bluefox) Added helper files to test react admin GUI
46
68
 
47
69
  ### 1.0.1 (2023-10-16)
48
- * (bluefox) Made `common.title` not required
70
+
71
+ - (bluefox) Made `common.title` not required
49
72
 
50
73
  ### 1.0.0 (2023-09-18)
51
- * (bluefox) Corrected error if systemConfig requested
74
+
75
+ - (bluefox) Corrected error if systemConfig requested
52
76
 
53
77
  ### 0.3.7 (2023-07-07)
54
- * (bluefox) Allowed using the specific version of js-controller
78
+
79
+ - (bluefox) Allowed using the specific version of js-controller
55
80
 
56
81
  ### 0.3.6 (2023-05-08)
57
- * (bluefox) Added possibility to install additional adapters at start
58
- * (bluefox) Added setOfflineState/getOfflineState
82
+
83
+ - (bluefox) Added possibility to install additional adapters at start
84
+ - (bluefox) Added setOfflineState/getOfflineState
59
85
 
60
86
  ### 0.1.1 (2022-12-22)
61
- * (bluefox) Extended testPackageFiles.js with checks
87
+
88
+ - (bluefox) Extended testPackageFiles.js with checks
62
89
 
63
90
  ### 0.1.0 (2022-12-22)
64
- * (bluefox) Corrected testPackageFiles.js
91
+
92
+ - (bluefox) Corrected testPackageFiles.js
65
93
 
66
94
  ### 0.0.4 (2022-11-21)
67
- * (bluefox) Added testPackageFiles.js
95
+
96
+ - (bluefox) Added testPackageFiles.js
68
97
 
69
98
  ### 0.0.3 (2022-11-21)
70
- * (bluefox) initial release
99
+
100
+ - (bluefox) initial release
71
101
 
72
102
  ## License
103
+
73
104
  MIT License
74
105
 
75
106
  Copyright (c) 2022-2024 bluefox <dogafox@gmail.com>
package/engineHelper.js CHANGED
@@ -1,34 +1,54 @@
1
1
  /**
2
2
  * This file starts and stops the admin adapter including js-controller
3
3
  */
4
- const fs = require('fs');
5
- const setup = require('./setup');
4
+ const { existsSync, readdirSync, statSync, rmdirSync, unlinkSync } = require('node:fs');
5
+ const {
6
+ setOfflineState,
7
+ setupController,
8
+ setObject,
9
+ getAdapterConfig,
10
+ setAdapterConfig,
11
+ startController,
12
+ startCustomAdapter,
13
+ stopCustomAdapter,
14
+ stopController,
15
+ } = require('./setup');
6
16
 
7
17
  let rootDir = `${__dirname}/../../../`;
8
18
  let objects = null;
9
- let states = null;
19
+ let states = null;
10
20
  let onStateChanged = null;
11
21
 
12
22
  function deleteFoldersRecursive(path) {
13
23
  if (path.endsWith('/')) {
14
24
  path = path.substring(0, path.length - 1);
15
25
  }
16
- if (fs.existsSync(path)) {
17
- const files = fs.readdirSync(path);
26
+ if (existsSync(path)) {
27
+ const files = readdirSync(path);
18
28
  for (const file of files) {
19
29
  const curPath = `${path}/${file}`;
20
- const stat = fs.statSync(curPath);
30
+ const stat = statSync(curPath);
21
31
  if (stat.isDirectory()) {
22
32
  deleteFoldersRecursive(curPath);
23
- fs.rmdirSync(curPath);
33
+ rmdirSync(curPath);
24
34
  } else {
25
- fs.unlinkSync(curPath);
35
+ unlinkSync(curPath);
26
36
  }
27
37
  }
28
38
  }
29
39
  }
30
40
 
31
- function startIoBrokerAdmin(options) {
41
+ let startedAdapters = ['admin'];
42
+
43
+ /**
44
+ * Start ioBroker controller and provided adapters. If no adapters are provided, only the admin will be started.
45
+ *
46
+ * @param options.rootDir {string} The root directory of the project
47
+ * @param options.adapters {string[]} The adapters to start. Default is ['admin']
48
+ *
49
+ * @return {Promise<unknown>}
50
+ */
51
+ function startIoBrokerAdapters(options) {
32
52
  options = options || {};
33
53
  if (options.rootDir) {
34
54
  rootDir = options.rootDir;
@@ -38,70 +58,84 @@ function startIoBrokerAdmin(options) {
38
58
  // delete the old project
39
59
  deleteFoldersRecursive(`${rootDir}tmp/screenshots`);
40
60
 
41
- await setup.setOfflineState(`system.adapter.admin.0.alive`, { val: false });
61
+ const adapters = options.adapters || startedAdapters;
62
+ startedAdapters = adapters;
63
+ for (let a = 0; a < adapters.length; a++) {
64
+ await setOfflineState(`system.adapter.${adapters[a]}.0.alive`, { val: false });
65
+ }
42
66
 
43
- setup.setupController(['admin'], async systemConfig => {
67
+ setupController(adapters, async systemConfig => {
44
68
  // disable statistics and set license accepted
45
69
  systemConfig.common.licenseConfirmed = true;
46
70
  systemConfig.common.diag = 'none';
47
- await setup.setObject('system.config', systemConfig);
71
+ await setObject('system.config', systemConfig);
48
72
 
49
- // start admin
50
- const adminConfig = await setup.getAdapterConfig(0, 'admin');
51
- if (adminConfig && adminConfig.common) {
52
- adminConfig.common.enabled = true;
53
- await setup.setAdapterConfig(adminConfig.common, adminConfig.native, 0, 'admin');
73
+ // start adapters
74
+ for (let a = 0; a < adapters.length; a++) {
75
+ const adapter = adapters[a];
76
+ const adapterConfig = await getAdapterConfig(0, adapter);
77
+ if (adapterConfig?.common) {
78
+ adapterConfig.common.enabled = true;
79
+ await setAdapterConfig(adapterConfig.common, adapterConfig.native, 0, adapter);
80
+ }
54
81
  }
55
82
 
56
- setup.startController(
83
+ startController(
57
84
  false, // do not start widgets
58
85
  (/* id, obj */) => {},
59
86
  (id, state) => onStateChanged && onStateChanged(id, state),
60
87
  async (_objects, _states) => {
61
88
  objects = _objects;
62
89
  states = _states;
63
- setup.startCustomAdapter('admin', 0);
64
- await checkIsWelcomeStartedAsync('admin', states);
90
+ for (let a = 0; a < adapters.length; a++) {
91
+ startCustomAdapter(adapters[a], 0);
92
+ await checkIsAdapterStartedAsync(adapters[a], states);
93
+ }
65
94
  resolve({ objects, states });
66
- });
95
+ },
96
+ );
67
97
  });
68
98
  });
69
99
  }
70
100
 
71
- async function stopIoBrokerAdmin() {
72
- await setup.stopCustomAdapter('admin', 0);
101
+ async function stopIoBrokerAdapters() {
102
+ for (let a = 0; a < startedAdapters.length; a++) {
103
+ await stopCustomAdapter(startedAdapters[a], 0);
104
+ }
73
105
 
74
106
  await new Promise(resolve =>
75
- setup.stopController(normalTerminated => {
107
+ stopController(normalTerminated => {
76
108
  console.log(`Adapter normal terminated: ${normalTerminated}`);
77
109
  resolve();
78
- }));
110
+ }),
111
+ );
79
112
  }
80
113
 
81
- function checkIsWelcomeStarted(adapterName, states, cb, counter) {
114
+ function checkIsAdapterStarted(adapterName, states, cb, counter) {
82
115
  counter = counter === undefined ? 20 : counter;
83
116
  if (counter === 0) {
84
117
  return cb && cb(`Cannot check value Of State system.adapter.${adapterName}.0.alive`);
85
118
  }
86
119
 
87
120
  states.getState(`system.adapter.${adapterName}.0.alive`, (err, state) => {
88
- console.log(`[${counter}]Check if ${adapterName} is started "system.adapter.${adapterName}.0.alive" = ${JSON.stringify(state)}`);
121
+ console.log(
122
+ `[${counter}]Check if ${adapterName} is started "system.adapter.${adapterName}.0.alive" = ${JSON.stringify(state)}`,
123
+ );
89
124
  err && console.error(err);
90
125
  if (state && state.val) {
91
126
  cb && cb();
92
127
  } else {
93
- setTimeout(() =>
94
- checkIsWelcomeStarted(adapterName, states, cb, counter - 1), 500);
128
+ setTimeout(() => checkIsAdapterStarted(adapterName, states, cb, counter - 1), 500);
95
129
  }
96
130
  });
97
131
  }
98
132
 
99
- function checkIsWelcomeStartedAsync(adapterName, states, counter) {
100
- return new Promise(resolve => checkIsWelcomeStarted(adapterName, states, resolve, counter));
133
+ function checkIsAdapterStartedAsync(adapterName, states, counter) {
134
+ return new Promise(resolve => checkIsAdapterStarted(adapterName, states, resolve, counter));
101
135
  }
102
136
 
103
137
  module.exports = {
104
- startIoBrokerAdmin,
105
- stopIoBrokerAdmin,
106
- setOnStateChanged: cb => onStateChanged = cb
107
- };
138
+ startIoBrokerAdapters,
139
+ stopIoBrokerAdapters,
140
+ setOnStateChanged: cb => (onStateChanged = cb),
141
+ };
package/guiHelper.js CHANGED
@@ -1,39 +1,40 @@
1
1
  /* This file helps to start and stop the browser and make screenshots of desired adapter
2
- * Do not forget to include into package.json:
2
+ * Do not forget to include in package.json:
3
3
  * "devDependencies": {
4
4
  * "puppeteer": "^21.4.1",
5
5
  * "colorette": "^1.2.1"
6
6
  * }
7
- **/
7
+ **/
8
8
  const puppeteer = require('puppeteer');
9
9
  const { blue, cyan, red, yellow } = require('colorette');
10
- const fs = require('fs');
10
+ const { existsSync, mkdirSync } = require('node:fs');
11
11
 
12
12
  let gBrowser;
13
13
  let gPage;
14
14
 
15
15
  /* This function starts the browser and opens the desired adapter
16
- * @param {string} adapterName - could be just an adapter name or adapter name with path, like 'device-manager/tab_m.html'
17
- * @param {string} rootDir
18
- * @param {boolean} headless
16
+ * @param {string} adapterName - could be just an adapter name or adapter name with path, like 'device-manager/tab_m.html'
17
+ * @param {string} rootDir
18
+ * @param {boolean} headless
19
+ * @param {pathUrl} string
19
20
  */
20
- async function startBrowser(adapterName, rootDir, headless) {
21
+ async function startBrowser(adapterName, rootDir, headless, pathUrl) {
21
22
  if (!rootDir.endsWith('/')) {
22
23
  rootDir += '/';
23
24
  }
24
25
 
25
26
  const browser = await puppeteer.launch({
26
27
  headless: headless === undefined ? false : headless,
27
- args: ['--no-sandbox', '--disable-setuid-sandbox']
28
+ args: ['--no-sandbox', '--disable-setuid-sandbox'],
28
29
  });
29
30
  const pages = await browser.pages();
30
31
  const timeout = 5000;
31
32
  pages[0].setDefaultTimeout(timeout);
32
33
 
33
- await pages[0].setViewport( {
34
+ await pages[0].setViewport({
34
35
  width: 1920,
35
36
  height: 1080,
36
- deviceScaleFactor: 1
37
+ deviceScaleFactor: 1,
37
38
  });
38
39
 
39
40
  gBrowser = browser;
@@ -47,7 +48,7 @@ async function startBrowser(adapterName, rootDir, headless) {
47
48
  LOG: text => text,
48
49
  ERR: red,
49
50
  WAR: yellow,
50
- INF: cyan
51
+ INF: cyan,
51
52
  };
52
53
 
53
54
  const color = colors[type] || blue;
@@ -55,10 +56,17 @@ async function startBrowser(adapterName, rootDir, headless) {
55
56
  })
56
57
  .on('pageerror', ({ message }) => console.log(red(`[BROWSER] ${message}`)));
57
58
 
58
- await gPage.goto(`http://127.0.0.1:8081/adapter/${adapterName.includes('/') ? (!adapterName.includes('?') ? `${adapterName}?` : adapterName) : `${adapterName}/index_m.html?`}&newReact=true&0&react=dark`, { waitUntil: 'domcontentloaded' });
59
+ pathUrl =
60
+ pathUrl ||
61
+ `/adapter/${adapterName.includes('/') ? (!adapterName.includes('?') ? `${adapterName}?` : adapterName) : `${adapterName}/index_m.html?`}&newReact=true&0&react=dark`;
62
+ if (!pathUrl.startsWith('/')) {
63
+ pathUrl = `/${pathUrl}`;
64
+ }
65
+
66
+ await gPage.goto(`http://127.0.0.1:8081${pathUrl}`, { waitUntil: 'domcontentloaded' });
59
67
 
60
68
  // Create directory
61
- !fs.existsSync(`${rootDir}tmp/screenshots`) && fs.mkdirSync(`${rootDir}tmp/screenshots`);
69
+ !existsSync(`${rootDir}tmp/screenshots`) && mkdirSync(`${rootDir}tmp/screenshots`);
62
70
  await gPage.screenshot({ path: `${rootDir}tmp/screenshots/00_starting.png` });
63
71
 
64
72
  return { browser, page: pages[0] };
@@ -80,5 +88,5 @@ async function screenshot(rootDir, page, fileName) {
80
88
  module.exports = {
81
89
  startBrowser,
82
90
  stopBrowser,
83
- screenshot
91
+ screenshot,
84
92
  };
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.12",
2
+ "version": "2.0.0",
3
3
  "name": "@iobroker/legacy-testing",
4
4
  "main": "setup.js",
5
5
  "files": [
@@ -26,12 +26,13 @@
26
26
  "email": "dogafox@gmail.com"
27
27
  },
28
28
  "dependencies": {
29
- "mocha": "^10.4.0",
30
- "chai": "^4.4.1"
29
+ "mocha": "^10.8.2",
30
+ "chai": "^4.5.0"
31
31
  },
32
32
  "devDependencies": {
33
- "@alcalzone/release-script": "^3.7.0",
34
- "@alcalzone/release-script-plugin-license": "^3.7.0"
33
+ "@alcalzone/release-script": "^3.8.0",
34
+ "@alcalzone/release-script-plugin-license": "^3.7.0",
35
+ "@iobroker/eslint-config": "^0.1.6"
35
36
  },
36
37
  "scripts": {
37
38
  "release": "release-script",
package/setup.js CHANGED
@@ -3,18 +3,19 @@
3
3
  /* jslint node: true */
4
4
 
5
5
  // check if tmp directory exists
6
- const fs = require('fs');
7
- const path = require('path');
8
- const cp = require('child_process');
9
- let rootDir = path.normalize(`${__dirname}/../../../`);
6
+ const { lstatSync, existsSync, mkdirSync, readFileSync, writeFileSync, readdirSync, unlinkSync } = require('node:fs');
7
+ const { normalize, join, basename } = require('node:path');
8
+ const { execSync, fork, exec } = require('node:child_process');
9
+
10
+ let rootDir = normalize(`${__dirname}/../../../`);
10
11
  const debug = typeof v8debug === 'object';
11
12
 
12
13
  let JSONLDB;
13
14
 
14
- let adapterName = path.normalize(rootDir).replace(/\\/g, '/').split('/');
15
+ let adapterName = normalize(rootDir).replace(/\\/g, '/').split('/');
15
16
  if (adapterName[adapterName.length - 2] === 'vis-2-widgets-testing') {
16
- rootDir = path.normalize(`${__dirname}/../../../../../../`);
17
- adapterName = path.normalize(rootDir).replace(/\\/g, '/').split('/');
17
+ rootDir = normalize(`${__dirname}/../../../../../../`);
18
+ adapterName = normalize(rootDir).replace(/\\/g, '/').split('/');
18
19
  }
19
20
  adapterName = adapterName[adapterName.length - 2];
20
21
 
@@ -36,7 +37,7 @@ function initialize() {
36
37
  pkg = require(`${rootDir}package.json`);
37
38
  pkg.main = pkg.main || 'main.js';
38
39
 
39
- !fs.existsSync(`${rootDir}tmp`) && fs.mkdirSync(`${rootDir}tmp`);
40
+ !existsSync(`${rootDir}tmp`) && mkdirSync(`${rootDir}tmp`);
40
41
  }
41
42
 
42
43
  /** Lowercase application name */
@@ -45,7 +46,7 @@ const appName = 'iobroker';
45
46
  function loadJSONLDB() {
46
47
  if (!JSONLDB) {
47
48
  const dbPath = require.resolve('@alcalzone/jsonl-db', {
48
- paths: [`${rootDir}tmp/node_modules`, rootDir, `${rootDir}tmp/node_modules/${appName}.js-controller`]
49
+ paths: [`${rootDir}tmp/node_modules`, rootDir, `${rootDir}tmp/node_modules/${appName}.js-controller`],
49
50
  });
50
51
  console.log(`JSONLDB path: ${dbPath}`);
51
52
  try {
@@ -61,12 +62,12 @@ function copyFileSync(source, target) {
61
62
  let targetFile = target;
62
63
 
63
64
  //if target is a directory a new file with the same name will be created
64
- if (fs.existsSync(target) && fs.lstatSync(target).isDirectory() ) {
65
- targetFile = path.join(target, path.basename(source));
65
+ if (existsSync(target) && lstatSync(target).isDirectory()) {
66
+ targetFile = join(target, basename(source));
66
67
  }
67
68
 
68
69
  try {
69
- fs.writeFileSync(targetFile, fs.readFileSync(source));
70
+ writeFileSync(targetFile, readFileSync(source));
70
71
  } catch (err) {
71
72
  console.log(`file copy error: ${source} -> ${targetFile} (error ignored)`);
72
73
  }
@@ -75,27 +76,27 @@ function copyFileSync(source, target) {
75
76
  function copyFolderRecursiveSync(source, target, ignore) {
76
77
  let files = [];
77
78
 
78
- let base = path.basename(source);
79
+ let base = basename(source);
79
80
  if (base === adapterName) {
80
81
  base = pkg.name;
81
82
  }
82
83
  //check if folder needs to be created or integrated
83
- const targetFolder = path.join(target, base);
84
- if (!fs.existsSync(targetFolder)) {
85
- fs.mkdirSync(targetFolder);
84
+ const targetFolder = join(target, base);
85
+ if (!existsSync(targetFolder)) {
86
+ mkdirSync(targetFolder);
86
87
  }
87
88
 
88
89
  //copy
89
- if (fs.lstatSync(source).isDirectory()) {
90
- files = fs.readdirSync(source);
90
+ if (lstatSync(source).isDirectory()) {
91
+ files = readdirSync(source);
91
92
  files.forEach(file => {
92
- if (ignore && ignore.includes(file)) {
93
+ if (ignore?.includes(file)) {
93
94
  return;
94
95
  }
95
96
 
96
- const curSource = path.join(source, file);
97
- const curTarget = path.join(targetFolder, file);
98
- if (fs.lstatSync(curSource).isDirectory()) {
97
+ const curSource = join(source, file);
98
+ const curTarget = join(targetFolder, file);
99
+ if (lstatSync(curSource).isDirectory()) {
99
100
  // ignore grunt files
100
101
  if (file.includes('grunt') || file === 'chai' || file === 'mocha') {
101
102
  return;
@@ -112,8 +113,8 @@ async function storeOriginalFiles() {
112
113
  console.log('Store original files...');
113
114
  const dataDir = `${rootDir}tmp/${appName}-data/`;
114
115
 
115
- if (fs.existsSync(`${dataDir}objects.json`)) {
116
- const f = fs.readFileSync(`${dataDir}objects.json`);
116
+ if (existsSync(`${dataDir}objects.json`)) {
117
+ const f = readFileSync(`${dataDir}objects.json`);
117
118
  const objects = JSON.parse(f.toString());
118
119
  if (objects['system.adapter.admin.0'] && objects['system.adapter.admin.0'].common) {
119
120
  objects['system.adapter.admin.0'].common.enabled = false;
@@ -122,21 +123,21 @@ async function storeOriginalFiles() {
122
123
  objects['system.adapter.admin.1'].common.enabled = false;
123
124
  }
124
125
 
125
- fs.writeFileSync(`${dataDir}objects.json.original`, JSON.stringify(objects));
126
+ writeFileSync(`${dataDir}objects.json.original`, JSON.stringify(objects));
126
127
  console.log('Store original objects.json');
127
128
  }
128
129
 
129
- if (fs.existsSync(`${dataDir}states.json`)) {
130
+ if (existsSync(`${dataDir}states.json`)) {
130
131
  try {
131
- const f = fs.readFileSync(`${dataDir}states.json`);
132
- fs.writeFileSync(`${dataDir}states.json.original`, f);
132
+ const f = readFileSync(`${dataDir}states.json`);
133
+ writeFileSync(`${dataDir}states.json.original`, f);
133
134
  console.log('Store original states.json');
134
135
  } catch (err) {
135
136
  console.log('no states.json found - ignore');
136
137
  }
137
138
  }
138
139
 
139
- if (fs.existsSync(`${dataDir}objects.jsonl`)) {
140
+ if (existsSync(`${dataDir}objects.jsonl`)) {
140
141
  loadJSONLDB();
141
142
  const db = new JSONLDB(`${dataDir}objects.jsonl`);
142
143
  await db.open();
@@ -158,14 +159,14 @@ async function storeOriginalFiles() {
158
159
  }
159
160
  await db.close();
160
161
 
161
- const f = fs.readFileSync(`${dataDir}objects.jsonl`);
162
- fs.writeFileSync(`${dataDir}objects.jsonl.original`, f);
162
+ const f = readFileSync(`${dataDir}objects.jsonl`);
163
+ writeFileSync(`${dataDir}objects.jsonl.original`, f);
163
164
  console.log('Store original objects.jsonl');
164
165
  }
165
166
 
166
- if (fs.existsSync(`${dataDir}states.jsonl`)) {
167
- const f = fs.readFileSync(`${dataDir}states.jsonl`);
168
- fs.writeFileSync(`${dataDir}states.jsonl.original`, f);
167
+ if (existsSync(`${dataDir}states.jsonl`)) {
168
+ const f = readFileSync(`${dataDir}states.jsonl`);
169
+ writeFileSync(`${dataDir}states.jsonl.original`, f);
169
170
  console.log('Store original states.jsonl');
170
171
  }
171
172
  }
@@ -174,22 +175,22 @@ function restoreOriginalFiles() {
174
175
  console.log('restoreOriginalFiles...');
175
176
  const dataDir = `${rootDir}tmp/${appName}-data/`;
176
177
 
177
- if (fs.existsSync(`${dataDir}objects.json.original`)) {
178
- const f = fs.readFileSync(`${dataDir}objects.json.original`);
179
- fs.writeFileSync(`${dataDir}objects.json`, f);
178
+ if (existsSync(`${dataDir}objects.json.original`)) {
179
+ const f = readFileSync(`${dataDir}objects.json.original`);
180
+ writeFileSync(`${dataDir}objects.json`, f);
180
181
  }
181
- if (fs.existsSync(`${dataDir}objects.json.original`)) {
182
- const f = fs.readFileSync(`${dataDir}states.json.original`);
183
- fs.writeFileSync(`${dataDir}states.json`, f);
182
+ if (existsSync(`${dataDir}objects.json.original`)) {
183
+ const f = readFileSync(`${dataDir}states.json.original`);
184
+ writeFileSync(`${dataDir}states.json`, f);
184
185
  }
185
186
 
186
- if (fs.existsSync(`${dataDir}objects.jsonl.original`)) {
187
- const f = fs.readFileSync(`${dataDir}objects.jsonl.original`);
188
- fs.writeFileSync(`${dataDir}objects.jsonl`, f);
187
+ if (existsSync(`${dataDir}objects.jsonl.original`)) {
188
+ const f = readFileSync(`${dataDir}objects.jsonl.original`);
189
+ writeFileSync(`${dataDir}objects.jsonl`, f);
189
190
  }
190
- if (fs.existsSync(`${dataDir}objects.jsonl.original`)) {
191
- const f = fs.readFileSync(`${dataDir}states.jsonl.original`);
192
- fs.writeFileSync(`${dataDir}states.jsonl`, f);
191
+ if (existsSync(`${dataDir}objects.jsonl.original`)) {
192
+ const f = readFileSync(`${dataDir}states.jsonl.original`);
193
+ writeFileSync(`${dataDir}states.jsonl`, f);
193
194
  }
194
195
  }
195
196
 
@@ -221,13 +222,18 @@ async function checkIsAdapterInstalled(cb, counter, customAdapterName, customIns
221
222
 
222
223
  function checkIsAdapterInstalledAsync(counter, customAdapterName, customInstance) {
223
224
  return new Promise((resolve, reject) => {
224
- checkIsAdapterInstalled(err => {
225
- if (err) {
226
- reject(err);
227
- } else {
228
- resolve();
229
- }
230
- }, counter, customAdapterName, customInstance);
225
+ checkIsAdapterInstalled(
226
+ err => {
227
+ if (err) {
228
+ reject(err);
229
+ } else {
230
+ resolve();
231
+ }
232
+ },
233
+ counter,
234
+ customAdapterName,
235
+ customInstance,
236
+ );
231
237
  });
232
238
  }
233
239
 
@@ -283,21 +289,21 @@ async function installAdapter(customAdapterName, cb) {
283
289
  const startFile = `node_modules/${appName}.js-controller/${appName}.js`;
284
290
  // make first install
285
291
  if (debug) {
286
- cp.execSync(`node ${startFile} add ${customAdapterName} --enabled false`, {
287
- cwd: `${rootDir}tmp`,
292
+ execSync(`node ${startFile} add ${customAdapterName} --enabled false`, {
293
+ cwd: `${rootDir}tmp`,
288
294
  stdio: [0, 1, 2],
289
295
  });
290
296
  } else {
291
297
  // add controller
292
- const _pid = cp.fork(startFile, ['add', customAdapterName, '--enabled', 'false'], {
293
- cwd: `${rootDir}tmp`,
298
+ const _pid = fork(startFile, ['add', customAdapterName, '--enabled', 'false'], {
299
+ cwd: `${rootDir}tmp`,
294
300
  stdio: [0, 1, 2, 'ipc'],
295
301
  });
296
302
 
297
303
  await waitForEndAsync(_pid);
298
304
  }
299
305
 
300
- const name = (customAdapterName.split('@')[0]).split('.').pop(); // extract from iobroker.adaptername@version => adaptername
306
+ const name = customAdapterName.split('@')[0].split('.').pop(); // extract from iobroker.adaptername@version => adaptername
301
307
 
302
308
  await checkIsAdapterInstalledAsync(null, name);
303
309
  console.log(`[${customAdapterName}] Adapter installed.`);
@@ -305,25 +311,24 @@ async function installAdapter(customAdapterName, cb) {
305
311
  }
306
312
 
307
313
  function installAdapterAsync(customAdapterName) {
308
- return new Promise(resolve =>
309
- installAdapter(customAdapterName, () => resolve()));
314
+ return new Promise(resolve => installAdapter(customAdapterName, () => resolve()));
310
315
  }
311
316
 
312
317
  function waitForEndAsync(_pid) {
313
318
  if (!_pid) {
314
- return {code: -1, signal: -1};
319
+ return { code: -1, signal: -1 };
315
320
  } else {
316
321
  return new Promise(resolve => {
317
322
  _pid.on('exit', (code, signal) => {
318
323
  if (_pid) {
319
324
  _pid = null;
320
- resolve({code, signal});
325
+ resolve({ code, signal });
321
326
  }
322
327
  });
323
328
  _pid.on('close', (code, signal) => {
324
329
  if (_pid) {
325
330
  _pid = null;
326
- resolve({code, signal});
331
+ resolve({ code, signal });
327
332
  }
328
333
  });
329
334
  });
@@ -337,88 +342,100 @@ async function installJsController(preInstalledAdapters, cb) {
337
342
  }
338
343
 
339
344
  console.log('installJsController...');
340
- if (!fs.existsSync(`${rootDir}tmp/node_modules/${appName}.js-controller`) ||
341
- !fs.existsSync(`${rootDir}tmp/${appName}-data`)) {
345
+ if (
346
+ !existsSync(`${rootDir}tmp/node_modules/${appName}.js-controller`) ||
347
+ !existsSync(`${rootDir}tmp/${appName}-data`)
348
+ ) {
342
349
  // try to detect appName.js-controller in node_modules/appName.js-controller
343
350
  // travis CI installs js-controller into node_modules
344
- if (fs.existsSync(`${rootDir}node_modules/${appName}.js-controller`)) {
345
- console.log(`installJsController: no js-controller => copy it from "${rootDir}node_modules/${appName}.js-controller"`);
351
+ if (existsSync(`${rootDir}node_modules/${appName}.js-controller`)) {
352
+ console.log(
353
+ `installJsController: no js-controller => copy it from "${rootDir}node_modules/${appName}.js-controller"`,
354
+ );
346
355
  // copy all
347
356
  // stop the controller
348
357
  console.log('Stop controller if running...');
349
358
  let _pid;
350
359
  if (debug) {
351
360
  // start controller
352
- _pid = cp.exec(`node ${appName}.js stop`, {
361
+ _pid = exec(`node ${appName}.js stop`, {
353
362
  cwd: `${rootDir}node_modules/${appName}.js-controller`,
354
363
  stdio: [0, 1, 2],
355
364
  });
356
365
  } else {
357
- _pid = cp.fork(`${appName}.js`, ['stop'], {
358
- cwd: `${rootDir}node_modules/${appName}.js-controller`,
366
+ _pid = fork(`${appName}.js`, ['stop'], {
367
+ cwd: `${rootDir}node_modules/${appName}.js-controller`,
359
368
  stdio: [0, 1, 2, 'ipc'],
360
369
  });
361
370
  }
362
371
 
363
372
  await waitForEndAsync(_pid);
364
373
  // copy all files into
365
- !fs.existsSync(`${rootDir}tmp`) && fs.mkdirSync(`${rootDir}tmp`);
366
- !fs.existsSync(`${rootDir}tmp/node_modules`) && fs.mkdirSync(`${rootDir}tmp/node_modules`);
374
+ !existsSync(`${rootDir}tmp`) && mkdirSync(`${rootDir}tmp`);
375
+ !existsSync(`${rootDir}tmp/node_modules`) && mkdirSync(`${rootDir}tmp/node_modules`);
367
376
 
368
- if (!fs.existsSync(`${rootDir}tmp/node_modules/${appName}.js-controller`)){
377
+ if (!existsSync(`${rootDir}tmp/node_modules/${appName}.js-controller`)) {
369
378
  console.log('Copy js-controller...');
370
- copyFolderRecursiveSync(`${rootDir}node_modules/${appName}.js-controller`, `${rootDir}tmp/node_modules/`);
379
+ copyFolderRecursiveSync(
380
+ `${rootDir}node_modules/${appName}.js-controller`,
381
+ `${rootDir}tmp/node_modules/`,
382
+ );
371
383
  }
372
384
 
373
385
  console.log('Setup js-controller...');
374
386
  let __pid;
375
387
  if (debug) {
376
388
  // start controller
377
- __pid = cp.exec(`node ${appName}.js setup first --console`, {
389
+ __pid = exec(`node ${appName}.js setup first --console`, {
378
390
  cwd: `${rootDir}tmp/node_modules/${appName}.js-controller`,
379
- stdio: [0, 1, 2]
391
+ stdio: [0, 1, 2],
380
392
  });
381
393
  } else {
382
- __pid = cp.fork(`${appName}.js`, ['setup', 'first', '--console'], {
383
- cwd: `${rootDir}tmp/node_modules/${appName}.js-controller`,
384
- stdio: [0, 1, 2, 'ipc']
394
+ __pid = fork(`${appName}.js`, ['setup', 'first', '--console'], {
395
+ cwd: `${rootDir}tmp/node_modules/${appName}.js-controller`,
396
+ stdio: [0, 1, 2, 'ipc'],
385
397
  });
386
398
  }
387
399
  await waitForEndAsync(__pid);
388
400
  await checkIsControllerInstalledAsync();
389
401
  } else {
390
402
  // check if port 9000 is free, else admin adapter will be added to running instance
391
- const {Socket} = require('net')
403
+ const { Socket } = require('node:net');
392
404
  const client = new Socket();
393
405
  client.on('error', () => {
394
406
  // ignore
395
407
  });
396
408
  client.connect(9000, '127.0.0.1', () => {
397
- console.error('Cannot initiate the first run of test, because one instance of application is running on this PC. Stop it and repeat.');
409
+ console.error(
410
+ 'Cannot initiate the first run of test, because one instance of application is running on this PC. Stop it and repeat.',
411
+ );
398
412
  process.exit(0);
399
413
  });
400
414
 
401
415
  await new Promise(resolve => setTimeout(resolve, 1000));
402
416
  client.destroy();
403
417
 
404
- if (!fs.existsSync(`${rootDir}tmp/node_modules/${appName}.js-controller`)) {
418
+ if (!existsSync(`${rootDir}tmp/node_modules/${appName}.js-controller`)) {
405
419
  console.log('installJsController: no js-controller => install dev build from npm');
406
420
 
407
- cp.execSync(`npm install ${appName}.js-controller@${process.env.JS_CONTROLLER_VERSION || 'dev'} --prefix ./ --omit=dev`, {
408
- cwd: `${rootDir}tmp/`,
409
- stdio: [0, 1, 2],
410
- });
421
+ execSync(
422
+ `npm install ${appName}.js-controller@${process.env.JS_CONTROLLER_VERSION || 'dev'} --prefix ./ --omit=dev`,
423
+ {
424
+ cwd: `${rootDir}tmp/`,
425
+ stdio: [0, 1, 2],
426
+ },
427
+ );
411
428
  } else {
412
429
  console.log('Setup js-controller...');
413
430
  let __pid;
414
431
  if (debug) {
415
432
  // start controller
416
- __pid = cp.exec(`node ${appName}.js setup first`, {
433
+ __pid = exec(`node ${appName}.js setup first`, {
417
434
  cwd: `${rootDir}tmp/node_modules/${appName}.js-controller`,
418
435
  stdio: [0, 1, 2],
419
436
  });
420
437
  } else {
421
- __pid = cp.fork(`${appName}.js`, ['setup', 'first'], {
438
+ __pid = fork(`${appName}.js`, ['setup', 'first'], {
422
439
  cwd: `${rootDir}tmp/node_modules/${appName}.js-controller`,
423
440
  stdio: [0, 1, 2, 'ipc'],
424
441
  });
@@ -430,8 +447,8 @@ async function installJsController(preInstalledAdapters, cb) {
430
447
  await checkIsControllerInstalledAsync();
431
448
  let _pid;
432
449
 
433
- if (fs.existsSync(`${rootDir}node_modules/${appName}.js-controller/${appName}.js`)) {
434
- _pid = cp.fork(`${appName}.js`, ['stop'], {
450
+ if (existsSync(`${rootDir}node_modules/${appName}.js-controller/${appName}.js`)) {
451
+ _pid = fork(`${appName}.js`, ['stop'], {
435
452
  cwd: `${rootDir}node_modules/${appName}.js-controller`,
436
453
  stdio: [0, 1, 2, 'ipc'],
437
454
  });
@@ -443,9 +460,9 @@ async function installJsController(preInstalledAdapters, cb) {
443
460
  // change ports for the object and state DBs
444
461
  const config = require(`${rootDir}tmp/${appName}-data/${appName}.json`);
445
462
  config.objects.port = 19001;
446
- config.states.port = 19000;
463
+ config.states.port = 19000;
447
464
 
448
- fs.writeFileSync(`${rootDir}tmp/${appName}-data/${appName}.json`, JSON.stringify(config, null, 2));
465
+ writeFileSync(`${rootDir}tmp/${appName}-data/${appName}.json`, JSON.stringify(config, null, 2));
449
466
  console.log('Setup finished.');
450
467
 
451
468
  copyAdapterToController();
@@ -465,7 +482,7 @@ async function installJsController(preInstalledAdapters, cb) {
465
482
  const parts = preInstalledAdapters[p].split('@');
466
483
  const name = parts[0];
467
484
  const version = parts[1];
468
- if (!fs.existsSync(`${rootDir}tmp/node_modules/${name}`)) {
485
+ if (!existsSync(`${rootDir}tmp/node_modules/${name}`)) {
469
486
  await installAdapterAsync(preInstalledAdapters[p]);
470
487
  } else {
471
488
  const pack = require(`${rootDir}tmp/node_modules/${name}/package.json`);
@@ -485,26 +502,27 @@ async function installJsController(preInstalledAdapters, cb) {
485
502
  function copyAdapterToController() {
486
503
  console.log('Pack adapter...');
487
504
 
488
- fs.existsSync(`${rootDir}${pkg.name}-${pkg.version}.tgz`) && fs.unlinkSync(`${rootDir}${pkg.name}-${pkg.version}.tgz`);
489
- fs.existsSync(`${rootDir}tmp/${pkg.name}-${pkg.version}.tgz`) && fs.unlinkSync(`${rootDir}tmp/${pkg.name}-${pkg.version}.tgz`);
505
+ existsSync(`${rootDir}${pkg.name}-${pkg.version}.tgz`) && unlinkSync(`${rootDir}${pkg.name}-${pkg.version}.tgz`);
506
+ existsSync(`${rootDir}tmp/${pkg.name}-${pkg.version}.tgz`) &&
507
+ unlinkSync(`${rootDir}tmp/${pkg.name}-${pkg.version}.tgz`);
490
508
 
491
- cp.execSync(`npm pack`, {
492
- cwd: rootDir,
509
+ execSync(`npm pack`, {
510
+ cwd: rootDir,
493
511
  stdio: [0, 1, 2],
494
512
  });
495
513
  copyFileSync(`${rootDir}${pkg.name}-${pkg.version}.tgz`, `${rootDir}tmp/${pkg.name}-${pkg.version}.tgz`);
496
- cp.execSync(`npm install ${pkg.name}-${pkg.version}.tgz --prefix ./ --omit=dev`, {
497
- cwd: `${rootDir}tmp`,
514
+ execSync(`npm install ${pkg.name}-${pkg.version}.tgz --prefix ./ --omit=dev`, {
515
+ cwd: `${rootDir}tmp`,
498
516
  stdio: [0, 1, 2],
499
517
  });
500
518
  console.log('Adapter copied.');
501
519
  }
502
520
 
503
521
  function installCustomAdapter(adapterName) {
504
- if (!fs.existsSync(`${rootDir}tmp/node_modules/${adapterName}`)) {
522
+ if (!existsSync(`${rootDir}tmp/node_modules/${adapterName}`)) {
505
523
  console.log(`Install ${adapterName}`);
506
- cp.execSync(`npm install ${adapterName} --prefix ./ --omit=dev`, {
507
- cwd: `${rootDir}tmp/`,
524
+ execSync(`npm install ${adapterName} --prefix ./ --omit=dev`, {
525
+ cwd: `${rootDir}tmp/`,
508
526
  stdio: [0, 1, 2],
509
527
  });
510
528
  }
@@ -514,15 +532,15 @@ function clearControllerLog() {
514
532
  const dirPath = `${rootDir}tmp/log`;
515
533
  let files;
516
534
  try {
517
- if (fs.existsSync(dirPath)) {
535
+ if (existsSync(dirPath)) {
518
536
  console.log('Clear controller log...');
519
- files = fs.readdirSync(dirPath);
537
+ files = readdirSync(dirPath);
520
538
  } else {
521
539
  console.log('Create controller log directory...');
522
540
  files = [];
523
- fs.mkdirSync(dirPath);
541
+ mkdirSync(dirPath);
524
542
  }
525
- } catch(e) {
543
+ } catch (e) {
526
544
  console.error(`Cannot read "${dirPath}"`);
527
545
  return;
528
546
  }
@@ -530,7 +548,7 @@ function clearControllerLog() {
530
548
  try {
531
549
  for (let i = 0; i < files.length; i++) {
532
550
  const filePath = `${dirPath}/${files[i]}`;
533
- fs.unlinkSync(filePath);
551
+ unlinkSync(filePath);
534
552
  }
535
553
  console.log('Controller log cleared');
536
554
  } catch (err) {
@@ -543,15 +561,15 @@ function clearDB() {
543
561
  const dirPath = `${rootDir}tmp/iobroker-data/sqlite`;
544
562
  let files;
545
563
  try {
546
- if (fs.existsSync(dirPath)) {
564
+ if (existsSync(dirPath)) {
547
565
  console.log('Clear sqlite DB...');
548
- files = fs.readdirSync(dirPath);
566
+ files = readdirSync(dirPath);
549
567
  } else {
550
568
  console.log('Create controller log directory...');
551
569
  files = [];
552
- fs.mkdirSync(dirPath);
570
+ mkdirSync(dirPath);
553
571
  }
554
- } catch(e) {
572
+ } catch (e) {
555
573
  console.error(`Cannot read "${dirPath}"`);
556
574
  return;
557
575
  }
@@ -559,7 +577,7 @@ function clearDB() {
559
577
  try {
560
578
  for (let i = 0; i < files.length; i++) {
561
579
  const filePath = `${dirPath}/${files[i]}`;
562
- fs.unlinkSync(filePath);
580
+ unlinkSync(filePath);
563
581
  }
564
582
  console.log('Clear sqlite DB');
565
583
  } catch (err) {
@@ -576,8 +594,8 @@ function clearDB() {
576
594
  * @param {LegacyTestingOptions} options specify attributes which should be overridden
577
595
  */
578
596
  function setOptions(options) {
579
- if (options.rootDir && fs.existsSync(options.rootDir) && rootDir !== options.rootDir) {
580
- rootDir = options.rootDir
597
+ if (options.rootDir && existsSync(options.rootDir) && rootDir !== options.rootDir) {
598
+ rootDir = options.rootDir;
581
599
  initialize();
582
600
  }
583
601
  }
@@ -614,11 +632,11 @@ function setupController(preInstalledAdapters, cb) {
614
632
  });
615
633
  }
616
634
 
617
- async function getObject(id){
618
- if (fs.existsSync(`${rootDir}tmp/${appName}-data/objects.json`)) {
619
- const objects = JSON.parse(fs.readFileSync(`${rootDir}tmp/${appName}-data/objects.json`).toString());
635
+ async function getObject(id) {
636
+ if (existsSync(`${rootDir}tmp/${appName}-data/objects.json`)) {
637
+ const objects = JSON.parse(readFileSync(`${rootDir}tmp/${appName}-data/objects.json`).toString());
620
638
  return objects[id];
621
- } else if (fs.existsSync(`${rootDir}tmp/${appName}-data/objects.jsonl`)) {
639
+ } else if (existsSync(`${rootDir}tmp/${appName}-data/objects.jsonl`)) {
622
640
  loadJSONLDB();
623
641
  const db = new JSONLDB(`${rootDir}tmp/${appName}-data/objects.jsonl`);
624
642
  try {
@@ -639,11 +657,11 @@ async function getObject(id){
639
657
  }
640
658
  }
641
659
 
642
- async function setObject(id, obj){
643
- if (fs.existsSync(`${rootDir}tmp/${appName}-data/objects.json`)) {
644
- const objects = JSON.parse(fs.readFileSync(`${rootDir}tmp/${appName}-data/objects.json`).toString());
660
+ async function setObject(id, obj) {
661
+ if (existsSync(`${rootDir}tmp/${appName}-data/objects.json`)) {
662
+ const objects = JSON.parse(readFileSync(`${rootDir}tmp/${appName}-data/objects.json`).toString());
645
663
  objects[id] = obj;
646
- } else if (fs.existsSync(`${rootDir}tmp/${appName}-data/objects.jsonl`)) {
664
+ } else if (existsSync(`${rootDir}tmp/${appName}-data/objects.jsonl`)) {
647
665
  loadJSONLDB();
648
666
  const db = new JSONLDB(`${rootDir}tmp/${appName}-data/objects.jsonl`);
649
667
  try {
@@ -672,7 +690,7 @@ async function getSecret() {
672
690
  return systemConfig.native.secret;
673
691
  }
674
692
 
675
- function encrypt (key, value) {
693
+ function encrypt(key, value) {
676
694
  let result = '';
677
695
  for (let i = 0; i < value.length; ++i) {
678
696
  result += String.fromCharCode(key[i % key.length].charCodeAt(0) ^ value.charCodeAt(i));
@@ -696,20 +714,27 @@ function startCustomAdapter(adapterName, adapterInstance) {
696
714
  console.log(`startAdapter ${id} ...`);
697
715
  const _pkg = adapterName ? require(`${rootDir}tmp/node_modules/iobroker.${adapterName}/package.json`) : pkg;
698
716
  adapterName = adapterName || pkg.name.split('.')[1];
699
- if (fs.existsSync(`${rootDir}tmp/node_modules/iobroker.${adapterName}/${_pkg.main || 'main.js'}`)) {
717
+ if (existsSync(`${rootDir}tmp/node_modules/iobroker.${adapterName}/${_pkg.main || 'main.js'}`)) {
700
718
  try {
701
719
  if (debug) {
702
720
  // start controller
703
- pids[id] = cp.exec(`node node_modules/iobroker.${adapterName}/${_pkg.main || 'main.js'} ${adapterInstance} --debug --console silly`, {
704
- cwd: `${rootDir}tmp`,
705
- stdio: [0, 1, 2],
706
- });
721
+ pids[id] = exec(
722
+ `node node_modules/iobroker.${adapterName}/${_pkg.main || 'main.js'} ${adapterInstance} --debug --console silly`,
723
+ {
724
+ cwd: `${rootDir}tmp`,
725
+ stdio: [0, 1, 2],
726
+ },
727
+ );
707
728
  } else {
708
729
  // start controller
709
- pids[id] = cp.fork(`node_modules/iobroker.${adapterName}/${_pkg.main || 'main.js'}`, [adapterInstance, '--debug ', '--console', 'silly'], {
710
- cwd: `${rootDir}tmp`,
711
- stdio: [0, 1, 2, 'ipc'],
712
- });
730
+ pids[id] = fork(
731
+ `node_modules/iobroker.${adapterName}/${_pkg.main || 'main.js'}`,
732
+ [adapterInstance, '--debug ', '--console', 'silly'],
733
+ {
734
+ cwd: `${rootDir}tmp`,
735
+ stdio: [0, 1, 2, 'ipc'],
736
+ },
737
+ );
713
738
  }
714
739
  pids[id].on('exit', (code, signal) => {
715
740
  if (pids[id]) {
@@ -749,7 +774,7 @@ function startController(isStartAdapter, onObjectChange, onStateChange, callback
749
774
  }
750
775
 
751
776
  if (onStateChange === undefined) {
752
- callback = onObjectChange;
777
+ callback = onObjectChange;
753
778
  onObjectChange = undefined;
754
779
  }
755
780
 
@@ -768,26 +793,26 @@ function startController(isStartAdapter, onObjectChange, onStateChange, callback
768
793
 
769
794
  // rootDir + 'tmp/node_modules
770
795
  const objPath = require.resolve(`@iobroker/db-objects-${config.objects.type}`, {
771
- paths: [`${rootDir}tmp/node_modules`, rootDir, `${rootDir}tmp/node_modules/${appName}.js-controller`]
796
+ paths: [`${rootDir}tmp/node_modules`, rootDir, `${rootDir}tmp/node_modules/${appName}.js-controller`],
772
797
  });
773
798
  console.log(`Objects Path: ${objPath}`);
774
799
  const Objects = require(objPath).Server;
775
800
  objects = new Objects({
776
801
  connection: {
777
- 'type': config.objects.type,
778
- 'host': '127.0.0.1',
779
- 'port': 19001,
780
- 'user': '',
781
- 'pass': '',
782
- 'noFileCache': false,
783
- 'connectTimeout': 2000
802
+ type: config.objects.type,
803
+ host: '127.0.0.1',
804
+ port: 19001,
805
+ user: '',
806
+ pass: '',
807
+ noFileCache: false,
808
+ connectTimeout: 2000,
784
809
  },
785
810
  logger: {
786
811
  silly: msg => console.log(msg),
787
812
  debug: msg => console.log(msg),
788
813
  info: msg => console.log(msg),
789
814
  warn: msg => console.warn(msg),
790
- error: msg => console.error(msg)
815
+ error: msg => console.error(msg),
791
816
  },
792
817
  connected: () => {
793
818
  isObjectConnected = true;
@@ -803,7 +828,7 @@ function startController(isStartAdapter, onObjectChange, onStateChange, callback
803
828
  }
804
829
  }
805
830
  },
806
- change: onObjectChange
831
+ change: onObjectChange,
807
832
  });
808
833
 
809
834
  // Just open in memory DB itself
@@ -819,8 +844,8 @@ function startController(isStartAdapter, onObjectChange, onStateChange, callback
819
844
  port: 19000,
820
845
  options: {
821
846
  auth_pass: null,
822
- retry_max_delay: 15000
823
- }
847
+ retry_max_delay: 15000,
848
+ },
824
849
  },
825
850
  logger: {
826
851
  silly: function (msg) {
@@ -837,7 +862,7 @@ function startController(isStartAdapter, onObjectChange, onStateChange, callback
837
862
  },
838
863
  error: function (msg) {
839
864
  console.log(msg);
840
- }
865
+ },
841
866
  },
842
867
  connected: function () {
843
868
  isStatesConnected = true;
@@ -853,7 +878,7 @@ function startController(isStartAdapter, onObjectChange, onStateChange, callback
853
878
  }
854
879
  }
855
880
  },
856
- change: onStateChange
881
+ change: onStateChange,
857
882
  });
858
883
  } catch (err) {
859
884
  console.log(err);
@@ -968,11 +993,11 @@ async function getAdapterConfig(instance, customAdapterName) {
968
993
  }
969
994
 
970
995
  async function setOfflineState(id, state) {
971
- if (fs.existsSync(`${rootDir}tmp/${appName}-data/states.json`)) {
972
- const states = JSON.parse(fs.readFileSync(`${rootDir}tmp/${appName}-data/states.json`).toString());
996
+ if (existsSync(`${rootDir}tmp/${appName}-data/states.json`)) {
997
+ const states = JSON.parse(readFileSync(`${rootDir}tmp/${appName}-data/states.json`).toString());
973
998
  states[id] = state;
974
- fs.writeFileSync(`${rootDir}tmp/${appName}-data/states.json`, JSON.stringify(objects));
975
- } else if (fs.existsSync(`${rootDir}tmp/${appName}-data/states.jsonl`)) {
999
+ writeFileSync(`${rootDir}tmp/${appName}-data/states.json`, JSON.stringify(objects));
1000
+ } else if (existsSync(`${rootDir}tmp/${appName}-data/states.jsonl`)) {
976
1001
  loadJSONLDB();
977
1002
  const db = new JSONLDB(`${rootDir}tmp/${appName}-data/states.jsonl`);
978
1003
  await db.open();
@@ -987,10 +1012,11 @@ async function setOfflineState(id, state) {
987
1012
 
988
1013
  // Read config of the adapter
989
1014
  async function getOfflineState(id) {
990
- if (fs.existsSync(`${rootDir}tmp/${appName}-data/states.json`)) {
991
- const states = JSON.parse(fs.readFileSync(`${rootDir}tmp/${appName}-data/states.json`).toString());
1015
+ if (existsSync(`${rootDir}tmp/${appName}-data/states.json`)) {
1016
+ const states = JSON.parse(readFileSync(`${rootDir}tmp/${appName}-data/states.json`).toString());
992
1017
  return states[id];
993
- } else if (fs.existsSync(`${rootDir}tmp/${appName}-data/states.jsonl`)) {
1018
+ }
1019
+ if (existsSync(`${rootDir}tmp/${appName}-data/states.jsonl`)) {
994
1020
  loadJSONLDB();
995
1021
  const db = new JSONLDB(`${rootDir}tmp/${appName}-data/states.jsonl`);
996
1022
  await db.open();
@@ -999,9 +1025,8 @@ async function getOfflineState(id) {
999
1025
 
1000
1026
  await db.close();
1001
1027
  return state;
1002
- } else {
1003
- console.error(`getAdapterConfig: No objects file found in datadir ${rootDir}tmp/${appName}-data/`);
1004
1028
  }
1029
+ console.error(`getAdapterConfig: No objects file found in datadir ${rootDir}tmp/${appName}-data/`);
1005
1030
  }
1006
1031
 
1007
1032
  if (typeof module !== undefined && module.parent) {
@@ -5,7 +5,7 @@
5
5
  'use strict';
6
6
 
7
7
  const expect = require('chai').expect;
8
- const fs = require('fs');
8
+ const { readFileSync, existsSync } = require('node:fs');
9
9
 
10
10
  // node_modules/@iobroker/legacy-testing/tests/testPackageFiles.js
11
11
  const adapterDir = process.env.IOBROKER_ROOT_DIR || `${__dirname}/../../../../`;
@@ -15,10 +15,10 @@ describe('Test package.json and io-package.json', () => {
15
15
  it('Test package files', done => {
16
16
  console.log();
17
17
 
18
- const fileContentIOPackage = fs.readFileSync(`${adapterDir}/io-package.json`, 'utf8');
18
+ const fileContentIOPackage = readFileSync(`${adapterDir}/io-package.json`, 'utf8');
19
19
  const ioPackage = JSON.parse(fileContentIOPackage);
20
20
 
21
- const fileContentNPMPackage = fs.readFileSync(`${adapterDir}/package.json`, 'utf8');
21
+ const fileContentNPMPackage = readFileSync(`${adapterDir}/package.json`, 'utf8');
22
22
  const npmPackage = JSON.parse(fileContentNPMPackage);
23
23
 
24
24
  expect(ioPackage).to.be.an('object');
@@ -27,73 +27,121 @@ describe('Test package.json and io-package.json', () => {
27
27
  expect(ioPackage.common.version, 'ERROR: Version number in io-package.json needs to exist').to.exist;
28
28
  expect(npmPackage.version, 'ERROR: Version number in package.json needs to exist').to.exist;
29
29
 
30
- expect(ioPackage.common.version, 'ERROR: Version numbers in package.json and io-package.json needs to match').to.be.equal(npmPackage.version);
30
+ expect(
31
+ ioPackage.common.version,
32
+ 'ERROR: Version numbers in package.json and io-package.json needs to match',
33
+ ).to.be.equal(npmPackage.version);
31
34
 
32
35
  if (!ioPackage.common.news || !ioPackage.common.news[ioPackage.common.version]) {
33
- console.log('WARNING: No news entry for current version exists in io-package.json, no rollback in Admin possible!');
36
+ console.log(
37
+ 'WARNING: No news entry for current version exists in io-package.json, no rollback in Admin possible!',
38
+ );
34
39
  console.log();
35
40
  }
36
41
 
37
42
  expect(npmPackage.author, 'ERROR: Author in package.json needs to exist').to.exist;
38
43
  expect(ioPackage.common.authors, 'ERROR: Authors in io-package.json needs to exist').to.exist;
39
44
 
40
- expect(ioPackage.common.license || ioPackage.common.licenseInformation?.license, 'ERROR: License missing in io-package in common.license or in common.licenseInformation.license').to.exist;
45
+ expect(
46
+ ioPackage.common.license || ioPackage.common.licenseInformation?.license,
47
+ 'ERROR: License missing in io-package in common.license or in common.licenseInformation.license',
48
+ ).to.exist;
41
49
 
42
50
  if (ioPackage.common.name.includes('template')) {
43
51
  if (Array.isArray(ioPackage.common.authors)) {
44
- expect(ioPackage.common.authors.length, 'ERROR: Author in io-package.json needs to be set').to.not.be.equal(0);
52
+ expect(
53
+ ioPackage.common.authors.length,
54
+ 'ERROR: Author in io-package.json needs to be set',
55
+ ).to.not.be.equal(0);
45
56
  if (ioPackage.common.authors.length === 1) {
46
- expect(ioPackage.common.authors[0], 'ERROR: Author in io-package.json needs to be a real name').to.not.be.equal('my Name <my@email.com>');
57
+ expect(
58
+ ioPackage.common.authors[0],
59
+ 'ERROR: Author in io-package.json needs to be a real name',
60
+ ).to.not.be.equal('my Name <my@email.com>');
47
61
  }
48
62
  } else {
49
- expect(ioPackage.common.authors, 'ERROR: Author in io-package.json needs to be a real name').to.not.be.equal('my Name <my@email.com>');
63
+ expect(
64
+ ioPackage.common.authors,
65
+ 'ERROR: Author in io-package.json needs to be a real name',
66
+ ).to.not.be.equal('my Name <my@email.com>');
50
67
  }
51
68
  } else {
52
69
  console.log('WARNING: Testing for set authors field in io-package skipped because template adapter');
53
70
  console.log();
54
71
  }
55
72
 
56
- expect(fs.existsSync(`${adapterDir}/README.md`) || fs.existsSync(`${alternativeAdapterDir}/README.md`), 'ERROR: README.md needs to exist! Please create one with description, detail information and changelog. English is mandatory.').to.be.true;
73
+ expect(
74
+ existsSync(`${adapterDir}/README.md`) || existsSync(`${alternativeAdapterDir}/README.md`),
75
+ 'ERROR: README.md needs to exist! Please create one with description, detail information and changelog. English is mandatory.',
76
+ ).to.be.true;
57
77
 
58
78
  if (!ioPackage.common.titleLang || typeof ioPackage.common.titleLang !== 'object') {
59
79
  console.log('WARNING: titleLang is not existing in io-package.json. Please add');
60
80
  console.log();
61
81
  }
62
82
 
63
- if (ioPackage.common.title &&
83
+ if (
84
+ ioPackage.common.title &&
64
85
  (ioPackage.common.title.includes('iobroker') ||
65
- ioPackage.common.title.includes('ioBroker') ||
66
- ioPackage.common.title.includes('adapter') ||
67
- ioPackage.common.title.includes('Adapter'))
86
+ ioPackage.common.title.includes('ioBroker') ||
87
+ ioPackage.common.title.includes('adapter') ||
88
+ ioPackage.common.title.includes('Adapter'))
68
89
  ) {
69
- console.log('WARNING: title contains Adapter or ioBroker. It is clear anyway, that it is adapter for ioBroker.');
90
+ console.log(
91
+ 'WARNING: title contains Adapter or ioBroker. It is clear anyway, that it is adapter for ioBroker.',
92
+ );
70
93
  console.log();
71
94
  }
72
95
 
73
96
  if (!ioPackage.common.controller && !ioPackage.common.onlyWWW && !ioPackage.common.noConfig) {
74
- if (ioPackage.common.materialize || (ioPackage.common.adminUI && ioPackage.common.adminUI.conifg === 'materialize')) {
75
- expect(fs.existsSync(`${adapterDir}/admin/index_m.html`), 'Admin3 support is enabled in io-package.json, but index_m.html is missing!').to.be.true;
97
+ if (
98
+ ioPackage.common.materialize ||
99
+ (ioPackage.common.adminUI && ioPackage.common.adminUI.conifg === 'materialize')
100
+ ) {
101
+ expect(
102
+ existsSync(`${adapterDir}/admin/index_m.html`),
103
+ 'Admin3 support is enabled in io-package.json, but index_m.html is missing!',
104
+ ).to.be.true;
76
105
  }
77
- if (ioPackage.common.jsonConfig || (ioPackage.common.adminUI && ioPackage.common.adminUI.conifg === 'json')) {
78
- expect(fs.existsSync(`${adapterDir}/admin/jsonConfig.json`) || fs.existsSync(`${adapterDir}/admin/jsonConfig.json5`), 'Admin3 support is enabled in io-package.json, but jsonConfig.json(5) is missing!').to.be.true;
106
+ if (
107
+ ioPackage.common.jsonConfig ||
108
+ (ioPackage.common.adminUI && ioPackage.common.adminUI.conifg === 'json')
109
+ ) {
110
+ expect(
111
+ existsSync(`${adapterDir}/admin/jsonConfig.json`) ||
112
+ existsSync(`${adapterDir}/admin/jsonConfig.json5`),
113
+ 'Admin3 support is enabled in io-package.json, but jsonConfig.json(5) is missing!',
114
+ ).to.be.true;
79
115
  }
80
116
  if (ioPackage.common.adminUI && ioPackage.common.adminUI.custom === 'json') {
81
- expect(fs.existsSync(`${adapterDir}/admin/jsonCustom.json`) || fs.existsSync(`${adapterDir}/admin/jsonCustom.json5`), 'Custom config support is enabled in io-package.json, but jsonCustom.json(5) is missing!').to.be.true;
117
+ expect(
118
+ existsSync(`${adapterDir}/admin/jsonCustom.json`) ||
119
+ existsSync(`${adapterDir}/admin/jsonCustom.json5`),
120
+ 'Custom config support is enabled in io-package.json, but jsonCustom.json(5) is missing!',
121
+ ).to.be.true;
82
122
  }
83
123
  if (ioPackage.common.adminUI && ioPackage.common.adminUI.tab === 'html') {
84
- expect(fs.existsSync(`${adapterDir}/admin/tab.html`) || fs.existsSync(`${adapterDir}/admin/tab_m.html`), 'HTML-Tab support is enabled in io-package.json, but tab(_m).html is missing!').to.be.true;
124
+ expect(
125
+ existsSync(`${adapterDir}/admin/tab.html`) || existsSync(`${adapterDir}/admin/tab_m.html`),
126
+ 'HTML-Tab support is enabled in io-package.json, but tab(_m).html is missing!',
127
+ ).to.be.true;
85
128
  }
86
129
  }
87
130
 
88
- const licenseFileExists = fs.existsSync(`${adapterDir}/LICENSE`);
89
- const fileContentReadme = fs.existsSync(`${alternativeAdapterDir}/README.md`) ? fs.readFileSync(`${alternativeAdapterDir}/README.md`, 'utf8') : fs.readFileSync(`${adapterDir}/README.md`, 'utf8');
131
+ const licenseFileExists = existsSync(`${adapterDir}/LICENSE`);
132
+ const fileContentReadme = existsSync(`${alternativeAdapterDir}/README.md`)
133
+ ? readFileSync(`${alternativeAdapterDir}/README.md`, 'utf8')
134
+ : readFileSync(`${adapterDir}/README.md`, 'utf8');
90
135
 
91
136
  if (!fileContentReadme.includes('## Changelog')) {
92
137
  console.log('Warning: The README.md should have a section ## Changelog');
93
138
  console.log();
94
139
  }
95
140
 
96
- expect((licenseFileExists || fileContentReadme.includes('## License')), 'A LICENSE must exist as LICENSE file or as part of the README.md').to.be.true;
141
+ expect(
142
+ licenseFileExists || fileContentReadme.includes('## License'),
143
+ 'A LICENSE must exist as LICENSE file or as part of the README.md',
144
+ ).to.be.true;
97
145
 
98
146
  if (!licenseFileExists) {
99
147
  console.log('Warning: The License should also exist as LICENSE file');