@iobroker/legacy-testing 1.0.13 → 2.0.1

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,78 +1,109 @@
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.1 (2024-11-07)
22
+ - (bluefox) Added the step to upload of the admin files after installation
23
+
24
+ ### 2.0.0 (2024-11-05)
25
+
26
+ - (bluefox) Function names for GUI tests were changed: startIoBrokerAdmin => startIoBrokerAdapters, stopIoBrokerAdmin => stopIoBrokerAdapters
27
+
17
28
  ### 1.0.13 (2024-08-18)
18
- * (bluefox) Improve the GUI tests
29
+
30
+ - (bluefox) Improved the GUI tests
19
31
 
20
32
  ### 1.0.12 (2024-04-27)
21
- * (bluefox) Allowed setting license into `common.licenseInformation.license`
33
+
34
+ - (bluefox) Allowed setting license into `common.licenseInformation.license`
22
35
 
23
36
  ### 1.0.11 (2024-04-14)
24
- * (bluefox) Added support for the once mode
37
+
38
+ - (bluefox) Added support for the once mode
25
39
 
26
40
  ### 1.0.10 (2024-04-10)
27
- * (bluefox) Added support for vis-2 testing
41
+
42
+ - (bluefox) Added support for vis-2 testing
28
43
 
29
44
  ### 1.0.9 (2023-12-19)
30
- * (foxriver76) create folder on initialization
45
+
46
+ - (foxriver76) create folder on initialization
31
47
 
32
48
  ### 1.0.8 (2023-12-19)
33
- * (foxriver76) use hardcoded appName instead of inference with a heuristic approach
49
+
50
+ - (foxriver76) use hardcoded appName instead of inference with a heuristic approach
34
51
 
35
52
  ### 1.0.7 (2023-12-19)
36
- * (foxriver76) allow re-initialization after config change
53
+
54
+ - (foxriver76) allow re-initialization after config change
37
55
 
38
56
  ### 1.0.6 (2023-12-19)
39
- * (foxriver76) allow specifying the `rootDir`
57
+
58
+ - (foxriver76) allow specifying the `rootDir`
40
59
 
41
60
  ### 1.0.5 (2023-12-15)
42
- * (bluefox) Added support for vis-1 testing
61
+
62
+ - (bluefox) Added support for vis-1 testing
43
63
 
44
64
  ### 1.0.4 (2023-12-15)
45
- * (bluefox) Allowed GUI tests for tab_m.html too
65
+
66
+ - (bluefox) Allowed GUI tests for tab_m.html too
46
67
 
47
68
  ### 1.0.3 (2023-10-26)
48
- * (bluefox) Added helper files to test react admin GUI
69
+
70
+ - (bluefox) Added helper files to test react admin GUI
49
71
 
50
72
  ### 1.0.1 (2023-10-16)
51
- * (bluefox) Made `common.title` not required
73
+
74
+ - (bluefox) Made `common.title` not required
52
75
 
53
76
  ### 1.0.0 (2023-09-18)
54
- * (bluefox) Corrected error if systemConfig requested
77
+
78
+ - (bluefox) Corrected error if systemConfig requested
55
79
 
56
80
  ### 0.3.7 (2023-07-07)
57
- * (bluefox) Allowed using the specific version of js-controller
81
+
82
+ - (bluefox) Allowed using the specific version of js-controller
58
83
 
59
84
  ### 0.3.6 (2023-05-08)
60
- * (bluefox) Added possibility to install additional adapters at start
61
- * (bluefox) Added setOfflineState/getOfflineState
85
+
86
+ - (bluefox) Added possibility to install additional adapters at start
87
+ - (bluefox) Added setOfflineState/getOfflineState
62
88
 
63
89
  ### 0.1.1 (2022-12-22)
64
- * (bluefox) Extended testPackageFiles.js with checks
90
+
91
+ - (bluefox) Extended testPackageFiles.js with checks
65
92
 
66
93
  ### 0.1.0 (2022-12-22)
