@iobroker/legacy-testing 2.0.1 → 2.1.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/LICENSE +1 -1
- package/README.md +8 -3
- package/build/engineHelper.d.ts +21 -0
- package/build/engineHelper.js +114 -0
- package/build/guiHelper.d.ts +15 -0
- package/build/guiHelper.js +81 -0
- package/build/setup.d.ts +53 -0
- package/build/setup.js +986 -0
- package/build/tests/testPackageFiles.d.ts +1 -0
- package/build/tests/testPackageFiles.js +89 -0
- package/package.json +44 -10
- package/engineHelper.js +0 -141
- package/guiHelper.js +0 -92
- package/setup.js +0 -1062
- package/tests/testPackageFiles.js +0 -157
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2022-
|
|
3
|
+
Copyright (c) 2022-2026 bluefox <dogafox@gmail.com>
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -13,11 +13,16 @@ Legacy test modules for ioBroker
|
|
|
13
13
|
|
|
14
14
|
## Usage of the specific js-controller version
|
|
15
15
|
|
|
16
|
-
Set process.env.JS_CONTROLLER_VERSION to version e.g. `5.0.5-alpha.0-20230617-464b0fd6`
|
|
16
|
+
Set `process.env.JS_CONTROLLER_VERSION` to version e.g. `5.0.5-alpha.0-20230617-464b0fd6`
|
|
17
17
|
|
|
18
18
|
## Changelog
|
|
19
|
+
### 2.1.1 (2026-07-12)
|
|
20
|
+
- (@GermanBluefox) The module was rewritten in TypeScript. The sources live now in `src/` and are compiled to `build/`. The public API and import paths stayed the same.
|
|
21
|
+
- (@GermanBluefox) If `JS_CONTROLLER_VERSION` is not set, js-controller `7.2.2` is installed on Node.js <= 20 and the `dev` build on newer Node.js versions.
|
|
22
|
+
|
|
23
|
+
### 2.0.2 (2025-01-21)
|
|
24
|
+
- (@GermanBluefox) Packages were updated
|
|
19
25
|
|
|
20
|
-
<!-- ### **WORK IN PROGRESS** -->
|
|
21
26
|
### 2.0.1 (2024-11-07)
|
|
22
27
|
- (bluefox) Added the step to upload of the admin files after installation
|
|
23
28
|
|
|
@@ -106,7 +111,7 @@ Set process.env.JS_CONTROLLER_VERSION to version e.g. `5.0.5-alpha.0-20230617-46
|
|
|
106
111
|
|
|
107
112
|
MIT License
|
|
108
113
|
|
|
109
|
-
Copyright (c) 2022-
|
|
114
|
+
Copyright (c) 2022-2026 bluefox <dogafox@gmail.com>
|
|
110
115
|
|
|
111
116
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
112
117
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type ObjectsClient, type StatesClient } from './setup';
|
|
2
|
+
type OnStateChanged = (id: string, state: ioBroker.State | null | undefined) => void;
|
|
3
|
+
/** Options for {@link startIoBrokerAdapters} */
|
|
4
|
+
export interface StartIoBrokerAdaptersOptions {
|
|
5
|
+
/** The root directory of the project */
|
|
6
|
+
rootDir?: string;
|
|
7
|
+
/** The adapters to start. Default is `['admin']` */
|
|
8
|
+
adapters?: string[];
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Start ioBroker controller and provided adapters. If no adapters are provided, only the admin will be started.
|
|
12
|
+
*
|
|
13
|
+
* @param options options for starting the adapters
|
|
14
|
+
*/
|
|
15
|
+
declare function startIoBrokerAdapters(options?: StartIoBrokerAdaptersOptions): Promise<{
|
|
16
|
+
objects: ObjectsClient;
|
|
17
|
+
states: StatesClient;
|
|
18
|
+
}>;
|
|
19
|
+
declare function stopIoBrokerAdapters(): Promise<void>;
|
|
20
|
+
export { startIoBrokerAdapters, stopIoBrokerAdapters };
|
|
21
|
+
export declare function setOnStateChanged(cb: OnStateChanged): void;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.startIoBrokerAdapters = startIoBrokerAdapters;
|
|
4
|
+
exports.stopIoBrokerAdapters = stopIoBrokerAdapters;
|
|
5
|
+
exports.setOnStateChanged = setOnStateChanged;
|
|
6
|
+
/**
|
|
7
|
+
* This file starts and stops the admin adapter including js-controller
|
|
8
|
+
*/
|
|
9
|
+
const node_fs_1 = require("node:fs");
|
|
10
|
+
const setup_1 = require("./setup");
|
|
11
|
+
let rootDir = `${__dirname}/../../../`;
|
|
12
|
+
let objects = null;
|
|
13
|
+
let states = null;
|
|
14
|
+
let onStateChanged = null;
|
|
15
|
+
function deleteFoldersRecursive(path) {
|
|
16
|
+
if (path.endsWith('/')) {
|
|
17
|
+
path = path.substring(0, path.length - 1);
|
|
18
|
+
}
|
|
19
|
+
if ((0, node_fs_1.existsSync)(path)) {
|
|
20
|
+
const files = (0, node_fs_1.readdirSync)(path);
|
|
21
|
+
for (const file of files) {
|
|
22
|
+
const curPath = `${path}/${file}`;
|
|
23
|
+
const stat = (0, node_fs_1.statSync)(curPath);
|
|
24
|
+
if (stat.isDirectory()) {
|
|
25
|
+
deleteFoldersRecursive(curPath);
|
|
26
|
+
(0, node_fs_1.rmdirSync)(curPath);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
(0, node_fs_1.unlinkSync)(curPath);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
let startedAdapters = ['admin'];
|
|
35
|
+
/**
|
|
36
|
+
* Start ioBroker controller and provided adapters. If no adapters are provided, only the admin will be started.
|
|
37
|
+
*
|
|
38
|
+
* @param options options for starting the adapters
|
|
39
|
+
*/
|
|
40
|
+
function startIoBrokerAdapters(options) {
|
|
41
|
+
const opts = options || {};
|
|
42
|
+
if (opts.rootDir) {
|
|
43
|
+
rootDir = opts.rootDir;
|
|
44
|
+
}
|
|
45
|
+
return new Promise(resolve => {
|
|
46
|
+
void (async () => {
|
|
47
|
+
// delete the old project
|
|
48
|
+
deleteFoldersRecursive(`${rootDir}tmp/screenshots`);
|
|
49
|
+
const adapters = opts.adapters || startedAdapters;
|
|
50
|
+
startedAdapters = adapters;
|
|
51
|
+
for (let a = 0; a < adapters.length; a++) {
|
|
52
|
+
await (0, setup_1.setOfflineState)(`system.adapter.${adapters[a]}.0.alive`, { val: false });
|
|
53
|
+
}
|
|
54
|
+
(0, setup_1.setupController)(adapters, async (systemConfig) => {
|
|
55
|
+
// disable statistics and set license accepted
|
|
56
|
+
systemConfig.common.licenseConfirmed = true;
|
|
57
|
+
systemConfig.common.diag = 'none';
|
|
58
|
+
await (0, setup_1.setObject)('system.config', systemConfig);
|
|
59
|
+
// start adapters
|
|
60
|
+
for (let a = 0; a < adapters.length; a++) {
|
|
61
|
+
const adapter = adapters[a];
|
|
62
|
+
const adapterConfig = await (0, setup_1.getAdapterConfig)(0, adapter);
|
|
63
|
+
if (adapterConfig?.common) {
|
|
64
|
+
adapterConfig.common.enabled = true;
|
|
65
|
+
await (0, setup_1.setAdapterConfig)(adapterConfig.common, adapterConfig.native, 0, adapter);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
(0, setup_1.startController)(false, // do not start widgets
|
|
69
|
+
() => { }, (id, state) => onStateChanged?.(id, state), async (_objects, _states) => {
|
|
70
|
+
objects = _objects;
|
|
71
|
+
states = _states;
|
|
72
|
+
for (let a = 0; a < adapters.length; a++) {
|
|
73
|
+
(0, setup_1.startCustomAdapter)(adapters[a], 0);
|
|
74
|
+
await checkIsAdapterStartedAsync(adapters[a], states);
|
|
75
|
+
}
|
|
76
|
+
resolve({ objects, states });
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
})();
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
async function stopIoBrokerAdapters() {
|
|
83
|
+
for (let a = 0; a < startedAdapters.length; a++) {
|
|
84
|
+
await (0, setup_1.stopCustomAdapter)(startedAdapters[a], 0);
|
|
85
|
+
}
|
|
86
|
+
await new Promise(resolve => (0, setup_1.stopController)(normalTerminated => {
|
|
87
|
+
console.log(`Adapter normal terminated: ${normalTerminated}`);
|
|
88
|
+
resolve();
|
|
89
|
+
}));
|
|
90
|
+
}
|
|
91
|
+
function checkIsAdapterStarted(adapterName, states, cb, counter) {
|
|
92
|
+
counter ??= 20;
|
|
93
|
+
if (counter === 0) {
|
|
94
|
+
return cb?.(`Cannot check value Of State system.adapter.${adapterName}.0.alive`);
|
|
95
|
+
}
|
|
96
|
+
void states.getState(`system.adapter.${adapterName}.0.alive`, (err, state) => {
|
|
97
|
+
console.log(`[${counter}]Check if ${adapterName} is started "system.adapter.${adapterName}.0.alive" = ${JSON.stringify(state)}`);
|
|
98
|
+
if (err) {
|
|
99
|
+
console.error(err);
|
|
100
|
+
}
|
|
101
|
+
if (state?.val) {
|
|
102
|
+
cb?.();
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
setTimeout(() => checkIsAdapterStarted(adapterName, states, cb, counter - 1), 500);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
function checkIsAdapterStartedAsync(adapterName, states, counter) {
|
|
110
|
+
return new Promise(resolve => checkIsAdapterStarted(adapterName, states, () => resolve(), counter));
|
|
111
|
+
}
|
|
112
|
+
function setOnStateChanged(cb) {
|
|
113
|
+
onStateChanged = cb;
|
|
114
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type Browser, type Page } from 'puppeteer';
|
|
2
|
+
/**
|
|
3
|
+
* This function starts the browser and opens the desired adapter
|
|
4
|
+
*
|
|
5
|
+
* @param adapterName could be just an adapter name or adapter name with path, like 'device-manager/tab_m.html'
|
|
6
|
+
* @param rootDir the root directory of the project
|
|
7
|
+
* @param headless whether the browser should be started in headless mode
|
|
8
|
+
* @param pathUrl optional URL path to open instead of the default adapter page
|
|
9
|
+
*/
|
|
10
|
+
export declare function startBrowser(adapterName: string, rootDir: string, headless?: boolean, pathUrl?: string): Promise<{
|
|
11
|
+
browser: Browser;
|
|
12
|
+
page: Page;
|
|
13
|
+
}>;
|
|
14
|
+
export declare function stopBrowser(browser?: Browser): Promise<void>;
|
|
15
|
+
export declare function screenshot(rootDir: string, page?: Page, fileName?: string): Promise<void>;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.startBrowser = startBrowser;
|
|
7
|
+
exports.stopBrowser = stopBrowser;
|
|
8
|
+
exports.screenshot = screenshot;
|
|
9
|
+
/* This file helps to start and stop the browser and make screenshots of desired adapter
|
|
10
|
+
* Do not forget to include in package.json:
|
|
11
|
+
* "devDependencies": {
|
|
12
|
+
* "puppeteer": "^21.4.1",
|
|
13
|
+
* "colorette": "^1.2.1"
|
|
14
|
+
* }
|
|
15
|
+
**/
|
|
16
|
+
const puppeteer_1 = __importDefault(require("puppeteer"));
|
|
17
|
+
const colorette_1 = require("colorette");
|
|
18
|
+
const node_fs_1 = require("node:fs");
|
|
19
|
+
let gBrowser;
|
|
20
|
+
let gPage;
|
|
21
|
+
/**
|
|
22
|
+
* This function starts the browser and opens the desired adapter
|
|
23
|
+
*
|
|
24
|
+
* @param adapterName could be just an adapter name or adapter name with path, like 'device-manager/tab_m.html'
|
|
25
|
+
* @param rootDir the root directory of the project
|
|
26
|
+
* @param headless whether the browser should be started in headless mode
|
|
27
|
+
* @param pathUrl optional URL path to open instead of the default adapter page
|
|
28
|
+
*/
|
|
29
|
+
async function startBrowser(adapterName, rootDir, headless, pathUrl) {
|
|
30
|
+
if (!rootDir.endsWith('/')) {
|
|
31
|
+
rootDir += '/';
|
|
32
|
+
}
|
|
33
|
+
const browser = await puppeteer_1.default.launch({
|
|
34
|
+
headless: headless === undefined ? false : headless,
|
|
35
|
+
args: ['--no-sandbox', '--disable-setuid-sandbox'],
|
|
36
|
+
});
|
|
37
|
+
const pages = await browser.pages();
|
|
38
|
+
const timeout = 5000;
|
|
39
|
+
pages[0].setDefaultTimeout(timeout);
|
|
40
|
+
await pages[0].setViewport({
|
|
41
|
+
width: 1920,
|
|
42
|
+
height: 1080,
|
|
43
|
+
deviceScaleFactor: 1,
|
|
44
|
+
});
|
|
45
|
+
gBrowser = browser;
|
|
46
|
+
gPage = pages[0];
|
|
47
|
+
// LOGGING
|
|
48
|
+
gPage
|
|
49
|
+
.on('console', message => {
|
|
50
|
+
const type = message.type().substring(0, 3).toUpperCase();
|
|
51
|
+
const colors = {
|
|
52
|
+
LOG: (text) => `${text}`,
|
|
53
|
+
ERR: colorette_1.red,
|
|
54
|
+
WAR: colorette_1.yellow,
|
|
55
|
+
INF: colorette_1.cyan,
|
|
56
|
+
};
|
|
57
|
+
const color = colors[type] || colorette_1.blue;
|
|
58
|
+
console.log(color(`[BROWSER] ${type} ${message.text()}`));
|
|
59
|
+
})
|
|
60
|
+
.on('pageerror', ({ message }) => console.log((0, colorette_1.red)(`[BROWSER] ${message}`)));
|
|
61
|
+
pathUrl ||= `/adapter/${adapterName.includes('/') ? (!adapterName.includes('?') ? `${adapterName}?` : adapterName) : `${adapterName}/index_m.html?`}&newReact=true&0&react=dark`;
|
|
62
|
+
if (!pathUrl.startsWith('/')) {
|
|
63
|
+
pathUrl = `/${pathUrl}`;
|
|
64
|
+
}
|
|
65
|
+
await gPage.goto(`http://127.0.0.1:8081${pathUrl}`, { waitUntil: 'domcontentloaded' });
|
|
66
|
+
// Create directory
|
|
67
|
+
!(0, node_fs_1.existsSync)(`${rootDir}tmp/screenshots`) && (0, node_fs_1.mkdirSync)(`${rootDir}tmp/screenshots`);
|
|
68
|
+
await gPage.screenshot({ path: `${rootDir}tmp/screenshots/00_starting.png` });
|
|
69
|
+
return { browser, page: pages[0] };
|
|
70
|
+
}
|
|
71
|
+
async function stopBrowser(browser) {
|
|
72
|
+
browser ||= gBrowser;
|
|
73
|
+
await browser?.close();
|
|
74
|
+
}
|
|
75
|
+
async function screenshot(rootDir, page, fileName) {
|
|
76
|
+
if (!rootDir.endsWith('/')) {
|
|
77
|
+
rootDir += '/';
|
|
78
|
+
}
|
|
79
|
+
page ||= gPage;
|
|
80
|
+
await page?.screenshot({ path: `${rootDir}tmp/screenshots/${fileName}.png` });
|
|
81
|
+
}
|
package/build/setup.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { Client as ObjectsClient } from '@iobroker/db-objects-redis';
|
|
2
|
+
import type { Client as StatesClient } from '@iobroker/db-states-redis';
|
|
3
|
+
export type { ObjectsClient, StatesClient };
|
|
4
|
+
/** Options that can be overridden at runtime */
|
|
5
|
+
export interface LegacyTestingOptions {
|
|
6
|
+
rootDir?: string;
|
|
7
|
+
}
|
|
8
|
+
type ChangeHandlerObject = (id: string, obj: ioBroker.Object | null | undefined) => void;
|
|
9
|
+
type ChangeHandlerState = (id: string, obj: ioBroker.State | null | undefined) => void;
|
|
10
|
+
/**
|
|
11
|
+
* The objects/states database client instances are created from the dynamically
|
|
12
|
+
* resolved `@iobroker/db-objects-*` / `@iobroker/db-states-*` packages of the
|
|
13
|
+
* js-controller. Their full types are not available here, and they are handed to the
|
|
14
|
+
* caller as-is, so they are intentionally left untyped.
|
|
15
|
+
*/
|
|
16
|
+
type ControllerCallback = (objects: ObjectsClient, states: StatesClient) => void;
|
|
17
|
+
declare const adapterName: string;
|
|
18
|
+
/**
|
|
19
|
+
* Initialize logic, you can re-trigger it after config has changed
|
|
20
|
+
*/
|
|
21
|
+
declare function initialize(): void;
|
|
22
|
+
declare function installAdapter(customAdapterName?: string | (() => void) | null, cb?: () => void): Promise<void>;
|
|
23
|
+
declare function installCustomAdapter(customAdapterName: string): void;
|
|
24
|
+
/**
|
|
25
|
+
* Override options
|
|
26
|
+
*
|
|
27
|
+
* @param options specify attributes which should be overridden
|
|
28
|
+
*/
|
|
29
|
+
declare function setOptions(options: LegacyTestingOptions): void;
|
|
30
|
+
/**
|
|
31
|
+
* Install js-controller and set up the adapter
|
|
32
|
+
*
|
|
33
|
+
* @param preInstalledAdapters list of adapters which need to be installed additionally
|
|
34
|
+
* @param cb callback
|
|
35
|
+
*/
|
|
36
|
+
declare function setupController(preInstalledAdapters?: string[] | ((systemConfig: ioBroker.SystemConfigObject) => void) | null, cb?: (systemConfig: ioBroker.SystemConfigObject) => void): void;
|
|
37
|
+
declare function getObject<T extends ioBroker.Object = ioBroker.Object>(id: string): Promise<T | null | undefined>;
|
|
38
|
+
declare function setObject(id: string, obj: ioBroker.Object): Promise<ioBroker.Object | null | undefined>;
|
|
39
|
+
declare function getSecret(): Promise<string | undefined>;
|
|
40
|
+
declare function encrypt(key: string, value: string): string;
|
|
41
|
+
declare function startAdapter(objects: ObjectsClient, states: StatesClient, callback?: ControllerCallback): void;
|
|
42
|
+
declare function startCustomAdapter(customAdapterName?: string, adapterInstance?: number): void;
|
|
43
|
+
declare function startController(_isStartAdapter: boolean, _onObjectChange: ChangeHandlerObject, _onStateChange: ChangeHandlerState, _callback?: ControllerCallback): void;
|
|
44
|
+
declare function startController(_onObjectChange: ChangeHandlerObject, _onStateChange: ChangeHandlerState, _callback?: ControllerCallback): void;
|
|
45
|
+
declare function startController(_isStartAdapter: boolean, _callback?: ControllerCallback): void;
|
|
46
|
+
declare function stopAdapter(cb?: () => void): Promise<void>;
|
|
47
|
+
declare function stopCustomAdapter(customAdapterName?: string, adapterInstance?: number): Promise<void>;
|
|
48
|
+
declare function stopController(cb?: (normalTerminated: boolean) => void): Promise<void>;
|
|
49
|
+
declare function setAdapterConfig(common?: ioBroker.InstanceObject['common'], native?: ioBroker.InstanceObject['native'], instance?: number, customAdapterName?: string): Promise<void>;
|
|
50
|
+
declare function getAdapterConfig(instance?: number, customAdapterName?: string): Promise<ioBroker.InstanceObject | null | undefined>;
|
|
51
|
+
declare function setOfflineState(id: string, state: ioBroker.SettableState): Promise<void>;
|
|
52
|
+
declare function getOfflineState(id: string): Promise<ioBroker.State | null | undefined>;
|
|
53
|
+
export { getAdapterConfig, setAdapterConfig, startController, stopController, setupController, stopAdapter, startAdapter, installAdapter, adapterName, getSecret, encrypt, setOfflineState, getOfflineState, stopCustomAdapter, startCustomAdapter, installCustomAdapter, getObject, setObject, setOptions, initialize, };
|