@iobroker/legacy-testing 1.0.13 → 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 +51 -23
- package/engineHelper.js +69 -35
- package/guiHelper.js +11 -9
- package/package.json +4 -3
- package/setup.js +181 -156
- package/tests/testPackageFiles.js +72 -24
package/README.md
CHANGED
|
@@ -1,78 +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
|
-
|
|
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
|
+
|
|
17
25
|
### 1.0.13 (2024-08-18)
|
|
18
|
-
|
|
26
|
+
|
|
27
|
+
- (bluefox) Improved the GUI tests
|
|
19
28
|
|
|
20
29
|
### 1.0.12 (2024-04-27)
|
|
21
|
-
|
|
30
|
+
|
|
31
|
+
- (bluefox) Allowed setting license into `common.licenseInformation.license`
|
|
22
32
|
|
|
23
33
|
### 1.0.11 (2024-04-14)
|
|
24
|
-
|
|
34
|
+
|
|
35
|
+
- (bluefox) Added support for the once mode
|
|
25
36
|
|
|
26
37
|
### 1.0.10 (2024-04-10)
|
|
27
|
-
|
|
38
|
+
|
|
39
|
+
- (bluefox) Added support for vis-2 testing
|
|
28
40
|
|
|
29
41
|
### 1.0.9 (2023-12-19)
|
|
30
|
-
|
|
42
|
+
|
|
43
|
+
- (foxriver76) create folder on initialization
|
|
31
44
|
|
|
32
45
|
### 1.0.8 (2023-12-19)
|
|
33
|
-
|
|
46
|
+
|
|
47
|
+
- (foxriver76) use hardcoded appName instead of inference with a heuristic approach
|
|
34
48
|
|
|
35
49
|
### 1.0.7 (2023-12-19)
|
|
36
|
-
|
|
50
|
+
|
|
51
|
+
- (foxriver76) allow re-initialization after config change
|
|
37
52
|
|
|
38
53
|
### 1.0.6 (2023-12-19)
|
|
39
|
-
|
|
54
|
+
|
|
55
|
+
- (foxriver76) allow specifying the `rootDir`
|
|
40
56
|
|
|
41
57
|
### 1.0.5 (2023-12-15)
|
|
42
|
-
|
|
58
|
+
|
|
59
|
+
- (bluefox) Added support for vis-1 testing
|
|
43
60
|
|
|
44
61
|
### 1.0.4 (2023-12-15)
|
|
45
|
-
|
|
62
|
+
|
|
63
|
+
- (bluefox) Allowed GUI tests for tab_m.html too
|
|
46
64
|
|
|
47
65
|
### 1.0.3 (2023-10-26)
|
|
48
|
-
|
|
66
|
+
|
|
67
|
+
- (bluefox) Added helper files to test react admin GUI
|
|
49
68
|
|
|
50
69
|
### 1.0.1 (2023-10-16)
|
|
51
|
-
|
|
70
|
+
|
|
71
|
+
- (bluefox) Made `common.title` not required
|
|
52
72
|
|
|
53
73
|
### 1.0.0 (2023-09-18)
|
|
54
|
-
|
|
74
|
+
|
|
75
|
+
- (bluefox) Corrected error if systemConfig requested
|
|
55
76
|
|
|
56
77
|
### 0.3.7 (2023-07-07)
|
|
57
|
-
|
|
78
|
+
|
|
79
|
+
- (bluefox) Allowed using the specific version of js-controller
|
|
58
80
|
|
|
59
81
|
### 0.3.6 (2023-05-08)
|
|
60
|
-
|
|
61
|
-
|
|
82
|
+
|
|
83
|
+
- (bluefox) Added possibility to install additional adapters at start
|
|
84
|
+
- (bluefox) Added setOfflineState/getOfflineState
|
|
62
85
|
|
|
63
86
|
### 0.1.1 (2022-12-22)
|
|
64
|
-
|
|
87
|
+
|
|
88
|
+
- (bluefox) Extended testPackageFiles.js with checks
|
|
65
89
|
|
|
66
90
|
### 0.1.0 (2022-12-22)
|
|
67
|
-
|
|
91
|
+
|
|
92
|
+
- (bluefox) Corrected testPackageFiles.js
|
|
68
93
|
|
|
69
94
|
### 0.0.4 (2022-11-21)
|
|
70
|
-
|
|
95
|
+
|
|
96
|
+
- (bluefox) Added testPackageFiles.js
|
|
71
97
|
|
|
72
98
|
### 0.0.3 (2022-11-21)
|
|
73
|
-
|
|
99
|
+
|
|
100
|
+
- (bluefox) initial release
|
|
74
101
|
|
|
75
102
|
## License
|
|
103
|
+
|
|
76
104
|
MIT License
|
|
77
105
|
|
|
78
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
|
|
5
|
-
const
|
|
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
|
|
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 (
|
|
17
|
-
const files =
|
|
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 =
|
|
30
|
+
const stat = statSync(curPath);
|
|
21
31
|
if (stat.isDirectory()) {
|
|
22
32
|
deleteFoldersRecursive(curPath);
|
|
23
|
-
|
|
33
|
+
rmdirSync(curPath);
|
|
24
34
|
} else {
|
|
25
|
-
|
|
35
|
+
unlinkSync(curPath);
|
|
26
36
|
}
|
|
27
37
|
}
|
|
28
38
|
}
|
|
29
39
|
}
|
|
30
40
|
|
|
31
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
71
|
+
await setObject('system.config', systemConfig);
|
|
48
72
|
|
|
49
|
-
// start
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
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
|
-
|
|
64
|
-
|
|
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
|
|
72
|
-
|
|
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
|
-
|
|
107
|
+
stopController(normalTerminated => {
|
|
76
108
|
console.log(`Adapter normal terminated: ${normalTerminated}`);
|
|
77
109
|
resolve();
|
|
78
|
-
})
|
|
110
|
+
}),
|
|
111
|
+
);
|
|
79
112
|
}
|
|
80
113
|
|
|
81
|
-
function
|
|
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(
|
|
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
|
|
100
|
-
return new Promise(resolve =>
|
|
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
|
-
|
|
105
|
-
|
|
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
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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 =
|
|
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
|
-
!
|
|
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": "
|
|
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.
|
|
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
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
|
|
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 =
|
|
15
|
+
let adapterName = normalize(rootDir).replace(/\\/g, '/').split('/');
|
|
15
16
|
if (adapterName[adapterName.length - 2] === 'vis-2-widgets-testing') {
|
|
16
|
-
rootDir =
|
|
17
|
-
adapterName =
|
|
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
|
-
!
|
|
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 (
|
|
65
|
-
targetFile =
|
|
65
|
+
if (existsSync(target) && lstatSync(target).isDirectory()) {
|
|
66
|
+
targetFile = join(target, basename(source));
|
|
66
67
|
}
|
|
67
68
|
|
|
68
69
|
try {
|
|
69
|
-
|
|
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 =
|
|
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 =
|
|
84
|
-
if (!
|
|
85
|
-
|
|
84
|
+
const targetFolder = join(target, base);
|
|
85
|
+
if (!existsSync(targetFolder)) {
|
|
86
|
+
mkdirSync(targetFolder);
|
|
86
87
|
}
|
|
87
88
|
|
|
88
89
|
//copy
|
|
89
|
-
if (
|
|
90
|
-
files =
|
|
90
|
+
if (lstatSync(source).isDirectory()) {
|
|
91
|
+
files = readdirSync(source);
|
|
91
92
|
files.forEach(file => {
|
|
92
|
-
if (ignore
|
|
93
|
+
if (ignore?.includes(file)) {
|
|
93
94
|
return;
|
|
94
95
|
}
|
|
95
96
|
|
|
96
|
-
const curSource =
|
|
97
|
-
const curTarget =
|
|
98
|
-
if (
|
|
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 (
|
|
116
|
-
const f =
|
|
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
|
-
|
|
126
|
+
writeFileSync(`${dataDir}objects.json.original`, JSON.stringify(objects));
|
|
126
127
|
console.log('Store original objects.json');
|
|
127
128
|
}
|
|
128
129
|
|
|
129
|
-
if (
|
|
130
|
+
if (existsSync(`${dataDir}states.json`)) {
|
|
130
131
|
try {
|
|
131
|
-
const f =
|
|
132
|
-
|
|
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 (
|
|
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 =
|
|
162
|
-
|
|
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 (
|
|
167
|
-
const f =
|
|
168
|
-
|
|
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 (
|
|
178
|
-
const f =
|
|
179
|
-
|
|
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 (
|
|
182
|
-
const f =
|
|
183
|
-
|
|
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 (
|
|
187
|
-
const f =
|
|
188
|
-
|
|
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 (
|
|
191
|
-
const f =
|
|
192
|
-
|
|
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(
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
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
|
-
|
|
287
|
-
cwd:
|
|
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 =
|
|
293
|
-
cwd:
|
|
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 =
|
|
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 (
|
|
341
|
-
!
|
|
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 (
|
|
345
|
-
console.log(
|
|
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 =
|
|
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 =
|
|
358
|
-
cwd:
|
|
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
|
-
!
|
|
366
|
-
!
|
|
374
|
+
!existsSync(`${rootDir}tmp`) && mkdirSync(`${rootDir}tmp`);
|
|
375
|
+
!existsSync(`${rootDir}tmp/node_modules`) && mkdirSync(`${rootDir}tmp/node_modules`);
|
|
367
376
|
|
|
368
|
-
if (!
|
|
377
|
+
if (!existsSync(`${rootDir}tmp/node_modules/${appName}.js-controller`)) {
|
|
369
378
|
console.log('Copy js-controller...');
|
|
370
|
-
copyFolderRecursiveSync(
|
|
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 =
|
|
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 =
|
|
383
|
-
cwd:
|
|
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(
|
|
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 (!
|
|
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
|
-
|
|
408
|
-
|
|
409
|
-
|
|
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 =
|
|
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 =
|
|
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 (
|
|
434
|
-
_pid =
|
|
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
|
|
463
|
+
config.states.port = 19000;
|
|
447
464
|
|
|
448
|
-
|
|
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 (!
|
|
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
|
-
|
|
489
|
-
|
|
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
|
-
|
|
492
|
-
cwd:
|
|
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
|
-
|
|
497
|
-
cwd:
|
|
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 (!
|
|
522
|
+
if (!existsSync(`${rootDir}tmp/node_modules/${adapterName}`)) {
|
|
505
523
|
console.log(`Install ${adapterName}`);
|
|
506
|
-
|
|
507
|
-
cwd:
|
|
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 (
|
|
535
|
+
if (existsSync(dirPath)) {
|
|
518
536
|
console.log('Clear controller log...');
|
|
519
|
-
files =
|
|
537
|
+
files = readdirSync(dirPath);
|
|
520
538
|
} else {
|
|
521
539
|
console.log('Create controller log directory...');
|
|
522
540
|
files = [];
|
|
523
|
-
|
|
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
|
-
|
|
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 (
|
|
564
|
+
if (existsSync(dirPath)) {
|
|
547
565
|
console.log('Clear sqlite DB...');
|
|
548
|
-
files =
|
|
566
|
+
files = readdirSync(dirPath);
|
|
549
567
|
} else {
|
|
550
568
|
console.log('Create controller log directory...');
|
|
551
569
|
files = [];
|
|
552
|
-
|
|
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
|
-
|
|
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 &&
|
|
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 (
|
|
619
|
-
const objects = JSON.parse(
|
|
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 (
|
|
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 (
|
|
644
|
-
const objects = JSON.parse(
|
|
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 (
|
|
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
|
|
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 (
|
|
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] =
|
|
704
|
-
|
|
705
|
-
|
|
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] =
|
|
710
|
-
|
|
711
|
-
|
|
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
|
|
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
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
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 (
|
|
972
|
-
const states = JSON.parse(
|
|
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
|
-
|
|
975
|
-
} else if (
|
|
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 (
|
|
991
|
-
const states = JSON.parse(
|
|
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
|
-
}
|
|
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
|
|
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 =
|
|
18
|
+
const fileContentIOPackage = readFileSync(`${adapterDir}/io-package.json`, 'utf8');
|
|
19
19
|
const ioPackage = JSON.parse(fileContentIOPackage);
|
|
20
20
|
|
|
21
|
-
const fileContentNPMPackage =
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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 (
|
|
83
|
+
if (
|
|
84
|
+
ioPackage.common.title &&
|
|
64
85
|
(ioPackage.common.title.includes('iobroker') ||
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
86
|
+
ioPackage.common.title.includes('ioBroker') ||
|
|
87
|
+
ioPackage.common.title.includes('adapter') ||
|
|
88
|
+
ioPackage.common.title.includes('Adapter'))
|
|
68
89
|
) {
|
|
69
|
-
console.log(
|
|
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 (
|
|
75
|
-
|
|
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 (
|
|
78
|
-
|
|
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(
|
|
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(
|
|
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 =
|
|
89
|
-
const fileContentReadme =
|
|
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(
|
|
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');
|