67
- * (bluefox) Corrected testPackageFiles.js
94
+
95
+ - (bluefox) Corrected testPackageFiles.js
68
96
 
69
97
  ### 0.0.4 (2022-11-21)
70
- * (bluefox) Added testPackageFiles.js
98
+
99
+ - (bluefox) Added testPackageFiles.js
71
100
 
72
101
  ### 0.0.3 (2022-11-21)
73
- * (bluefox) initial release
102
+
103
+ - (bluefox) initial release
74
104
 
75
105
  ## License
106
+
76
107
  MIT License
77
108
 
78
109
  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
@@ -4,19 +4,19 @@
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('node: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
19
- * @param {pathUrl} string
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
20
20
  */
21
21
  async function startBrowser(adapterName, rootDir, headless, pathUrl) {
22
22
  if (!rootDir.endsWith('/')) {
@@ -31,7 +31,7 @@ async function startBrowser(adapterName, rootDir, headless, pathUrl) {
31
31
  const timeout = 5000;
32
32
  pages[0].setDefaultTimeout(timeout);
33
33
 
34
- await pages[0].setViewport( {
34
+ await pages[0].setViewport({
35
35
  width: 1920,
36
36
  height: 1080,
37
37
  deviceScaleFactor: 1,
@@ -56,7 +56,9 @@ async function startBrowser(adapterName, rootDir, headless, pathUrl) {
56
56
  })
57
57
  .on('pageerror', ({ message }) => console.log(red(`[BROWSER] ${message}`)));
58
58
 
59
- pathUrl = pathUrl || `/adapter/${adapterName.includes('/') ? (!adapterName.includes('?') ? `${adapterName}?` : adapterName) : `${adapterName}/index_m.html?`}&newReact=true&0&react=dark`;
59
+ pathUrl =
60
+ pathUrl ||
61
+ `/adapter/${adapterName.includes('/') ? (!adapterName.includes('?') ? `${adapterName}?` : adapterName) : `${adapterName}/index_m.html?`}&newReact=true&0&react=dark`;
60
62
  if (!pathUrl.startsWith('/')) {
61
63
  pathUrl = `/${pathUrl}`;
62
64
  }
@@ -64,7 +66,7 @@ async function startBrowser(adapterName, rootDir, headless, pathUrl) {
64
66
  await gPage.goto(`http://127.0.0.1:8081${pathUrl}`, { waitUntil: 'domcontentloaded' });
65
67
 
66
68
  // Create directory
67
- !fs.existsSync(`${rootDir}tmp/screenshots`) && fs.mkdirSync(`${rootDir}tmp/screenshots`);
69
+ !existsSync(`${rootDir}tmp/screenshots`) && mkdirSync(`${rootDir}tmp/screenshots`);
68
70
  await gPage.screenshot({ path: `${rootDir}tmp/screenshots/00_starting.png` });
69
71
 
70
72
  return { browser, page: pages[0] };
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.13",
2
+ "version": "2.0.1",
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.7.3",
29
+ "mocha": "^10.8.2",
30
30
  "chai": "^4.5.0"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@alcalzone/release-script": "^3.8.0",
34
- "@alcalzone/release-script-plugin-license": "^3.7.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,35 @@ 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.');
519
+
520
+ // update admin files
521
+ execSync(`node ${rootDir}tmp/node_modules/${appName}.js-controller/iobroker.js upload ${pkg.name.replace('iobroker.', '')}`, {
522
+ cwd: `${rootDir}tmp`,
523
+ stdio: [0, 1, 2],
524
+ });
525
+
526
+ console.log('Adapter uploaded.');
501
527
  }
502
528
 
503
529
  function installCustomAdapter(adapterName) {
504
- if (!fs.existsSync(`${rootDir}tmp/node_modules/${adapterName}`)) {
530
+ if (!existsSync(`${rootDir}tmp/node_modules/${adapterName}`)) {
505
531
  console.log(`Install ${adapterName}`);
506
- cp.execSync(`npm install ${adapterName} --prefix ./ --omit=dev`, {
507
- cwd: `${rootDir}tmp/`,
532
+ execSync(`npm install ${adapterName} --prefix ./ --omit=dev`, {
533
+ cwd: `${rootDir}tmp/`,
508
534
  stdio: [0, 1, 2],
509
535
  });
510
536
  }
@@ -514,15 +540,15 @@ function clearControllerLog() {
514
540
  const dirPath = `${rootDir}tmp/log`;
515
541
  let files;
516
542
  try {
517
- if (fs.existsSync(dirPath)) {
543
+ if (existsSync(dirPath)) {
518
544
  console.log('Clear controller log...');
519
- files = fs.readdirSync(dirPath);
545
+ files = readdirSync(dirPath);
520
546
  } else {
521
547
  console.log('Create controller log directory...');
522
548
  files = [];
523
- fs.mkdirSync(dirPath);
549
+ mkdirSync(dirPath);
524
550
  }
525
- } catch(e) {
551
+ } catch (e) {
526
552
  console.error(`Cannot read "${dirPath}"`);
527
553
  return;
528
554
  }
@@ -530,7 +556,7 @@ function clearControllerLog() {
530
556
  try {
531
557
  for (let i = 0; i < files.length; i++) {
532
558
  const filePath = `${dirPath}/${files[i]}`;
533
- fs.unlinkSync(filePath);
559
+ unlinkSync(filePath);
534
560
  }
535
561
  console.log('Controller log cleared');
536
562
  } catch (err) {
@@ -543,15 +569,15 @@ function clearDB() {
543
569
  const dirPath = `${rootDir}tmp/iobroker-data/sqlite`;
544
570
  let files;
545
571
  try {
546
- if (fs.existsSync(dirPath)) {
572
+ if (existsSync(dirPath)) {
547
573
  console.log('Clear sqlite DB...');
548
- files = fs.readdirSync(dirPath);
574
+ files = readdirSync(dirPath);
549
575
  } else {
550
576
  console.log('Create controller log directory...');
551
577
  files = [];
552
- fs.mkdirSync(dirPath);
578
+ mkdirSync(dirPath);
553
579
  }
554
- } catch(e) {
580
+ } catch (e) {
555
581
  console.error(`Cannot read "${dirPath}"`);
556
582
  return;
557
583
  }
@@ -559,7 +585,7 @@ function clearDB() {
559
585
  try {
560
586
  for (let i = 0; i < files.length; i++) {
561
587
  const filePath = `${dirPath}/${files[i]}`;
562
- fs.unlinkSync(filePath);
588
+ unlinkSync(filePath);
563
589
  }
564
590
  console.log('Clear sqlite DB');
565
591
  } catch (err) {
@@ -576,8 +602,8 @@ function clearDB() {
576
602
  * @param {LegacyTestingOptions} options specify attributes which should be overridden
577
603
  */
578
604
  function setOptions(options) {
579
- if (options.rootDir && fs.existsSync(options.rootDir) && rootDir !== options.rootDir) {
580
- rootDir = options.rootDir
605
+ if (options.rootDir && existsSync(options.rootDir) && rootDir !== options.rootDir) {
606
+ rootDir = options.rootDir;
581
607
  initialize();
582
608
  }
583
609
  }
@@ -614,11 +640,11 @@ function setupController(preInstalledAdapters, cb) {
614
640
  });
615
641
  }
616
642
 
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());
643
+ async function getObject(id) {
644
+ if (existsSync(`${rootDir}tmp/${appName}-data/objects.json`)) {
645
+ const objects = JSON.parse(readFileSync(`${rootDir}tmp/${appName}-data/objects.json`).toString());
620
646
  return objects[id];
621
- } else if (fs.existsSync(`${rootDir}tmp/${appName}-data/objects.jsonl`)) {
647
+ } else if (existsSync(`${rootDir}tmp/${appName}-data/objects.jsonl`)) {
622
648
  loadJSONLDB();
623
649
  const db = new JSONLDB(`${rootDir}tmp/${appName}-data/objects.jsonl`);
624
650
  try {
@@ -639,11 +665,11 @@ async function getObject(id){
639
665
  }
640
666
  }
641
667
 
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());
668
+ async function setObject(id, obj) {
669
+ if (existsSync(`${rootDir}tmp/${appName}-data/objects.json`)) {
670
+ const objects = JSON.parse(readFileSync(`${rootDir}tmp/${appName}-data/objects.json`).toString());
645
671
  objects[id] = obj;
646
- } else if (fs.existsSync(`${rootDir}tmp/${appName}-data/objects.jsonl`)) {
672
+ } else if (existsSync(`${rootDir}tmp/${appName}-data/objects.jsonl`)) {
647
673
  loadJSONLDB();
648
674
  const db = new JSONLDB(`${rootDir}tmp/${appName}-data/objects.jsonl`);
649
675
  try {
@@ -672,7 +698,7 @@ async function getSecret() {
672
698
  return systemConfig.native.secret;
673
699
  }
674
700
 
675
- function encrypt (key, value) {
701
+ function encrypt(key, value) {
676
702
  let result = '';
677
703
  for (let i = 0; i < value.length; ++i) {
678
704
  result += String.fromCharCode(key[i % key.length].charCodeAt(0) ^ value.charCodeAt(i));
@@ -696,20 +722,27 @@ function startCustomAdapter(adapterName, adapterInstance) {
696
722
  console.log(`startAdapter ${id} ...`);
697
723
  const _pkg = adapterName ? require(`${rootDir}tmp/node_modules/iobroker.${adapterName}/package.json`) : pkg;
698
724
  adapterName = adapterName || pkg.name.split('.')[1];
699
- if (fs.existsSync(`${rootDir}tmp/node_modules/iobroker.${adapterName}/${_pkg.main || 'main.js'}`)) {
725
+ if (existsSync(`${rootDir}tmp/node_modules/iobroker.${adapterName}/${_pkg.main || 'main.js'}`)) {
700
726
  try {
701
727
  if (debug) {
702
728
  // 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
- });
729
+ pids[id] = exec(
730
+ `node node_modules/iobroker.${adapterName}/${_pkg.main || 'main.js'} ${adapterInstance} --debug --console silly`,
731
+ {
732
+ cwd: `${rootDir}tmp`,
733
+ stdio: [0, 1, 2],
734
+ },
735
+ );
707
736
  } else {
708
737
  // 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
- });
738
+ pids[id] = fork(
739
+ `node_modules/iobroker.${adapterName}/${_pkg.main || 'main.js'}`,
740
+ [adapterInstance, '--debug ', '--console', 'silly'],
741
+ {
742
+ cwd: `${rootDir}tmp`,
743
+ stdio: [0, 1, 2, 'ipc'],
744
+ },
745
+ );
713
746
  }
714
747
  pids[id].on('exit', (code, signal) => {
715
748
  if (pids[id]) {
@@ -749,7 +782,7 @@ function startController(isStartAdapter, onObjectChange, onStateChange, callback
749
782
  }
750
783
 
751
784
  if (onStateChange === undefined) {
752
- callback = onObjectChange;
785
+ callback = onObjectChange;
753
786
  onObjectChange = undefined;
754
787
  }
755
788
 
@@ -768,26 +801,26 @@ function startController(isStartAdapter, onObjectChange, onStateChange, callback
768
801
 
769
802
  // rootDir + 'tmp/node_modules
770
803
  const objPath = require.resolve(`@iobroker/db-objects-${config.objects.type}`, {
771
- paths: [`${rootDir}tmp/node_modules`, rootDir, `${rootDir}tmp/node_modules/${appName}.js-controller`]
804
+ paths: [`${rootDir}tmp/node_modules`, rootDir, `${rootDir}tmp/node_modules/${appName}.js-controller`],
772
805
  });
773
806
  console.log(`Objects Path: ${objPath}`);
774
807
  const Objects = require(objPath).Server;
775
808
  objects = new Objects({
776
809
  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
810
+ type: config.objects.type,
811
+ host: '127.0.0.1',
812
+ port: 19001,
813
+ user: '',
814
+ pass: '',
815
+ noFileCache: false,
816
+ connectTimeout: 2000,
784
817
  },
785
818
  logger: {
786
819
  silly: msg => console.log(msg),
787
820
  debug: msg => console.log(msg),
788
821
  info: msg => console.log(msg),
789
822
  warn: msg => console.warn(msg),
790
- error: msg => console.error(msg)
823
+ error: msg => console.error(msg),
791
824
  },
792
825
  connected: () => {
793
826
  isObjectConnected = true;
@@ -803,7 +836,7 @@ function startController(isStartAdapter, onObjectChange, onStateChange, callback
803
836
  }
804
837
  }
805
838
  },
806
- change: onObjectChange
839
+ change: onObjectChange,
807
840
  });
808
841
 
809
842
  // Just open in memory DB itself
@@ -819,8 +852,8 @@ function startController(isStartAdapter, onObjectChange, onStateChange, callback
819
852
  port: 19000,
820
853
  options: {
821
854
  auth_pass: null,
822
- retry_max_delay: 15000
823
- }
855
+ retry_max_delay: 15000,
856
+ },
824
857
  },
825
858
  logger: {
826
859
  silly: function (msg) {
@@ -837,7 +870,7 @@ function startController(isStartAdapter, onObjectChange, onStateChange, callback
837
870
  },
838
871
  error: function (msg) {
839
872
  console.log(msg);
840
- }
873
+ },
841
874
  },
842
875
  connected: function () {
843
876
  isStatesConnected = true;
@@ -853,7 +886,7 @@ function startController(isStartAdapter, onObjectChange, onStateChange, callback
853
886
  }
854
887
  }
855
888
  },
856
- change: onStateChange
889
+ change: onStateChange,
857
890
  });
858
891
  } catch (err) {
859
892
  console.log(err);
@@ -968,11 +1001,11 @@ async function getAdapterConfig(instance, customAdapterName) {
968
1001
  }
969
1002
 
970
1003
  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());
1004
+ if (existsSync(`${rootDir}tmp/${appName}-data/states.json`)) {
1005
+ const states = JSON.parse(readFileSync(`${rootDir}tmp/${appName}-data/states.json`).toString());
973
1006
  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`)) {
1007
+ writeFileSync(`${rootDir}tmp/${appName}-data/states.json`, JSON.stringify(objects));
1008
+ } else if (existsSync(`${rootDir}tmp/${appName}-data/states.jsonl`)) {
976
1009
  loadJSONLDB();
977
1010
  const db = new JSONLDB(`${rootDir}tmp/${appName}-data/states.jsonl`);
978
1011
  await db.open();
@@ -987,10 +1020,11 @@ async function setOfflineState(id, state) {
987
1020
 
988
1021
  // Read config of the adapter
989
1022
  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());
1023
+ if (existsSync(`${rootDir}tmp/${appName}-data/states.json`)) {
1024
+ const states = JSON.parse(readFileSync(`${rootDir}tmp/${appName}-data/states.json`).toString());
992
1025
  return states[id];
993
- } else if (fs.existsSync(`${rootDir}tmp/${appName}-data/states.jsonl`)) {
1026
+ }
1027
+ if (existsSync(`${rootDir}tmp/${appName}-data/states.jsonl`)) {
994
1028
  loadJSONLDB();
995
1029
  const db = new JSONLDB(`${rootDir}tmp/${appName}-data/states.jsonl`);
996
1030
  await db.open();
@@ -999,9 +1033,8 @@ async function getOfflineState(id) {
999
1033
 
1000
1034
  await db.close();
1001
1035
  return state;
1002
- } else {
1003
- console.error(`getAdapterConfig: No objects file found in datadir ${rootDir}tmp/${appName}-data/`);
1004
1036
  }
1037
+ console.error(`getAdapterConfig: No objects file found in datadir ${rootDir}tmp/${appName}-data/`);
1005
1038
  }
1006
1039
 
1007
1040
  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');