@iobroker/legacy-testing 1.0.1 → 1.0.2
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 +3 -0
- package/engineHelper.js +107 -0
- package/guiHelper.js +73 -0
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -14,6 +14,9 @@ Set process.env.JS_CONTROLLER_VERSION to version e.g. `5.0.5-alpha.0-20230617-46
|
|
|
14
14
|
|
|
15
15
|
## Changelog
|
|
16
16
|
<!-- ### **WORK IN PROGRESS** -->
|
|
17
|
+
### 1.0.2 (2023-10-25)
|
|
18
|
+
* (bluefox) Added helper files to test react admin GUI
|
|
19
|
+
|
|
17
20
|
### 1.0.1 (2023-10-16)
|
|
18
21
|
* (bluefox) Made `common.title` not required
|
|
19
22
|
|
package/engineHelper.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file starts and stops the admin adapter including js-controller
|
|
3
|
+
*/
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const setup = require('./setup');
|
|
6
|
+
|
|
7
|
+
let rootDir = `${__dirname}/../../../`;
|
|
8
|
+
let objects = null;
|
|
9
|
+
let states = null;
|
|
10
|
+
let onStateChanged = null;
|
|
11
|
+
|
|
12
|
+
function deleteFoldersRecursive(path) {
|
|
13
|
+
if (path.endsWith('/')) {
|
|
14
|
+
path = path.substring(0, path.length - 1);
|
|
15
|
+
}
|
|
16
|
+
if (fs.existsSync(path)) {
|
|
17
|
+
const files = fs.readdirSync(path);
|
|
18
|
+
for (const file of files) {
|
|
19
|
+
const curPath = `${path}/${file}`;
|
|
20
|
+
const stat = fs.statSync(curPath);
|
|
21
|
+
if (stat.isDirectory()) {
|
|
22
|
+
deleteFoldersRecursive(curPath);
|
|
23
|
+
fs.rmdirSync(curPath);
|
|
24
|
+
} else {
|
|
25
|
+
fs.unlinkSync(curPath);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function startIoBrokerAdmin(options) {
|
|
32
|
+
options = options || {};
|
|
33
|
+
if (options.rootDir) {
|
|
34
|
+
rootDir = options.rootDir;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return new Promise(async resolve => {
|
|
38
|
+
// delete the old project
|
|
39
|
+
deleteFoldersRecursive(`${rootDir}tmp/screenshots`);
|
|
40
|
+
|
|
41
|
+
await setup.setOfflineState(`system.adapter.admin.0.alive`, { val: false });
|
|
42
|
+
|
|
43
|
+
setup.setupController(['admin'], async systemConfig => {
|
|
44
|
+
// disable statistics and set license accepted
|
|
45
|
+
systemConfig.common.licenseConfirmed = true;
|
|
46
|
+
systemConfig.common.diag = 'none';
|
|
47
|
+
await setup.setObject('system.config', systemConfig);
|
|
48
|
+
|
|
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');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
setup.startController(
|
|
57
|
+
false, // do not start widgets
|
|
58
|
+
(/* id, obj */) => {},
|
|
59
|
+
(id, state) => onStateChanged && onStateChanged(id, state),
|
|
60
|
+
async (_objects, _states) => {
|
|
61
|
+
objects = _objects;
|
|
62
|
+
states = _states;
|
|
63
|
+
setup.startCustomAdapter('admin', 0);
|
|
64
|
+
await checkIsWelcomeStartedAsync('admin', states);
|
|
65
|
+
resolve({ objects, states });
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async function stopIoBrokerAdmin() {
|
|
72
|
+
await setup.stopCustomAdapter('admin', 0);
|
|
73
|
+
|
|
74
|
+
await new Promise(resolve =>
|
|
75
|
+
setup.stopController(normalTerminated => {
|
|
76
|
+
console.log(`Adapter normal terminated: ${normalTerminated}`);
|
|
77
|
+
resolve();
|
|
78
|
+
}));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function checkIsWelcomeStarted(adapterName, states, cb, counter) {
|
|
82
|
+
counter = counter === undefined ? 20 : counter;
|
|
83
|
+
if (counter === 0) {
|
|
84
|
+
return cb && cb(`Cannot check value Of State system.adapter.${adapterName}.0.alive`);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
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)}`);
|
|
89
|
+
err && console.error(err);
|
|
90
|
+
if (state && state.val) {
|
|
91
|
+
cb && cb();
|
|
92
|
+
} else {
|
|
93
|
+
setTimeout(() =>
|
|
94
|
+
checkIsWelcomeStarted(adapterName, states, cb, counter - 1), 500);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function checkIsWelcomeStartedAsync(adapterName, states, counter) {
|
|
100
|
+
return new Promise(resolve => checkIsWelcomeStarted(adapterName, states, resolve, counter));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
module.exports = {
|
|
104
|
+
startIoBrokerAdmin,
|
|
105
|
+
stopIoBrokerAdmin,
|
|
106
|
+
setOnStateChanged: cb => onStateChanged = cb
|
|
107
|
+
};
|
package/guiHelper.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/* This file helps to start and stop the browser and make screenshots of desired adapter
|
|
2
|
+
* Do not forget to include into package.json:
|
|
3
|
+
* "devDependencies": {
|
|
4
|
+
* "puppeteer": "^21.4.1",
|
|
5
|
+
* "colorette": "^1.2.1"
|
|
6
|
+
* }
|
|
7
|
+
**/
|
|
8
|
+
const puppeteer = require('puppeteer');
|
|
9
|
+
const { blue, cyan, red, yellow } = require('colorette');
|
|
10
|
+
const fs = require('fs');
|
|
11
|
+
|
|
12
|
+
const rootDir = `${__dirname}/../`;
|
|
13
|
+
let gBrowser;
|
|
14
|
+
let gPage;
|
|
15
|
+
|
|
16
|
+
async function startBrowser(adapterName, headless) {
|
|
17
|
+
const browser = await puppeteer.launch({
|
|
18
|
+
headless: headless === undefined ? false : headless,
|
|
19
|
+
args: ['--no-sandbox', '--disable-setuid-sandbox']
|
|
20
|
+
});
|
|
21
|
+
const pages = await browser.pages();
|
|
22
|
+
const timeout = 5000;
|
|
23
|
+
pages[0].setDefaultTimeout(timeout);
|
|
24
|
+
|
|
25
|
+
await pages[0].setViewport( {
|
|
26
|
+
width: 1920,
|
|
27
|
+
height: 1080,
|
|
28
|
+
deviceScaleFactor: 1
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
gBrowser = browser;
|
|
32
|
+
gPage = pages[0];
|
|
33
|
+
|
|
34
|
+
// LOGGING
|
|
35
|
+
gPage
|
|
36
|
+
.on('console', message => {
|
|
37
|
+
const type = message.type().substr(0, 3).toUpperCase();
|
|
38
|
+
const colors = {
|
|
39
|
+
LOG: text => text,
|
|
40
|
+
ERR: red,
|
|
41
|
+
WAR: yellow,
|
|
42
|
+
INF: cyan
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const color = colors[type] || blue;
|
|
46
|
+
console.log(color(`[BROWSER] ${type} ${message.text()}`));
|
|
47
|
+
})
|
|
48
|
+
.on('pageerror', ({ message }) => console.log(red(`[BROWSER] ${message}`)));
|
|
49
|
+
|
|
50
|
+
await gPage.goto(`http://127.0.0.1:8081/adapter/${adapterName}/index_m.html?0&newReact=true&0&react=dark`, { waitUntil: 'domcontentloaded' });
|
|
51
|
+
|
|
52
|
+
// Create directory
|
|
53
|
+
!fs.existsSync(`${rootDir}tmp/screenshots`) && fs.mkdirSync(`${rootDir}tmp/screenshots`);
|
|
54
|
+
await gPage.screenshot({ path: `${rootDir}tmp/screenshots/00_starting.png` });
|
|
55
|
+
|
|
56
|
+
return { browser, page: pages[0] };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async function stopBrowser(browser) {
|
|
60
|
+
browser = browser || gBrowser;
|
|
61
|
+
await browser.close();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function screenshot(page, fileName) {
|
|
65
|
+
page = page || gPage;
|
|
66
|
+
await page.screenshot({ path: `${rootDir}tmp/screenshots/${fileName}.png` });
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
module.exports = {
|
|
70
|
+
startBrowser,
|
|
71
|
+
stopBrowser,
|
|
72
|
+
screenshot
|
|
73
|
+
};
|
package/package.json
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.0.
|
|
2
|
+
"version": "1.0.2",
|
|
3
3
|
"name": "@iobroker/legacy-testing",
|
|
4
4
|
"main": "setup.js",
|
|
5
5
|
"files": [
|
|
6
6
|
"setup.js",
|
|
7
|
+
"engineHelper.js",
|
|
8
|
+
"guiHelper.js",
|
|
7
9
|
"tests/"
|
|
8
10
|
],
|
|
9
11
|
"description": "Module to test ioBroker adapters with legacy tests. For new tests please use @iobroker/testing",
|