@iobroker/legacy-testing 0.2.0 → 0.2.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 +2 -1
- package/package.json +1 -1
- package/setup.js +43 -3
package/README.md
CHANGED
|
@@ -11,8 +11,9 @@ Legacy test modules for ioBroker
|
|
|
11
11
|
|
|
12
12
|
## Changelog
|
|
13
13
|
<!-- ### **WORK IN PROGRESS** -->
|
|
14
|
-
### 0.2.
|
|
14
|
+
### 0.2.2 (2023-05-07)
|
|
15
15
|
* (bluefox) Added possibility to install additional adapters at start
|
|
16
|
+
* (bluefox) Added setOfflineState/getOfflineState
|
|
16
17
|
|
|
17
18
|
### 0.1.1 (2022-12-22)
|
|
18
19
|
* (bluefox) Extended testPackageFiles.js with checks
|
package/package.json
CHANGED
package/setup.js
CHANGED
|
@@ -432,7 +432,8 @@ function installJsController(preInstalledAdapters, cb) {
|
|
|
432
432
|
});
|
|
433
433
|
} else {
|
|
434
434
|
// check if port 9000 is free, else admin adapter will be added to running instance
|
|
435
|
-
const
|
|
435
|
+
const { Socket } = require('net')
|
|
436
|
+
const client = new Socket();
|
|
436
437
|
client.on('error', () => {});
|
|
437
438
|
client.connect(9000, '127.0.0.1', () => {
|
|
438
439
|
console.error('Cannot initiate the first run of test, because one instance of application is running on this PC. Stop it and repeat.');
|
|
@@ -573,8 +574,8 @@ function clearDB() {
|
|
|
573
574
|
}
|
|
574
575
|
}
|
|
575
576
|
|
|
576
|
-
function setupController(cb) {
|
|
577
|
-
installJsController(async isInitialized => {
|
|
577
|
+
function setupController(preInstalledAdapters, cb) {
|
|
578
|
+
installJsController(preInstalledAdapters, async isInitialized => {
|
|
578
579
|
try {
|
|
579
580
|
clearControllerLog();
|
|
580
581
|
clearDB();
|
|
@@ -944,6 +945,43 @@ async function getAdapterConfig(instance, customAdapterName, customInstance) {
|
|
|
944
945
|
}
|
|
945
946
|
}
|
|
946
947
|
|
|
948
|
+
async function setOfflineState(id, state) {
|
|
949
|
+
if (fs.existsSync(`${rootDir}tmp/${appName}-data/states.json`)) {
|
|
950
|
+
const states = JSON.parse(fs.readFileSync(`${rootDir}tmp/${appName}-data/states.json`).toString());
|
|
951
|
+
states[id] = state;
|
|
952
|
+
fs.writeFileSync(`${rootDir}tmp/${appName}-data/states.json`, JSON.stringify(objects));
|
|
953
|
+
} else if (fs.existsSync(`${rootDir}tmp/${appName}-data/states.jsonl`)) {
|
|
954
|
+
loadJSONLDB();
|
|
955
|
+
const db = new JSONLDB(`${rootDir}tmp/${appName}-data/states.jsonl`);
|
|
956
|
+
await db.open();
|
|
957
|
+
|
|
958
|
+
db.set(id, state);
|
|
959
|
+
|
|
960
|
+
await db.close();
|
|
961
|
+
} else {
|
|
962
|
+
console.error(`setAdapterConfig: No objects file found in datadir ${rootDir}tmp/${appName}-data/`);
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
// Read config of the adapter
|
|
967
|
+
async function getOfflineState(id) {
|
|
968
|
+
if (fs.existsSync(`${rootDir}tmp/${appName}-data/states.json`)) {
|
|
969
|
+
const states = JSON.parse(fs.readFileSync(`${rootDir}tmp/${appName}-data/states.json`).toString());
|
|
970
|
+
return states[id];
|
|
971
|
+
} else if (fs.existsSync(`${rootDir}tmp/${appName}-data/states.jsonl`)) {
|
|
972
|
+
loadJSONLDB();
|
|
973
|
+
const db = new JSONLDB(`${rootDir}tmp/${appName}-data/states.jsonl`);
|
|
974
|
+
await db.open();
|
|
975
|
+
|
|
976
|
+
const state = db.get(id);
|
|
977
|
+
|
|
978
|
+
await db.close();
|
|
979
|
+
return state;
|
|
980
|
+
} else {
|
|
981
|
+
console.error(`getAdapterConfig: No objects file found in datadir ${rootDir}tmp/${appName}-data/`);
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
|
|
947
985
|
if (typeof module !== undefined && module.parent) {
|
|
948
986
|
module.exports.getAdapterConfig = getAdapterConfig;
|
|
949
987
|
module.exports.setAdapterConfig = setAdapterConfig;
|
|
@@ -958,4 +996,6 @@ if (typeof module !== undefined && module.parent) {
|
|
|
958
996
|
module.exports.adapterStarted = adapterStarted;
|
|
959
997
|
module.exports.getSecret = getSecret;
|
|
960
998
|
module.exports.encrypt = encrypt;
|
|
999
|
+
module.exports.setOfflineState = setOfflineState;
|
|
1000
|
+
module.exports.getOfflineState = getOfflineState;
|
|
961
1001
|
}
|