@iobroker/testing 2.5.6 → 2.6.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/CHANGELOG.md +3 -0
- package/build/tests/integration/index.d.ts +3 -0
- package/build/tests/integration/index.js +7 -4
- package/build/tests/integration/lib/dbConnection.d.ts +2 -1
- package/build/tests/integration/lib/dbConnection.js +4 -11
- package/build/tests/integration/lib/logger.d.ts +2 -0
- package/build/tests/integration/lib/logger.js +26 -0
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,9 @@
|
|
|
4
4
|
PLACEHOLDER for next version:
|
|
5
5
|
## __WORK IN PROGRESS__
|
|
6
6
|
-->
|
|
7
|
+
## 2.6.0 (2022-04-18)
|
|
8
|
+
* The loglevel for the adapter and DB instances is now configurable and defaults to `"debug"` in both cases
|
|
9
|
+
|
|
7
10
|
## 2.5.6 (2022-03-05)
|
|
8
11
|
* Allow immediate exit with code `0` for `once` and `subscribe` adapters too
|
|
9
12
|
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
/// <reference types="iobroker" />
|
|
1
2
|
import { TestHarness } from "./lib/harness";
|
|
2
3
|
export interface TestAdapterOptions {
|
|
3
4
|
allowedExitCodes?: (number | string)[];
|
|
5
|
+
/** The loglevel to use for DB and adapter related logs */
|
|
6
|
+
loglevel?: ioBroker.LogLevel;
|
|
4
7
|
/** How long to wait before the adapter startup is considered successful */
|
|
5
8
|
waitBeforeStartupSuccess?: number;
|
|
6
9
|
/** Allows you to define additional tests */
|
|
@@ -32,6 +32,7 @@ const adapterSetup_1 = require("./lib/adapterSetup");
|
|
|
32
32
|
const controllerSetup_1 = require("./lib/controllerSetup");
|
|
33
33
|
const dbConnection_1 = require("./lib/dbConnection");
|
|
34
34
|
const harness_1 = require("./lib/harness");
|
|
35
|
+
const logger_1 = require("./lib/logger");
|
|
35
36
|
function testAdapter(adapterDir, options = {}) {
|
|
36
37
|
const appName = (0, adapterTools_1.getAppName)(adapterDir);
|
|
37
38
|
const adapterName = (0, adapterTools_1.getAdapterName)(adapterDir);
|
|
@@ -47,6 +48,7 @@ function testAdapter(adapterDir, options = {}) {
|
|
|
47
48
|
let objectsBackup;
|
|
48
49
|
let statesBackup;
|
|
49
50
|
before(async function () {
|
|
51
|
+
var _a;
|
|
50
52
|
// Installation may take a while - especially if rsa-compat needs to be installed
|
|
51
53
|
const oneMinute = 60000;
|
|
52
54
|
this.timeout(30 * oneMinute);
|
|
@@ -61,7 +63,7 @@ function testAdapter(adapterDir, options = {}) {
|
|
|
61
63
|
// Only then we can install the adapter, because some (including VIS) try to access
|
|
62
64
|
// the databases if JS Controller is installed
|
|
63
65
|
await adapterSetup.installAdapterInTestDir();
|
|
64
|
-
const dbConnection = new dbConnection_1.DBConnection(appName, testDir);
|
|
66
|
+
const dbConnection = new dbConnection_1.DBConnection(appName, testDir, (0, logger_1.createLogger)((_a = options.loglevel) !== null && _a !== void 0 ? _a : "debug"));
|
|
65
67
|
await dbConnection.start();
|
|
66
68
|
controllerSetup.setupSystemConfig(dbConnection);
|
|
67
69
|
await controllerSetup.disableAdminInstances(dbConnection);
|
|
@@ -73,8 +75,9 @@ function testAdapter(adapterDir, options = {}) {
|
|
|
73
75
|
await dbConnection.backup());
|
|
74
76
|
});
|
|
75
77
|
beforeEach(async function () {
|
|
78
|
+
var _a, _b;
|
|
76
79
|
this.timeout(30000);
|
|
77
|
-
dbConnection = new dbConnection_1.DBConnection(appName, testDir);
|
|
80
|
+
dbConnection = new dbConnection_1.DBConnection(appName, testDir, (0, logger_1.createLogger)((_a = options.loglevel) !== null && _a !== void 0 ? _a : "debug"));
|
|
78
81
|
// Clean up before every single test
|
|
79
82
|
await Promise.all([
|
|
80
83
|
controllerSetup.clearDBDir(),
|
|
@@ -84,11 +87,11 @@ function testAdapter(adapterDir, options = {}) {
|
|
|
84
87
|
// Create a new test harness
|
|
85
88
|
await dbConnection.start();
|
|
86
89
|
harness = new harness_1.TestHarness(adapterDir, testDir, dbConnection);
|
|
87
|
-
// Enable the adapter and set its loglevel to
|
|
90
|
+
// Enable the adapter and set its loglevel to the selected one
|
|
88
91
|
await harness.changeAdapterConfig(adapterName, {
|
|
89
92
|
common: {
|
|
90
93
|
enabled: true,
|
|
91
|
-
loglevel: "debug",
|
|
94
|
+
loglevel: (_b = options.loglevel) !== null && _b !== void 0 ? _b : "debug",
|
|
92
95
|
},
|
|
93
96
|
});
|
|
94
97
|
// And enable the sendTo emulation
|
|
@@ -11,11 +11,12 @@ export interface DBConnection {
|
|
|
11
11
|
export declare class DBConnection extends EventEmitter {
|
|
12
12
|
private appName;
|
|
13
13
|
private testDir;
|
|
14
|
+
private logger;
|
|
14
15
|
/**
|
|
15
16
|
* @param appName The branded name of "iobroker"
|
|
16
17
|
* @param testDir The directory the integration tests are executed in
|
|
17
18
|
*/
|
|
18
|
-
constructor(appName: string, testDir: string);
|
|
19
|
+
constructor(appName: string, testDir: string, logger: ioBroker.Logger);
|
|
19
20
|
private testDataDir;
|
|
20
21
|
private testControllerDir;
|
|
21
22
|
private _objectsServer;
|
|
@@ -33,24 +33,17 @@ const fs_extra_1 = require("fs-extra");
|
|
|
33
33
|
const path = __importStar(require("path"));
|
|
34
34
|
const tools_1 = require("./tools");
|
|
35
35
|
const debug = (0, debug_1.default)("testing:integration:DBConnection");
|
|
36
|
-
/** The logger instance for the objects and states DB */
|
|
37
|
-
const logger = {
|
|
38
|
-
silly: console.log,
|
|
39
|
-
debug: console.log,
|
|
40
|
-
info: console.log,
|
|
41
|
-
warn: console.warn,
|
|
42
|
-
error: console.error,
|
|
43
|
-
};
|
|
44
36
|
/** The DB connection capsules access to the states and objects DB */
|
|
45
37
|
class DBConnection extends events_1.default {
|
|
46
38
|
/**
|
|
47
39
|
* @param appName The branded name of "iobroker"
|
|
48
40
|
* @param testDir The directory the integration tests are executed in
|
|
49
41
|
*/
|
|
50
|
-
constructor(appName, testDir) {
|
|
42
|
+
constructor(appName, testDir, logger) {
|
|
51
43
|
super();
|
|
52
44
|
this.appName = appName;
|
|
53
45
|
this.testDir = testDir;
|
|
46
|
+
this.logger = logger;
|
|
54
47
|
this._isRunning = false;
|
|
55
48
|
this.getObject = async (id) => {
|
|
56
49
|
if (!this._objectsClient) {
|
|
@@ -192,7 +185,7 @@ class DBConnection extends events_1.default {
|
|
|
192
185
|
noFileCache: false,
|
|
193
186
|
connectTimeout: 2000,
|
|
194
187
|
},
|
|
195
|
-
logger,
|
|
188
|
+
logger: this.logger,
|
|
196
189
|
};
|
|
197
190
|
const objectsDbPath = require.resolve(`@iobroker/db-objects-${objectsType}`, {
|
|
198
191
|
paths: [
|
|
@@ -240,7 +233,7 @@ class DBConnection extends events_1.default {
|
|
|
240
233
|
retry_max_delay: 15000,
|
|
241
234
|
},
|
|
242
235
|
},
|
|
243
|
-
logger,
|
|
236
|
+
logger: this.logger,
|
|
244
237
|
};
|
|
245
238
|
const statesDbPath = require.resolve(`@iobroker/db-states-${statesType}`, {
|
|
246
239
|
paths: [
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createLogger = void 0;
|
|
4
|
+
var LoglevelOrder;
|
|
5
|
+
(function (LoglevelOrder) {
|
|
6
|
+
LoglevelOrder[LoglevelOrder["error"] = 0] = "error";
|
|
7
|
+
LoglevelOrder[LoglevelOrder["warn"] = 1] = "warn";
|
|
8
|
+
LoglevelOrder[LoglevelOrder["info"] = 2] = "info";
|
|
9
|
+
LoglevelOrder[LoglevelOrder["debug"] = 3] = "debug";
|
|
10
|
+
LoglevelOrder[LoglevelOrder["silly"] = 4] = "silly";
|
|
11
|
+
})(LoglevelOrder || (LoglevelOrder = {}));
|
|
12
|
+
function createLogger(loglevel) {
|
|
13
|
+
var _a;
|
|
14
|
+
const loglevelNumeric = (_a = LoglevelOrder[loglevel !== null && loglevel !== void 0 ? loglevel : "debug"]) !== null && _a !== void 0 ? _a : LoglevelOrder.debug;
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
16
|
+
const ignore = () => { };
|
|
17
|
+
return {
|
|
18
|
+
error: loglevelNumeric >= LoglevelOrder.error ? console.error : ignore,
|
|
19
|
+
warn: loglevelNumeric >= LoglevelOrder.warn ? console.warn : ignore,
|
|
20
|
+
info: loglevelNumeric >= LoglevelOrder.info ? console.log : ignore,
|
|
21
|
+
debug: loglevelNumeric >= LoglevelOrder.debug ? console.log : ignore,
|
|
22
|
+
silly: loglevelNumeric >= LoglevelOrder.silly ? console.log : ignore,
|
|
23
|
+
level: loglevel,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
exports.createLogger = createLogger;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iobroker/testing",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.0",
|
|
4
4
|
"description": "Shared utilities for adapter and module testing in ioBroker",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
},
|
|
39
39
|
"homepage": "https://github.com/AlCalzone/testing#readme",
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@alcalzone/release-script": "^3.5.
|
|
41
|
+
"@alcalzone/release-script": "^3.5.6",
|
|
42
42
|
"@alcalzone/release-script-plugin-license": "^3.5.3",
|
|
43
43
|
"@iobroker/adapter-core": "^2.6.0",
|
|
44
44
|
"@tsconfig/node12": "^1.0.9",
|
|
@@ -51,12 +51,12 @@
|
|
|
51
51
|
"@types/node": "^16.11.26",
|
|
52
52
|
"@types/sinon": "^10.0.11",
|
|
53
53
|
"@types/sinon-chai": "^3.2.8",
|
|
54
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
54
|
+
"@typescript-eslint/eslint-plugin": "^5.17.0",
|
|
55
55
|
"@typescript-eslint/parser": "^5.13.0",
|
|
56
|
-
"eslint": "^8.
|
|
56
|
+
"eslint": "^8.12.0",
|
|
57
57
|
"eslint-config-prettier": "^8.5.0",
|
|
58
58
|
"eslint-plugin-prettier": "^4.0.0",
|
|
59
|
-
"prettier": "^2.
|
|
59
|
+
"prettier": "^2.6.1",
|
|
60
60
|
"rimraf": "^3.0.2",
|
|
61
61
|
"source-map-support": "^0.5.21",
|
|
62
62
|
"ts-node": "^10.6.0",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"chai-as-promised": "^7.1.1",
|
|
69
69
|
"debug": "^4.3.3",
|
|
70
70
|
"fs-extra": "^10.0.1",
|
|
71
|
-
"mocha": "^9.2.
|
|
71
|
+
"mocha": "^9.2.2",
|
|
72
72
|
"sinon": "^13.0.1",
|
|
73
73
|
"sinon-chai": "^3.7.0"
|
|
74
74
|
}
|