@iobroker/testing 4.1.3 → 5.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/LICENSE +1 -1
- package/README.md +2 -2
- package/build/index.d.ts +1 -1
- package/build/lib/adapterTools.d.ts +7 -2
- package/build/lib/adapterTools.js +47 -31
- package/build/lib/executeCommand.d.ts +3 -3
- package/build/lib/executeCommand.js +32 -32
- package/build/lib/str2regex.js +5 -6
- package/build/lib/testAdapter.d.ts +1 -0
- package/build/lib/testAdapter.js +1 -0
- package/build/tests/index.d.ts +9 -9
- package/build/tests/index.js +0 -1
- package/build/tests/integration/index.d.ts +1 -3
- package/build/tests/integration/index.js +46 -41
- package/build/tests/integration/lib/adapterSetup.d.ts +1 -1
- package/build/tests/integration/lib/adapterSetup.js +55 -42
- package/build/tests/integration/lib/controllerSetup.d.ts +1 -10
- package/build/tests/integration/lib/controllerSetup.js +59 -56
- package/build/tests/integration/lib/dbConnection.d.ts +12 -16
- package/build/tests/integration/lib/dbConnection.js +71 -69
- package/build/tests/integration/lib/harness.d.ts +9 -12
- package/build/tests/integration/lib/harness.js +70 -50
- package/build/tests/integration/lib/logger.d.ts +0 -1
- package/build/tests/integration/lib/logger.js +2 -4
- package/build/tests/integration/lib/tools.d.ts +6 -1
- package/build/tests/integration/lib/tools.js +32 -18
- package/build/tests/packageFiles/index.js +93 -77
- package/build/tests/unit/harness/createMocks.d.ts +3 -3
- package/build/tests/unit/harness/createMocks.js +1 -3
- package/build/tests/unit/index.js +6 -6
- package/build/tests/unit/mocks/mockAdapter.d.ts +3 -4
- package/build/tests/unit/mocks/mockAdapter.js +198 -164
- package/build/tests/unit/mocks/mockAdapterCore.d.ts +4 -10
- package/build/tests/unit/mocks/mockAdapterCore.js +24 -16
- package/build/tests/unit/mocks/mockDatabase.d.ts +13 -14
- package/build/tests/unit/mocks/mockDatabase.js +41 -45
- package/build/tests/unit/mocks/mockLogger.d.ts +1 -2
- package/build/tests/unit/mocks/mockLogger.js +2 -3
- package/build/tests/unit/mocks/tools.d.ts +2 -3
- package/build/tests/unit/mocks/tools.js +17 -15
- package/package.json +28 -32
|
@@ -15,25 +15,34 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.mockAdapterCore =
|
|
36
|
+
exports.mockAdapterCore = mockAdapterCore;
|
|
27
37
|
const os = __importStar(require("os"));
|
|
28
38
|
const path = __importStar(require("path"));
|
|
29
39
|
const mockAdapter_1 = require("./mockAdapter");
|
|
30
|
-
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
31
40
|
function mockAdapterCore(database, options = {}) {
|
|
32
41
|
/**
|
|
33
42
|
* The root directory of JS-Controller
|
|
34
43
|
* If this has to exist in the test, the user/tester has to take care of it!
|
|
35
44
|
*/
|
|
36
|
-
const controllerDir = path.join(options.adapterDir ||
|
|
45
|
+
const controllerDir = path.join(options.adapterDir || '', '..', 'iobroker.js-controller');
|
|
37
46
|
const dataDir = path.join(os.tmpdir(), `test-iobroker-data`);
|
|
38
47
|
/**
|
|
39
48
|
* The test location for iobroker-data
|
|
@@ -55,14 +64,14 @@ function mockAdapterCore(database, options = {}) {
|
|
|
55
64
|
}
|
|
56
65
|
const AdapterConstructor = function (nameOrOptions) {
|
|
57
66
|
// This needs to be a class with the correct `this` context or the ES6 tests won't work
|
|
58
|
-
if (!(this instanceof AdapterConstructor))
|
|
67
|
+
if (!(this instanceof AdapterConstructor)) {
|
|
59
68
|
return new AdapterConstructor(nameOrOptions);
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
: nameOrOptions;
|
|
69
|
+
}
|
|
70
|
+
const createAdapterMockOptions = typeof nameOrOptions === 'string' ? { name: nameOrOptions } : nameOrOptions;
|
|
63
71
|
mockAdapter_1.createAdapterMock.bind(this)(database, createAdapterMockOptions);
|
|
64
|
-
if (typeof options.onAdapterCreated ===
|
|
72
|
+
if (typeof options.onAdapterCreated === 'function') {
|
|
65
73
|
options.onAdapterCreated(this);
|
|
74
|
+
}
|
|
66
75
|
return this;
|
|
67
76
|
};
|
|
68
77
|
return {
|
|
@@ -74,4 +83,3 @@ function mockAdapterCore(database, options = {}) {
|
|
|
74
83
|
getAbsoluteInstanceDataDir,
|
|
75
84
|
};
|
|
76
85
|
}
|
|
77
|
-
exports.mockAdapterCore = mockAdapterCore;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
/// <reference types="iobroker" />
|
|
3
|
-
import type { MockAdapter } from "./mockAdapter";
|
|
1
|
+
import type { MockAdapter } from './mockAdapter';
|
|
4
2
|
/**
|
|
5
3
|
* A minimalistic version of ioBroker's Objects and States DB that just operates on a Map
|
|
6
4
|
*/
|
|
@@ -35,19 +33,20 @@ export declare class MockDatabase {
|
|
|
35
33
|
/**
|
|
36
34
|
* Returns a collection of predefined assertions to be used in unit tests
|
|
37
35
|
* Those include assertions for:
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
36
|
+
* - State exists
|
|
37
|
+
* - State has a certain value, ack flag, object property
|
|
38
|
+
* - Object exists
|
|
39
|
+
* - Object has a certain common or native part
|
|
40
|
+
*
|
|
42
41
|
* @param db The mock database to operate on
|
|
43
42
|
* @param adapter The mock adapter to operate on
|
|
44
43
|
*/
|
|
45
44
|
export declare function createAsserts(db: MockDatabase, adapter: MockAdapter): {
|
|
46
|
-
assertObjectExists(id: string | string[])
|
|
47
|
-
assertStateExists(id: string | string[])
|
|
48
|
-
assertStateHasValue(id: string | string[], value: any)
|
|
49
|
-
assertStateIsAcked(id: string | string[], ack
|
|
50
|
-
assertStateProperty(id: string | string[], property: string, value: any)
|
|
51
|
-
assertObjectCommon(id: string | string[], common: ioBroker.ObjectCommon)
|
|
52
|
-
assertObjectNative(id: string | string[], native: Record<string, any>)
|
|
45
|
+
assertObjectExists: (id: string | string[]) => void;
|
|
46
|
+
assertStateExists: (id: string | string[]) => void;
|
|
47
|
+
assertStateHasValue: (id: string | string[], value: any) => void;
|
|
48
|
+
assertStateIsAcked: (id: string | string[], ack: boolean) => void;
|
|
49
|
+
assertStateProperty: (id: string | string[], property: string, value: any) => void;
|
|
50
|
+
assertObjectCommon: (id: string | string[], common: ioBroker.ObjectCommon) => void;
|
|
51
|
+
assertObjectNative: (id: string | string[], native: Record<string, any>) => void;
|
|
53
52
|
};
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.MockDatabase = void 0;
|
|
4
|
+
exports.createAsserts = createAsserts;
|
|
5
|
+
// @ts-expect-error no types
|
|
4
6
|
const objects_1 = require("alcalzone-shared/objects");
|
|
5
|
-
const typeguards_1 = require("alcalzone-shared/typeguards");
|
|
6
7
|
const str2regex_1 = require("../../../lib/str2regex");
|
|
7
8
|
const objectTemplate = Object.freeze({
|
|
8
|
-
type:
|
|
9
|
-
common: { name:
|
|
9
|
+
type: 'state',
|
|
10
|
+
common: { name: 'an object' },
|
|
10
11
|
native: {},
|
|
11
12
|
});
|
|
12
13
|
const stateTemplate = Object.freeze({
|
|
@@ -32,10 +33,12 @@ class MockDatabase {
|
|
|
32
33
|
this.clearStates();
|
|
33
34
|
}
|
|
34
35
|
publishObject(obj) {
|
|
35
|
-
if (obj._id == null)
|
|
36
|
-
throw new Error(
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
if (obj._id == null) {
|
|
37
|
+
throw new Error('An object must have an ID');
|
|
38
|
+
}
|
|
39
|
+
if (obj.type == null) {
|
|
40
|
+
throw new Error('An object must have a type');
|
|
41
|
+
}
|
|
39
42
|
const completeObject = (0, objects_1.extend)({}, objectTemplate, obj);
|
|
40
43
|
this.objects.set(obj._id, completeObject);
|
|
41
44
|
}
|
|
@@ -43,22 +46,16 @@ class MockDatabase {
|
|
|
43
46
|
objects.forEach(this.publishObject.bind(this));
|
|
44
47
|
}
|
|
45
48
|
publishStateObjects(...objects) {
|
|
46
|
-
objects
|
|
47
|
-
.map((obj) => (0, objects_1.extend)({}, obj, { type: "state" }))
|
|
48
|
-
.forEach(this.publishObject.bind(this));
|
|
49
|
+
objects.map(obj => (0, objects_1.extend)({}, obj, { type: 'state' })).forEach(this.publishObject.bind(this));
|
|
49
50
|
}
|
|
50
51
|
publishChannelObjects(...objects) {
|
|
51
|
-
objects
|
|
52
|
-
.map((obj) => (0, objects_1.extend)({}, obj, { type: "channel" }))
|
|
53
|
-
.forEach(this.publishObject.bind(this));
|
|
52
|
+
objects.map(obj => (0, objects_1.extend)({}, obj, { type: 'channel' })).forEach(this.publishObject.bind(this));
|
|
54
53
|
}
|
|
55
54
|
publishDeviceObjects(...objects) {
|
|
56
|
-
objects
|
|
57
|
-
.map((obj) => (0, objects_1.extend)({}, obj, { type: "device" }))
|
|
58
|
-
.forEach(this.publishObject.bind(this));
|
|
55
|
+
objects.map(obj => (0, objects_1.extend)({}, obj, { type: 'device' })).forEach(this.publishObject.bind(this));
|
|
59
56
|
}
|
|
60
57
|
deleteObject(objOrID) {
|
|
61
|
-
this.objects.delete(typeof objOrID ===
|
|
58
|
+
this.objects.delete(typeof objOrID === 'string' ? objOrID : objOrID._id);
|
|
62
59
|
}
|
|
63
60
|
publishState(id, state) {
|
|
64
61
|
// if (typeof id !== "string") throw new Error("The id must be given!");
|
|
@@ -78,37 +75,38 @@ class MockDatabase {
|
|
|
78
75
|
}
|
|
79
76
|
}
|
|
80
77
|
hasObject(namespaceOrId, id) {
|
|
81
|
-
id = namespaceOrId + (id ?
|
|
78
|
+
id = namespaceOrId + (id ? `.${id}` : '');
|
|
82
79
|
return this.objects.has(id);
|
|
83
80
|
}
|
|
84
81
|
getObject(namespaceOrId, id) {
|
|
85
82
|
// combines getObject and getForeignObject into one
|
|
86
|
-
id = namespaceOrId + (id ?
|
|
83
|
+
id = namespaceOrId + (id ? `.${id}` : '');
|
|
87
84
|
return this.objects.get(id);
|
|
88
85
|
}
|
|
89
86
|
hasState(namespaceOrId, id) {
|
|
90
|
-
id = namespaceOrId + (id ?
|
|
87
|
+
id = namespaceOrId + (id ? `.${id}` : '');
|
|
91
88
|
return this.states.has(id);
|
|
92
89
|
}
|
|
93
90
|
getState(namespaceOrId, id) {
|
|
94
91
|
// combines getObject and getForeignObject into one
|
|
95
|
-
id = namespaceOrId + (id ?
|
|
92
|
+
id = namespaceOrId + (id ? `.${id}` : '');
|
|
96
93
|
return this.states.get(id);
|
|
97
94
|
}
|
|
98
|
-
getObjects(namespaceOrPattern,
|
|
95
|
+
getObjects(namespaceOrPattern,
|
|
96
|
+
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
|
|
97
|
+
patternOrType, type) {
|
|
99
98
|
// combines getObjects and getForeignObjects into one
|
|
100
99
|
let pattern;
|
|
101
100
|
if (type != null) {
|
|
102
|
-
pattern =
|
|
103
|
-
namespaceOrPattern + (patternOrType ? "." + patternOrType : "");
|
|
101
|
+
pattern = namespaceOrPattern + (patternOrType ? `.${patternOrType}` : '');
|
|
104
102
|
}
|
|
105
103
|
else if (patternOrType != null) {
|
|
106
|
-
if ([
|
|
104
|
+
if (['state', 'channel', 'device'].indexOf(patternOrType) > -1) {
|
|
107
105
|
type = patternOrType;
|
|
108
106
|
pattern = namespaceOrPattern;
|
|
109
107
|
}
|
|
110
108
|
else {
|
|
111
|
-
pattern = namespaceOrPattern
|
|
109
|
+
pattern = `${namespaceOrPattern}.${patternOrType}`;
|
|
112
110
|
}
|
|
113
111
|
}
|
|
114
112
|
else {
|
|
@@ -129,21 +127,22 @@ exports.MockDatabase = MockDatabase;
|
|
|
129
127
|
/**
|
|
130
128
|
* Returns a collection of predefined assertions to be used in unit tests
|
|
131
129
|
* Those include assertions for:
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
130
|
+
* - State exists
|
|
131
|
+
* - State has a certain value, ack flag, object property
|
|
132
|
+
* - Object exists
|
|
133
|
+
* - Object has a certain common or native part
|
|
134
|
+
*
|
|
136
135
|
* @param db The mock database to operate on
|
|
137
136
|
* @param adapter The mock adapter to operate on
|
|
138
137
|
*/
|
|
139
|
-
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
140
138
|
function createAsserts(db, adapter) {
|
|
141
139
|
function normalizeID(id) {
|
|
142
|
-
if (
|
|
143
|
-
id = id.join(
|
|
140
|
+
if (Array.isArray(id)) {
|
|
141
|
+
id = id.join('.');
|
|
142
|
+
}
|
|
144
143
|
// Test if this ID is fully qualified
|
|
145
144
|
if (!/^[a-z0-9\-_]+\.\d+\./.test(id)) {
|
|
146
|
-
id = adapter.namespace
|
|
145
|
+
id = `${adapter.namespace}.${id}`;
|
|
147
146
|
}
|
|
148
147
|
return id;
|
|
149
148
|
}
|
|
@@ -157,33 +156,30 @@ function createAsserts(db, adapter) {
|
|
|
157
156
|
db.hasState(id).should.equal(true, `The state "${adapter.namespace}.${id}" does not exist but it was expected to!`);
|
|
158
157
|
},
|
|
159
158
|
assertStateHasValue(id, value) {
|
|
160
|
-
ret.assertStateProperty(id,
|
|
159
|
+
ret.assertStateProperty(id, 'val', value);
|
|
161
160
|
},
|
|
162
161
|
assertStateIsAcked(id, ack = true) {
|
|
163
|
-
ret.assertStateProperty(id,
|
|
162
|
+
ret.assertStateProperty(id, 'ack', ack);
|
|
164
163
|
},
|
|
165
164
|
assertStateProperty(id, property, value) {
|
|
166
165
|
id = normalizeID(id);
|
|
167
166
|
ret.assertStateExists(id);
|
|
168
|
-
db.getState(id)
|
|
169
|
-
.should.be.an("object")
|
|
170
|
-
.that.has.property(property, value);
|
|
167
|
+
db.getState(id).should.be.an('object').that.has.property(property, value);
|
|
171
168
|
},
|
|
172
169
|
assertObjectCommon(id, common) {
|
|
173
170
|
id = normalizeID(id);
|
|
174
171
|
ret.assertObjectExists(id);
|
|
175
172
|
const dbObj = db.getObject(id);
|
|
176
|
-
dbObj.should.be.an(
|
|
177
|
-
dbObj.common.should.be.an(
|
|
173
|
+
dbObj.should.be.an('object').that.has.property('common');
|
|
174
|
+
dbObj.common.should.be.an('object').that.nested.include(common);
|
|
178
175
|
},
|
|
179
176
|
assertObjectNative(id, native) {
|
|
180
177
|
id = normalizeID(id);
|
|
181
178
|
ret.assertObjectExists(id);
|
|
182
179
|
const dbObj = db.getObject(id);
|
|
183
|
-
dbObj.should.be.an(
|
|
184
|
-
dbObj.native.should.be.an(
|
|
180
|
+
dbObj.should.be.an('object').that.has.property('native');
|
|
181
|
+
dbObj.native.should.be.an('object').that.nested.include(native);
|
|
185
182
|
},
|
|
186
183
|
};
|
|
187
184
|
return ret;
|
|
188
185
|
}
|
|
189
|
-
exports.createAsserts = createAsserts;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createLoggerMock =
|
|
3
|
+
exports.createLoggerMock = createLoggerMock;
|
|
4
4
|
const sinon_1 = require("sinon");
|
|
5
5
|
const tools_1 = require("./tools");
|
|
6
6
|
// Define here which methods were implemented manually, so we can hook them up with a real stub
|
|
@@ -16,7 +16,7 @@ function createLoggerMock() {
|
|
|
16
16
|
error: (0, sinon_1.stub)(),
|
|
17
17
|
debug: (0, sinon_1.stub)(),
|
|
18
18
|
silly: (0, sinon_1.stub)(),
|
|
19
|
-
level:
|
|
19
|
+
level: 'info',
|
|
20
20
|
// Mock-specific methods
|
|
21
21
|
resetMockHistory() {
|
|
22
22
|
// reset Logger
|
|
@@ -34,4 +34,3 @@ function createLoggerMock() {
|
|
|
34
34
|
(0, tools_1.stubAndPromisifyImplementedMethods)(ret, implementedMethods);
|
|
35
35
|
return ret;
|
|
36
36
|
}
|
|
37
|
-
exports.createLoggerMock = createLoggerMock;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import type { Equals, Overwrite } from "alcalzone-shared/types";
|
|
1
|
+
import type { Equals, Overwrite } from 'alcalzone-shared/types';
|
|
3
2
|
export type IsAny<T> = Equals<T extends never ? false : true, boolean>;
|
|
4
3
|
export type MockableMethods<T, All = Required<T>, NoAny = {
|
|
5
4
|
[K in keyof All]: IsAny<All[K]> extends true ? never : All[K] extends (...args: any[]) => void ? K : never;
|
|
@@ -10,4 +9,4 @@ export type Mock<T extends {}> = Overwrite<T, {
|
|
|
10
9
|
export declare function doResetHistory(parent: Record<string, any>): void;
|
|
11
10
|
export declare function doResetBehavior(parent: Record<string, any>, implementedMethods: Record<string, any>): void;
|
|
12
11
|
export declare function stubAndPromisifyImplementedMethods<T extends string>(parent: Record<T, any>, implementedMethods: Partial<Record<T, any>>, allowUserOverrides?: T[]): void;
|
|
13
|
-
export type ImplementedMethodDictionary<T> = Partial<Record<MockableMethods<T>,
|
|
12
|
+
export type ImplementedMethodDictionary<T> = Partial<Record<MockableMethods<T>, 'none' | 'normal' | 'no error'>>;
|
|
@@ -1,57 +1,59 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.doResetHistory = doResetHistory;
|
|
4
|
+
exports.doResetBehavior = doResetBehavior;
|
|
5
|
+
exports.stubAndPromisifyImplementedMethods = stubAndPromisifyImplementedMethods;
|
|
4
6
|
const async_1 = require("alcalzone-shared/async");
|
|
5
7
|
const sinon_1 = require("sinon");
|
|
6
8
|
function doResetHistory(parent) {
|
|
7
9
|
for (const prop of Object.keys(parent)) {
|
|
8
10
|
const val = parent[prop];
|
|
9
|
-
if (val && typeof val.resetHistory ===
|
|
11
|
+
if (val && typeof val.resetHistory === 'function') {
|
|
10
12
|
val.resetHistory();
|
|
13
|
+
}
|
|
11
14
|
}
|
|
12
15
|
}
|
|
13
|
-
exports.doResetHistory = doResetHistory;
|
|
14
16
|
function doResetBehavior(parent, implementedMethods) {
|
|
15
17
|
for (const prop of Object.keys(parent)) {
|
|
16
|
-
if (prop in implementedMethods ||
|
|
17
|
-
(prop.endsWith("Async") && prop.slice(0, -5) in implementedMethods))
|
|
18
|
+
if (prop in implementedMethods || (prop.endsWith('Async') && prop.slice(0, -5) in implementedMethods)) {
|
|
18
19
|
continue;
|
|
20
|
+
}
|
|
19
21
|
const val = parent[prop];
|
|
20
|
-
if (val && typeof val.resetBehavior ===
|
|
22
|
+
if (val && typeof val.resetBehavior === 'function') {
|
|
21
23
|
val.resetBehavior();
|
|
24
|
+
}
|
|
22
25
|
}
|
|
23
26
|
}
|
|
24
|
-
exports.doResetBehavior = doResetBehavior;
|
|
25
27
|
function dontOverwriteThis() {
|
|
26
|
-
throw new Error(
|
|
28
|
+
throw new Error('You must not overwrite the behavior of this stub!');
|
|
27
29
|
}
|
|
28
30
|
function stubAndPromisifyImplementedMethods(parent, implementedMethods, allowUserOverrides = []) {
|
|
29
31
|
// The methods implemented above are no stubs, but we claimed they are
|
|
30
32
|
// Therefore hook them up with a real stub
|
|
31
33
|
for (const methodName of Object.keys(implementedMethods)) {
|
|
32
|
-
if (methodName.endsWith(
|
|
34
|
+
if (methodName.endsWith('Async')) {
|
|
33
35
|
continue;
|
|
36
|
+
}
|
|
34
37
|
const originalMethod = parent[methodName];
|
|
35
38
|
const callbackFake = (parent[methodName] = (0, sinon_1.stub)());
|
|
36
39
|
callbackFake.callsFake(originalMethod);
|
|
37
40
|
// Prevent the user from changing the stub's behavior
|
|
38
|
-
if (allowUserOverrides.
|
|
41
|
+
if (!allowUserOverrides.includes(methodName)) {
|
|
39
42
|
callbackFake.returns = dontOverwriteThis;
|
|
40
43
|
callbackFake.callsFake = dontOverwriteThis;
|
|
41
44
|
}
|
|
42
45
|
// Construct the async fake if there's any
|
|
43
46
|
const asyncType = implementedMethods[methodName];
|
|
44
|
-
if (asyncType ===
|
|
47
|
+
if (asyncType === 'none') {
|
|
45
48
|
continue;
|
|
46
|
-
|
|
49
|
+
}
|
|
50
|
+
const promisifyMethod = asyncType === 'no error' ? async_1.promisifyNoError : async_1.promisify;
|
|
47
51
|
const asyncFake = (0, sinon_1.stub)().callsFake(promisifyMethod(originalMethod, parent));
|
|
48
52
|
parent[`${methodName}Async`] = asyncFake;
|
|
49
53
|
// Prevent the user from changing the stub's behavior
|
|
50
|
-
if (allowUserOverrides.
|
|
51
|
-
allowUserOverrides.indexOf((methodName + "Async")) === -1) {
|
|
54
|
+
if (!allowUserOverrides.includes(methodName) || !allowUserOverrides.includes(`${methodName}Async`)) {
|
|
52
55
|
asyncFake.returns = dontOverwriteThis;
|
|
53
56
|
asyncFake.callsFake = dontOverwriteThis;
|
|
54
57
|
}
|
|
55
58
|
}
|
|
56
59
|
}
|
|
57
|
-
exports.stubAndPromisifyImplementedMethods = stubAndPromisifyImplementedMethods;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iobroker/testing",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.2",
|
|
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",
|
|
@@ -15,9 +15,10 @@
|
|
|
15
15
|
"prewatch": "rimraf ./build",
|
|
16
16
|
"watch": "tsc -p tsconfig.build.json --watch",
|
|
17
17
|
"check": "npm run build -- --noEmit",
|
|
18
|
-
"lint:ts": "eslint
|
|
18
|
+
"lint:ts": "eslint -c eslint.config.mjs",
|
|
19
19
|
"lint": "npm run lint:ts",
|
|
20
|
-
"release": "release-script"
|
|
20
|
+
"release": "release-script",
|
|
21
|
+
"update-packages": "npx -y npm-check-updates --upgrade"
|
|
21
22
|
},
|
|
22
23
|
"repository": {
|
|
23
24
|
"type": "git",
|
|
@@ -38,38 +39,33 @@
|
|
|
38
39
|
},
|
|
39
40
|
"homepage": "https://github.com/AlCalzone/testing#readme",
|
|
40
41
|
"devDependencies": {
|
|
41
|
-
"@alcalzone/release-script": "^3.
|
|
42
|
-
"@alcalzone/release-script-plugin-license": "^3.
|
|
43
|
-
"@iobroker/adapter-core": "^2.
|
|
44
|
-
"@
|
|
45
|
-
"@types
|
|
46
|
-
"@
|
|
47
|
-
"@types/
|
|
48
|
-
"@types/
|
|
49
|
-
"@types/
|
|
50
|
-
"@types/
|
|
51
|
-
"@types/
|
|
52
|
-
"@types/
|
|
53
|
-
"@types/sinon
|
|
54
|
-
"@
|
|
55
|
-
"
|
|
56
|
-
"eslint": "^8.44.0",
|
|
57
|
-
"eslint-config-prettier": "^8.8.0",
|
|
58
|
-
"eslint-plugin-prettier": "^4.2.1",
|
|
59
|
-
"prettier": "^2.8.8",
|
|
60
|
-
"rimraf": "^3.0.2",
|
|
42
|
+
"@alcalzone/release-script": "^3.8.0",
|
|
43
|
+
"@alcalzone/release-script-plugin-license": "^3.7.0",
|
|
44
|
+
"@iobroker/adapter-core": "^3.2.3",
|
|
45
|
+
"@iobroker/eslint-config": "^1.0.0",
|
|
46
|
+
"@iobroker/types": "^7.0.6",
|
|
47
|
+
"@tsconfig/node16": "^16.1.3",
|
|
48
|
+
"@types/chai": "^4.3.20",
|
|
49
|
+
"@types/chai-as-promised": "^8.0.1",
|
|
50
|
+
"@types/debug": "4.1.12",
|
|
51
|
+
"@types/fs-extra": "^11.0.4",
|
|
52
|
+
"@types/mocha": "^10.0.10",
|
|
53
|
+
"@types/node": "^22.10.7",
|
|
54
|
+
"@types/sinon": "^17.0.3",
|
|
55
|
+
"@types/sinon-chai": "^3.2.12",
|
|
56
|
+
"rimraf": "^6.0.1",
|
|
61
57
|
"source-map-support": "^0.5.21",
|
|
62
|
-
"ts-node": "^10.9.
|
|
63
|
-
"typescript": "~
|
|
58
|
+
"ts-node": "^10.9.2",
|
|
59
|
+
"typescript": "~5.7.3"
|
|
64
60
|
},
|
|
65
61
|
"dependencies": {
|
|
66
|
-
"alcalzone-shared": "~
|
|
67
|
-
"chai": "^4.
|
|
68
|
-
"chai-as-promised": "^7.1.
|
|
69
|
-
"debug": "^4.
|
|
70
|
-
"fs-extra": "^
|
|
71
|
-
"mocha": "^
|
|
72
|
-
"sinon": "^
|
|
62
|
+
"alcalzone-shared": "~5.0.0",
|
|
63
|
+
"chai": "^4.5.0",
|
|
64
|
+
"chai-as-promised": "^7.1.2",
|
|
65
|
+
"debug": "^4.4.0",
|
|
66
|
+
"fs-extra": "^11.3.0",
|
|
67
|
+
"mocha": "^11.0.1",
|
|
68
|
+
"sinon": "^19.0.2",
|
|
73
69
|
"sinon-chai": "^3.7.0"
|
|
74
70
|
}
|
|
75
71
|
}
|