@iobroker/testing 2.5.0 → 2.5.4
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 +10 -1
- package/LICENSE +1 -1
- package/build/lib/adapterTools.js +27 -38
- package/build/lib/executeCommand.js +3 -4
- package/build/tests/index.js +1 -0
- package/build/tests/integration/index.js +59 -76
- package/build/tests/integration/lib/adapterSetup.d.ts +4 -5
- package/build/tests/integration/lib/adapterSetup.js +81 -97
- package/build/tests/integration/lib/controllerSetup.d.ts +4 -7
- package/build/tests/integration/lib/controllerSetup.js +90 -105
- package/build/tests/integration/lib/dbConnection.d.ts +46 -22
- package/build/tests/integration/lib/dbConnection.js +259 -65
- package/build/tests/integration/lib/harness.d.ts +6 -11
- package/build/tests/integration/lib/harness.js +107 -192
- package/build/tests/integration/lib/tools.js +1 -1
- package/build/tests/packageFiles/index.js +32 -26
- package/build/tests/unit/index.js +2 -11
- package/build/tests/unit/mocks/mockAdapter.d.ts +1 -1
- package/build/tests/unit/mocks/mockAdapter.js +17 -18
- package/build/tests/unit/mocks/mockAdapterCore.d.ts +1 -1
- package/build/tests/unit/mocks/mockDatabase.d.ts +2 -2
- package/build/tests/unit/mocks/mockDatabase.js +10 -10
- package/build/tests/unit/mocks/mockLogger.js +8 -8
- package/build/tests/unit/mocks/tools.d.ts +1 -1
- package/build/tests/unit/mocks/tools.js +2 -2
- package/package.json +27 -25
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createAdapterMock = void 0;
|
|
4
|
-
/* eslint-disable @typescript-eslint/camelcase */
|
|
5
4
|
const objects_1 = require("alcalzone-shared/objects");
|
|
6
5
|
const sinon_1 = require("sinon");
|
|
7
6
|
const mockLogger_1 = require("./mockLogger");
|
|
@@ -100,11 +99,11 @@ function createAdapterMock(db, options = {}) {
|
|
|
100
99
|
adapterDir: "",
|
|
101
100
|
ioPack: {},
|
|
102
101
|
pack: {},
|
|
103
|
-
log: mockLogger_1.createLoggerMock(),
|
|
102
|
+
log: (0, mockLogger_1.createLoggerMock)(),
|
|
104
103
|
version: "any",
|
|
105
104
|
connected: true,
|
|
106
105
|
getPort: asyncEnabledStub,
|
|
107
|
-
stop: sinon_1.stub(),
|
|
106
|
+
stop: (0, sinon_1.stub)(),
|
|
108
107
|
checkPassword: asyncEnabledStub,
|
|
109
108
|
setPassword: asyncEnabledStub,
|
|
110
109
|
checkGroup: asyncEnabledStub,
|
|
@@ -112,7 +111,7 @@ function createAdapterMock(db, options = {}) {
|
|
|
112
111
|
getCertificates: asyncEnabledStub,
|
|
113
112
|
sendTo: asyncEnabledStub,
|
|
114
113
|
sendToHost: asyncEnabledStub,
|
|
115
|
-
idToDCS: sinon_1.stub(),
|
|
114
|
+
idToDCS: (0, sinon_1.stub)(),
|
|
116
115
|
getObject: ((id, ...args) => {
|
|
117
116
|
if (!id.startsWith(ret.namespace))
|
|
118
117
|
id = ret.namespace + "." + id;
|
|
@@ -150,7 +149,7 @@ function createAdapterMock(db, options = {}) {
|
|
|
150
149
|
}
|
|
151
150
|
const callback = getCallback(...args);
|
|
152
151
|
if (typeof callback === "function") {
|
|
153
|
-
let objects = objects_1.values(db.getObjects("*"));
|
|
152
|
+
let objects = (0, objects_1.values)(db.getObjects("*"));
|
|
154
153
|
objects = objects.filter((obj) => obj.type === search);
|
|
155
154
|
if (startkey)
|
|
156
155
|
objects = objects.filter((obj) => obj._id >= startkey);
|
|
@@ -167,7 +166,7 @@ function createAdapterMock(db, options = {}) {
|
|
|
167
166
|
getObjectList: (({ startkey, endkey, include_docs, }, ...args) => {
|
|
168
167
|
const callback = getCallback(...args);
|
|
169
168
|
if (typeof callback === "function") {
|
|
170
|
-
let objects = objects_1.values(db.getObjects("*"));
|
|
169
|
+
let objects = (0, objects_1.values)(db.getObjects("*"));
|
|
171
170
|
if (startkey)
|
|
172
171
|
objects = objects.filter((obj) => obj._id >= startkey);
|
|
173
172
|
if (endkey)
|
|
@@ -187,7 +186,7 @@ function createAdapterMock(db, options = {}) {
|
|
|
187
186
|
if (!id.startsWith(ret.namespace))
|
|
188
187
|
id = ret.namespace + "." + id;
|
|
189
188
|
const existing = db.getObject(id) || {};
|
|
190
|
-
const target = objects_1.extend({}, existing, obj);
|
|
189
|
+
const target = (0, objects_1.extend)({}, existing, obj);
|
|
191
190
|
target._id = id;
|
|
192
191
|
db.publishObject(target);
|
|
193
192
|
const callback = getCallback(...args);
|
|
@@ -241,7 +240,7 @@ function createAdapterMock(db, options = {}) {
|
|
|
241
240
|
if (callback)
|
|
242
241
|
callback(null, { id: target._id, value: target }, id);
|
|
243
242
|
}),
|
|
244
|
-
findForeignObject: sinon_1.stub(),
|
|
243
|
+
findForeignObject: (0, sinon_1.stub)(),
|
|
245
244
|
delForeignObject: ((id, ...args) => {
|
|
246
245
|
db.deleteObject(id);
|
|
247
246
|
const callback = getCallback(...args);
|
|
@@ -374,7 +373,7 @@ function createAdapterMock(db, options = {}) {
|
|
|
374
373
|
createState: asyncEnabledStub,
|
|
375
374
|
deleteState: asyncEnabledStub,
|
|
376
375
|
getDevices: asyncEnabledStub,
|
|
377
|
-
getChannels: sinon_1.stub(),
|
|
376
|
+
getChannels: (0, sinon_1.stub)(),
|
|
378
377
|
getChannelsOf: asyncEnabledStub,
|
|
379
378
|
getStatesOf: asyncEnabledStub,
|
|
380
379
|
readDir: asyncEnabledStub,
|
|
@@ -385,8 +384,8 @@ function createAdapterMock(db, options = {}) {
|
|
|
385
384
|
unlink: asyncEnabledStub,
|
|
386
385
|
rename: asyncEnabledStub,
|
|
387
386
|
chmodFile: asyncEnabledStub,
|
|
388
|
-
formatValue: sinon_1.stub(),
|
|
389
|
-
formatDate: sinon_1.stub(),
|
|
387
|
+
formatValue: (0, sinon_1.stub)(),
|
|
388
|
+
formatDate: (0, sinon_1.stub)(),
|
|
390
389
|
terminate: ((reason, exitCode) => {
|
|
391
390
|
if (typeof reason === "number") {
|
|
392
391
|
// Only the exit code was passed
|
|
@@ -396,13 +395,13 @@ function createAdapterMock(db, options = {}) {
|
|
|
396
395
|
const errorMessage = `Adapter.terminate was called${typeof exitCode === "number" ? ` (exit code ${exitCode})` : ""}: ${reason ? reason : "Without reason"}`;
|
|
397
396
|
// Terminates execution by
|
|
398
397
|
const err = new Error(errorMessage);
|
|
399
|
-
// @ts-
|
|
398
|
+
// @ts-expect-error I'm too lazy to add terminateReason to the error type
|
|
400
399
|
err.terminateReason = reason || "no reason given!";
|
|
401
400
|
throw err;
|
|
402
401
|
}),
|
|
403
|
-
supportsFeature: sinon_1.stub(),
|
|
404
|
-
getPluginInstance: sinon_1.stub(),
|
|
405
|
-
getPluginConfig: sinon_1.stub(),
|
|
402
|
+
supportsFeature: (0, sinon_1.stub)(),
|
|
403
|
+
getPluginInstance: (0, sinon_1.stub)(),
|
|
404
|
+
getPluginConfig: (0, sinon_1.stub)(),
|
|
406
405
|
// EventEmitter methods
|
|
407
406
|
on: ((event, handler) => {
|
|
408
407
|
// Remember the event handlers so we can call them on demand
|
|
@@ -467,12 +466,12 @@ function createAdapterMock(db, options = {}) {
|
|
|
467
466
|
// Mock-specific methods
|
|
468
467
|
resetMockHistory() {
|
|
469
468
|
// reset Adapter
|
|
470
|
-
tools_1.doResetHistory(ret);
|
|
469
|
+
(0, tools_1.doResetHistory)(ret);
|
|
471
470
|
ret.log.resetMockHistory();
|
|
472
471
|
},
|
|
473
472
|
resetMockBehavior() {
|
|
474
473
|
// reset Adapter
|
|
475
|
-
tools_1.doResetBehavior(ret, implementedMethods);
|
|
474
|
+
(0, tools_1.doResetBehavior)(ret, implementedMethods);
|
|
476
475
|
ret.log.resetMockBehavior();
|
|
477
476
|
},
|
|
478
477
|
resetMock() {
|
|
@@ -480,7 +479,7 @@ function createAdapterMock(db, options = {}) {
|
|
|
480
479
|
ret.resetMockBehavior();
|
|
481
480
|
},
|
|
482
481
|
});
|
|
483
|
-
tools_1.stubAndPromisifyImplementedMethods(ret, implementedMethods, [
|
|
482
|
+
(0, tools_1.stubAndPromisifyImplementedMethods)(ret, implementedMethods, [
|
|
484
483
|
"getObjectView",
|
|
485
484
|
"getObjectList",
|
|
486
485
|
]);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="iobroker" />
|
|
2
2
|
import { MockAdapter } from "./mockAdapter";
|
|
3
|
-
import { MockDatabase } from "./mockDatabase";
|
|
3
|
+
import type { MockDatabase } from "./mockDatabase";
|
|
4
4
|
interface MockAdapterConstructor {
|
|
5
5
|
new (nameOrOptions: string | ioBroker.AdapterOptions): MockAdapter;
|
|
6
6
|
(nameOrOptions: string | ioBroker.AdapterOptions): MockAdapter;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="iobroker" />
|
|
2
|
-
import { MockAdapter } from "./mockAdapter";
|
|
2
|
+
import type { MockAdapter } from "./mockAdapter";
|
|
3
3
|
/**
|
|
4
4
|
* A minimalistic version of ioBroker's Objects and States DB that just operates on a Map
|
|
5
5
|
*/
|
|
@@ -48,5 +48,5 @@ export declare function createAsserts(db: MockDatabase, adapter: MockAdapter): {
|
|
|
48
48
|
assertStateIsAcked(id: string | string[], ack?: boolean): void;
|
|
49
49
|
assertStateProperty(id: string | string[], property: string, value: any): void;
|
|
50
50
|
assertObjectCommon(id: string | string[], common: ioBroker.ObjectCommon): void;
|
|
51
|
-
assertObjectNative(id: string | string[], native:
|
|
51
|
+
assertObjectNative(id: string | string[], native: Record<string, any>): void;
|
|
52
52
|
};
|
|
@@ -36,7 +36,7 @@ class MockDatabase {
|
|
|
36
36
|
throw new Error("An object must have an ID");
|
|
37
37
|
if (obj.type == null)
|
|
38
38
|
throw new Error("An object must have a type");
|
|
39
|
-
const completeObject = objects_1.extend({}, objectTemplate, obj);
|
|
39
|
+
const completeObject = (0, objects_1.extend)({}, objectTemplate, obj);
|
|
40
40
|
this.objects.set(obj._id, completeObject);
|
|
41
41
|
}
|
|
42
42
|
publishObjects(...objects) {
|
|
@@ -44,17 +44,17 @@ class MockDatabase {
|
|
|
44
44
|
}
|
|
45
45
|
publishStateObjects(...objects) {
|
|
46
46
|
objects
|
|
47
|
-
.map((obj) => objects_1.extend({}, obj, { type: "state" }))
|
|
47
|
+
.map((obj) => (0, objects_1.extend)({}, obj, { type: "state" }))
|
|
48
48
|
.forEach(this.publishObject.bind(this));
|
|
49
49
|
}
|
|
50
50
|
publishChannelObjects(...objects) {
|
|
51
51
|
objects
|
|
52
|
-
.map((obj) => objects_1.extend({}, obj, { type: "channel" }))
|
|
52
|
+
.map((obj) => (0, objects_1.extend)({}, obj, { type: "channel" }))
|
|
53
53
|
.forEach(this.publishObject.bind(this));
|
|
54
54
|
}
|
|
55
55
|
publishDeviceObjects(...objects) {
|
|
56
56
|
objects
|
|
57
|
-
.map((obj) => objects_1.extend({}, obj, { type: "device" }))
|
|
57
|
+
.map((obj) => (0, objects_1.extend)({}, obj, { type: "device" }))
|
|
58
58
|
.forEach(this.publishObject.bind(this));
|
|
59
59
|
}
|
|
60
60
|
deleteObject(objOrID) {
|
|
@@ -66,7 +66,7 @@ class MockDatabase {
|
|
|
66
66
|
this.deleteState(id);
|
|
67
67
|
return;
|
|
68
68
|
}
|
|
69
|
-
const completeState = objects_1.extend({}, stateTemplate, state);
|
|
69
|
+
const completeState = (0, objects_1.extend)({}, stateTemplate, state);
|
|
70
70
|
this.states.set(id, completeState);
|
|
71
71
|
}
|
|
72
72
|
deleteState(id) {
|
|
@@ -114,15 +114,15 @@ class MockDatabase {
|
|
|
114
114
|
else {
|
|
115
115
|
pattern = namespaceOrPattern;
|
|
116
116
|
}
|
|
117
|
-
const idRegExp = str2regex_1.str2regex(pattern);
|
|
118
|
-
return objects_1.composeObject([...this.objects.entries()]
|
|
117
|
+
const idRegExp = (0, str2regex_1.str2regex)(pattern);
|
|
118
|
+
return (0, objects_1.composeObject)([...this.objects.entries()]
|
|
119
119
|
.filter(([id]) => idRegExp.test(id))
|
|
120
120
|
.filter(([, obj]) => type == null || obj.type === type));
|
|
121
121
|
}
|
|
122
122
|
getStates(pattern) {
|
|
123
123
|
// combines getStates and getForeignStates into one
|
|
124
|
-
const idRegExp = str2regex_1.str2regex(pattern);
|
|
125
|
-
return objects_1.composeObject([...this.states.entries()].filter(([id]) => idRegExp.test(id)));
|
|
124
|
+
const idRegExp = (0, str2regex_1.str2regex)(pattern);
|
|
125
|
+
return (0, objects_1.composeObject)([...this.states.entries()].filter(([id]) => idRegExp.test(id)));
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
exports.MockDatabase = MockDatabase;
|
|
@@ -139,7 +139,7 @@ exports.MockDatabase = MockDatabase;
|
|
|
139
139
|
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
140
140
|
function createAsserts(db, adapter) {
|
|
141
141
|
function normalizeID(id) {
|
|
142
|
-
if (typeguards_1.isArray(id))
|
|
142
|
+
if ((0, typeguards_1.isArray)(id))
|
|
143
143
|
id = id.join(".");
|
|
144
144
|
// Test if this ID is fully qualified
|
|
145
145
|
if (!/^[a-z0-9\-_]+\.\d+\./.test(id)) {
|
|
@@ -11,27 +11,27 @@ const implementedMethods = {};
|
|
|
11
11
|
*/
|
|
12
12
|
function createLoggerMock() {
|
|
13
13
|
const ret = {
|
|
14
|
-
info: sinon_1.stub(),
|
|
15
|
-
warn: sinon_1.stub(),
|
|
16
|
-
error: sinon_1.stub(),
|
|
17
|
-
debug: sinon_1.stub(),
|
|
18
|
-
silly: sinon_1.stub(),
|
|
14
|
+
info: (0, sinon_1.stub)(),
|
|
15
|
+
warn: (0, sinon_1.stub)(),
|
|
16
|
+
error: (0, sinon_1.stub)(),
|
|
17
|
+
debug: (0, sinon_1.stub)(),
|
|
18
|
+
silly: (0, sinon_1.stub)(),
|
|
19
19
|
level: "info",
|
|
20
20
|
// Mock-specific methods
|
|
21
21
|
resetMockHistory() {
|
|
22
22
|
// reset Logger
|
|
23
|
-
tools_1.doResetHistory(ret);
|
|
23
|
+
(0, tools_1.doResetHistory)(ret);
|
|
24
24
|
},
|
|
25
25
|
resetMockBehavior() {
|
|
26
26
|
// reset Logger
|
|
27
|
-
tools_1.doResetBehavior(ret, implementedMethods);
|
|
27
|
+
(0, tools_1.doResetBehavior)(ret, implementedMethods);
|
|
28
28
|
},
|
|
29
29
|
resetMock() {
|
|
30
30
|
ret.resetMockHistory();
|
|
31
31
|
ret.resetMockBehavior();
|
|
32
32
|
},
|
|
33
33
|
};
|
|
34
|
-
tools_1.stubAndPromisifyImplementedMethods(ret, implementedMethods);
|
|
34
|
+
(0, tools_1.stubAndPromisifyImplementedMethods)(ret, implementedMethods);
|
|
35
35
|
return ret;
|
|
36
36
|
}
|
|
37
37
|
exports.createLoggerMock = createLoggerMock;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="sinon" />
|
|
2
|
-
import { Equals, Overwrite } from "alcalzone-shared/types";
|
|
2
|
+
import type { Equals, Overwrite } from "alcalzone-shared/types";
|
|
3
3
|
export declare type IsAny<T> = Equals<T extends never ? false : true, boolean>;
|
|
4
4
|
export declare type MockableMethods<T, All = Required<T>, NoAny = {
|
|
5
5
|
[K in keyof All]: IsAny<All[K]> extends true ? never : All[K] extends (...args: any[]) => void ? K : never;
|
|
@@ -32,7 +32,7 @@ function stubAndPromisifyImplementedMethods(parent, implementedMethods, allowUse
|
|
|
32
32
|
if (methodName.endsWith("Async"))
|
|
33
33
|
continue;
|
|
34
34
|
const originalMethod = parent[methodName];
|
|
35
|
-
const callbackFake = (parent[methodName] = sinon_1.stub());
|
|
35
|
+
const callbackFake = (parent[methodName] = (0, sinon_1.stub)());
|
|
36
36
|
callbackFake.callsFake(originalMethod);
|
|
37
37
|
// Prevent the user from changing the stub's behavior
|
|
38
38
|
if (allowUserOverrides.indexOf(methodName) === -1) {
|
|
@@ -44,7 +44,7 @@ function stubAndPromisifyImplementedMethods(parent, implementedMethods, allowUse
|
|
|
44
44
|
if (asyncType === "none")
|
|
45
45
|
continue;
|
|
46
46
|
const promisifyMethod = asyncType === "no error" ? async_1.promisifyNoError : async_1.promisify;
|
|
47
|
-
const asyncFake = sinon_1.stub().callsFake(promisifyMethod(originalMethod, parent));
|
|
47
|
+
const asyncFake = (0, sinon_1.stub)().callsFake(promisifyMethod(originalMethod, parent));
|
|
48
48
|
parent[`${methodName}Async`] = asyncFake;
|
|
49
49
|
// Prevent the user from changing the stub's behavior
|
|
50
50
|
if (allowUserOverrides.indexOf(methodName) === -1 ||
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iobroker/testing",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.4",
|
|
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,36 +38,38 @@
|
|
|
38
38
|
},
|
|
39
39
|
"homepage": "https://github.com/AlCalzone/testing#readme",
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@alcalzone/release-script": "^
|
|
42
|
-
"@
|
|
43
|
-
"@
|
|
44
|
-
"@
|
|
45
|
-
"@types/
|
|
46
|
-
"@types/
|
|
47
|
-
"@types/
|
|
41
|
+
"@alcalzone/release-script": "^3.5.0",
|
|
42
|
+
"@alcalzone/release-script-plugin-license": "^3.5.0",
|
|
43
|
+
"@iobroker/adapter-core": "^2.5.1",
|
|
44
|
+
"@tsconfig/node12": "^1.0.9",
|
|
45
|
+
"@types/chai": "^4.3.0",
|
|
46
|
+
"@types/chai-as-promised": "^7.1.4",
|
|
47
|
+
"@types/debug": "4.1.7",
|
|
48
|
+
"@types/fs-extra": "^9.0.13",
|
|
49
|
+
"@types/iobroker": "^3.3.4",
|
|
48
50
|
"@types/mocha": "^9.0.0",
|
|
49
|
-
"@types/node": "^16.
|
|
50
|
-
"@types/sinon": "^10.0.
|
|
51
|
-
"@types/sinon-chai": "^3.2.
|
|
52
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
53
|
-
"@typescript-eslint/parser": "^
|
|
54
|
-
"eslint": "^
|
|
55
|
-
"eslint-config-prettier": "^
|
|
56
|
-
"eslint-plugin-prettier": "^
|
|
57
|
-
"prettier": "^2.
|
|
51
|
+
"@types/node": "^16.10.2",
|
|
52
|
+
"@types/sinon": "^10.0.6",
|
|
53
|
+
"@types/sinon-chai": "^3.2.8",
|
|
54
|
+
"@typescript-eslint/eslint-plugin": "^4.33.0",
|
|
55
|
+
"@typescript-eslint/parser": "^4.33.0",
|
|
56
|
+
"eslint": "^7.32.0",
|
|
57
|
+
"eslint-config-prettier": "^8.3.0",
|
|
58
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
59
|
+
"prettier": "^2.5.1",
|
|
58
60
|
"rimraf": "^3.0.2",
|
|
59
|
-
"source-map-support": "^0.5.
|
|
60
|
-
"ts-node": "^10.2.
|
|
61
|
-
"typescript": "
|
|
61
|
+
"source-map-support": "^0.5.21",
|
|
62
|
+
"ts-node": "^10.2.1",
|
|
63
|
+
"typescript": "~4.5.5"
|
|
62
64
|
},
|
|
63
65
|
"dependencies": {
|
|
64
|
-
"alcalzone-shared": "~4.0.
|
|
66
|
+
"alcalzone-shared": "~4.0.1",
|
|
65
67
|
"chai": "^4.3.4",
|
|
66
68
|
"chai-as-promised": "^7.1.1",
|
|
67
|
-
"debug": "^4.3.
|
|
68
|
-
"fs-extra": "^
|
|
69
|
-
"mocha": "^9.1.
|
|
70
|
-
"sinon": "^
|
|
69
|
+
"debug": "^4.3.3",
|
|
70
|
+
"fs-extra": "^10.0.0",
|
|
71
|
+
"mocha": "^9.1.3",
|
|
72
|
+
"sinon": "^12.0.1",
|
|
71
73
|
"sinon-chai": "^3.7.0"
|
|
72
74
|
}
|
|
73
75
|
}
|