@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.
Files changed (41) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +2 -2
  3. package/build/index.d.ts +1 -1
  4. package/build/lib/adapterTools.d.ts +7 -2
  5. package/build/lib/adapterTools.js +47 -31
  6. package/build/lib/executeCommand.d.ts +3 -3
  7. package/build/lib/executeCommand.js +32 -32
  8. package/build/lib/str2regex.js +5 -6
  9. package/build/lib/testAdapter.d.ts +1 -0
  10. package/build/lib/testAdapter.js +1 -0
  11. package/build/tests/index.d.ts +9 -9
  12. package/build/tests/index.js +0 -1
  13. package/build/tests/integration/index.d.ts +1 -3
  14. package/build/tests/integration/index.js +46 -41
  15. package/build/tests/integration/lib/adapterSetup.d.ts +1 -1
  16. package/build/tests/integration/lib/adapterSetup.js +55 -42
  17. package/build/tests/integration/lib/controllerSetup.d.ts +1 -10
  18. package/build/tests/integration/lib/controllerSetup.js +59 -56
  19. package/build/tests/integration/lib/dbConnection.d.ts +12 -16
  20. package/build/tests/integration/lib/dbConnection.js +71 -69
  21. package/build/tests/integration/lib/harness.d.ts +9 -12
  22. package/build/tests/integration/lib/harness.js +70 -50
  23. package/build/tests/integration/lib/logger.d.ts +0 -1
  24. package/build/tests/integration/lib/logger.js +2 -4
  25. package/build/tests/integration/lib/tools.d.ts +6 -1
  26. package/build/tests/integration/lib/tools.js +32 -18
  27. package/build/tests/packageFiles/index.js +93 -77
  28. package/build/tests/unit/harness/createMocks.d.ts +3 -3
  29. package/build/tests/unit/harness/createMocks.js +1 -3
  30. package/build/tests/unit/index.js +6 -6
  31. package/build/tests/unit/mocks/mockAdapter.d.ts +3 -4
  32. package/build/tests/unit/mocks/mockAdapter.js +198 -164
  33. package/build/tests/unit/mocks/mockAdapterCore.d.ts +4 -10
  34. package/build/tests/unit/mocks/mockAdapterCore.js +24 -16
  35. package/build/tests/unit/mocks/mockDatabase.d.ts +13 -14
  36. package/build/tests/unit/mocks/mockDatabase.js +41 -45
  37. package/build/tests/unit/mocks/mockLogger.d.ts +1 -2
  38. package/build/tests/unit/mocks/mockLogger.js +2 -3
  39. package/build/tests/unit/mocks/tools.d.ts +2 -3
  40. package/build/tests/unit/mocks/tools.js +17 -15
  41. package/package.json +28 -32
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createAdapterMock = void 0;
3
+ exports.createAdapterMock = createAdapterMock;
4
+ // @ts-expect-error no types
4
5
  const objects_1 = require("alcalzone-shared/objects");
5
6
  const sinon_1 = require("sinon");
6
7
  const mockLogger_1 = require("./mockLogger");
@@ -8,79 +9,82 @@ const tools_1 = require("./tools");
8
9
  // Define here which methods were implemented manually, so we can hook them up with a real stub
9
10
  // The value describes if and how the async version of the callback is constructed
10
11
  const implementedMethods = {
11
- getObject: "normal",
12
- setObject: "normal",
13
- setObjectNotExists: "normal",
14
- extendObject: "normal",
15
- getForeignObject: "normal",
16
- getForeignObjects: "normal",
17
- setForeignObject: "normal",
18
- setForeignObjectNotExists: "normal",
19
- extendForeignObject: "normal",
20
- getState: "normal",
21
- getStates: "normal",
22
- setState: "normal",
23
- setStateChanged: "normal",
24
- delState: "normal",
25
- getForeignState: "normal",
26
- setForeignState: "normal",
27
- setForeignStateChanged: "normal",
28
- subscribeStates: "normal",
29
- subscribeForeignStates: "normal",
30
- subscribeObjects: "normal",
31
- subscribeForeignObjects: "normal",
32
- getAdapterObjects: "no error",
33
- getObjectView: "normal",
34
- getObjectList: "normal",
35
- on: "none",
36
- removeListener: "none",
37
- removeAllListeners: "none",
38
- terminate: "none",
39
- getPort: "no error",
40
- checkPassword: "no error",
41
- setPassword: "normal",
42
- checkGroup: "no error",
43
- calculatePermissions: "no error",
44
- getCertificates: "normal",
45
- sendTo: "no error",
46
- sendToHost: "no error",
47
- getHistory: "normal",
48
- setBinaryState: "normal",
49
- getBinaryState: "normal",
50
- getEnum: "normal",
51
- getEnums: "normal",
52
- addChannelToEnum: "normal",
53
- deleteChannelFromEnum: "normal",
54
- addStateToEnum: "normal",
55
- deleteStateFromEnum: "normal",
56
- createDevice: "normal",
57
- deleteDevice: "normal",
58
- createChannel: "normal",
59
- deleteChannel: "normal",
60
- createState: "normal",
61
- deleteState: "normal",
62
- getDevices: "normal",
63
- getChannelsOf: "normal",
64
- getStatesOf: "normal",
65
- readDir: "normal",
66
- mkDir: "normal",
67
- readFile: "normal",
68
- writeFile: "normal",
69
- delFile: "normal",
70
- unlink: "normal",
71
- rename: "normal",
72
- chmodFile: "normal",
12
+ getObject: 'normal',
13
+ setObject: 'normal',
14
+ setObjectNotExists: 'normal',
15
+ extendObject: 'normal',
16
+ getForeignObject: 'normal',
17
+ getForeignObjects: 'normal',
18
+ setForeignObject: 'normal',
19
+ setForeignObjectNotExists: 'normal',
20
+ extendForeignObject: 'normal',
21
+ getState: 'normal',
22
+ getStates: 'normal',
23
+ setState: 'normal',
24
+ setStateChanged: 'normal',
25
+ delState: 'normal',
26
+ getForeignState: 'normal',
27
+ setForeignState: 'normal',
28
+ setForeignStateChanged: 'normal',
29
+ subscribeStates: 'normal',
30
+ subscribeForeignStates: 'normal',
31
+ subscribeObjects: 'normal',
32
+ subscribeForeignObjects: 'normal',
33
+ getAdapterObjects: 'no error',
34
+ getObjectView: 'normal',
35
+ getObjectList: 'normal',
36
+ on: 'none',
37
+ removeListener: 'none',
38
+ removeAllListeners: 'none',
39
+ terminate: 'none',
40
+ getPort: 'no error',
41
+ checkPassword: 'no error',
42
+ setPassword: 'normal',
43
+ checkGroup: 'no error',
44
+ calculatePermissions: 'no error',
45
+ getCertificates: 'normal',
46
+ sendTo: 'no error',
47
+ sendToHost: 'no error',
48
+ getHistory: 'normal',
49
+ // @ts-expect-error This method was deprecated
50
+ setBinaryState: 'normal',
51
+ getBinaryState: 'normal',
52
+ getEnum: 'normal',
53
+ getEnums: 'normal',
54
+ addChannelToEnum: 'normal',
55
+ deleteChannelFromEnum: 'normal',
56
+ addStateToEnum: 'normal',
57
+ deleteStateFromEnum: 'normal',
58
+ createDevice: 'normal',
59
+ deleteDevice: 'normal',
60
+ createChannel: 'normal',
61
+ deleteChannel: 'normal',
62
+ createState: 'normal',
63
+ deleteState: 'normal',
64
+ getDevices: 'normal',
65
+ getChannelsOf: 'normal',
66
+ getStatesOf: 'normal',
67
+ readDir: 'normal',
68
+ mkDir: 'normal',
69
+ readFile: 'normal',
70
+ writeFile: 'normal',
71
+ delFile: 'normal',
72
+ unlink: 'normal',
73
+ rename: 'normal',
74
+ chmodFile: 'normal',
73
75
  };
74
76
  function getCallback(...args) {
75
77
  const lastArg = args[args.length - 1];
76
- if (typeof lastArg === "function")
78
+ if (typeof lastArg === 'function') {
77
79
  return lastArg;
80
+ }
78
81
  }
79
82
  /** Stub implementation which can be promisified */
80
83
  const asyncEnabledStub = ((...args) => {
81
84
  const callback = getCallback(...args);
82
- if (typeof callback === "function")
85
+ if (typeof callback === 'function') {
83
86
  callback();
87
+ }
84
88
  });
85
89
  /**
86
90
  * Creates an adapter mock that is connected to a given database mock
@@ -89,18 +93,18 @@ function createAdapterMock(db, options = {}) {
89
93
  // In order to support ES6-style adapters with inheritance, we need to work on the instance directly
90
94
  const ret = this || {};
91
95
  Object.assign(ret, {
92
- name: options.name || "test",
93
- host: "testhost",
96
+ name: options.name || 'test',
97
+ host: 'testhost',
94
98
  instance: options.instance || 0,
95
- namespace: `${options.name || "test"}.${options.instance || 0}`,
99
+ namespace: `${options.name || 'test'}.${options.instance || 0}`,
96
100
  config: options.config || {},
97
101
  common: {},
98
102
  systemConfig: null,
99
- adapterDir: "",
103
+ adapterDir: '',
100
104
  ioPack: {},
101
105
  pack: {},
102
106
  log: (0, mockLogger_1.createLoggerMock)(),
103
- version: "any",
107
+ version: 'any',
104
108
  connected: true,
105
109
  getPort: asyncEnabledStub,
106
110
  stop: (0, sinon_1.stub)(),
@@ -113,28 +117,34 @@ function createAdapterMock(db, options = {}) {
113
117
  sendToHost: asyncEnabledStub,
114
118
  idToDCS: (0, sinon_1.stub)(),
115
119
  getObject: ((id, ...args) => {
116
- if (!id.startsWith(ret.namespace))
117
- id = ret.namespace + "." + id;
120
+ if (!id.startsWith(ret.namespace)) {
121
+ id = `${ret.namespace}.${id}`;
122
+ }
118
123
  const callback = getCallback(...args);
119
- if (callback)
124
+ if (callback) {
120
125
  callback(null, db.getObject(id));
126
+ }
121
127
  }),
122
128
  setObject: ((id, obj, ...args) => {
123
- if (!id.startsWith(ret.namespace))
124
- id = ret.namespace + "." + id;
129
+ if (!id.startsWith(ret.namespace)) {
130
+ id = `${ret.namespace}.${id}`;
131
+ }
125
132
  obj._id = id;
126
133
  db.publishObject(obj);
127
134
  const callback = getCallback(...args);
128
- if (callback)
135
+ if (callback) {
129
136
  callback(null, { id });
137
+ }
130
138
  }),
131
139
  setObjectNotExists: ((id, obj, ...args) => {
132
- if (!id.startsWith(ret.namespace))
133
- id = ret.namespace + "." + id;
140
+ if (!id.startsWith(ret.namespace)) {
141
+ id = `${ret.namespace}.${id}`;
142
+ }
134
143
  const callback = getCallback(...args);
135
144
  if (db.hasObject(id)) {
136
- if (callback)
145
+ if (callback) {
137
146
  callback(null, { id });
147
+ }
138
148
  }
139
149
  else {
140
150
  ret.setObject(id, obj, callback);
@@ -144,19 +154,21 @@ function createAdapterMock(db, options = {}) {
144
154
  callback(db.getObjects(`${ret.namespace}.*`));
145
155
  }),
146
156
  getObjectView: ((design, search, { startkey, endkey }, ...args) => {
147
- if (design !== "system") {
148
- throw new Error("If you want to use a custom design for getObjectView, you need to mock it yourself!");
157
+ if (design !== 'system') {
158
+ throw new Error('If you want to use a custom design for getObjectView, you need to mock it yourself!');
149
159
  }
150
160
  const callback = getCallback(...args);
151
- if (typeof callback === "function") {
152
- let objects = (0, objects_1.values)(db.getObjects("*"));
153
- objects = objects.filter((obj) => obj.type === search);
154
- if (startkey)
155
- objects = objects.filter((obj) => obj._id >= startkey);
156
- if (endkey)
157
- objects = objects.filter((obj) => obj._id <= endkey);
161
+ if (typeof callback === 'function') {
162
+ let objects = (0, objects_1.values)(db.getObjects('*'));
163
+ objects = objects.filter(obj => obj.type === search);
164
+ if (startkey) {
165
+ objects = objects.filter(obj => obj._id >= startkey);
166
+ }
167
+ if (endkey) {
168
+ objects = objects.filter(obj => obj._id <= endkey);
169
+ }
158
170
  callback(null, {
159
- rows: objects.map((obj) => ({
171
+ rows: objects.map(obj => ({
160
172
  id: obj._id,
161
173
  value: obj,
162
174
  })),
@@ -165,16 +177,19 @@ function createAdapterMock(db, options = {}) {
165
177
  }),
166
178
  getObjectList: (({ startkey, endkey, include_docs, }, ...args) => {
167
179
  const callback = getCallback(...args);
168
- if (typeof callback === "function") {
169
- let objects = (0, objects_1.values)(db.getObjects("*"));
170
- if (startkey)
171
- objects = objects.filter((obj) => obj._id >= startkey);
172
- if (endkey)
173
- objects = objects.filter((obj) => obj._id <= endkey);
174
- if (!include_docs)
175
- objects = objects.filter((obj) => !obj._id.startsWith("_"));
180
+ if (typeof callback === 'function') {
181
+ let objects = (0, objects_1.values)(db.getObjects('*'));
182
+ if (startkey) {
183
+ objects = objects.filter(obj => obj._id >= startkey);
184
+ }
185
+ if (endkey) {
186
+ objects = objects.filter(obj => obj._id <= endkey);
187
+ }
188
+ if (!include_docs) {
189
+ objects = objects.filter(obj => !obj._id.startsWith('_'));
190
+ }
176
191
  callback(null, {
177
- rows: objects.map((obj) => ({
192
+ rows: objects.map(obj => ({
178
193
  id: obj._id,
179
194
  value: obj,
180
195
  doc: obj,
@@ -183,49 +198,55 @@ function createAdapterMock(db, options = {}) {
183
198
  }
184
199
  }),
185
200
  extendObject: ((id, obj, ...args) => {
186
- if (!id.startsWith(ret.namespace))
187
- id = ret.namespace + "." + id;
201
+ if (!id.startsWith(ret.namespace)) {
202
+ id = `${ret.namespace}.${id}`;
203
+ }
188
204
  const existing = db.getObject(id) || {};
189
205
  const target = (0, objects_1.extend)({}, existing, obj);
190
206
  target._id = id;
191
207
  db.publishObject(target);
192
208
  const callback = getCallback(...args);
193
- if (callback)
209
+ if (callback) {
194
210
  callback(null, { id: target._id, value: target }, id);
211
+ }
195
212
  }),
196
213
  delObject: ((id, ...args) => {
197
- if (!id.startsWith(ret.namespace))
198
- id = ret.namespace + "." + id;
214
+ if (!id.startsWith(ret.namespace)) {
215
+ id = `${ret.namespace}.${id}`;
216
+ }
199
217
  db.deleteObject(id);
200
218
  const callback = getCallback(...args);
201
- if (callback)
219
+ if (callback) {
202
220
  callback(undefined);
221
+ }
203
222
  }),
204
223
  getForeignObject: ((id, ...args) => {
205
224
  const callback = getCallback(...args);
206
- if (callback)
225
+ if (callback) {
207
226
  callback(null, db.getObject(id));
227
+ }
208
228
  }),
209
229
  getForeignObjects: ((pattern, ...args) => {
210
- const type = typeof args[0] === "string"
211
- ? args[0]
212
- : undefined;
230
+ const type = typeof args[0] === 'string' ? args[0] : undefined;
213
231
  const callback = getCallback(...args);
214
- if (callback)
232
+ if (callback) {
215
233
  callback(null, db.getObjects(pattern, type));
234
+ }
216
235
  }),
217
236
  setForeignObject: ((id, obj, ...args) => {
218
237
  obj._id = id;
219
238
  db.publishObject(obj);
220
239
  const callback = getCallback(...args);
221
- if (callback)
240
+ if (callback) {
222
241
  callback(null, { id });
242
+ }
223
243
  }),
224
244
  setForeignObjectNotExists: ((id, obj, ...args) => {
225
245
  const callback = getCallback(...args);
226
246
  if (db.hasObject(id)) {
227
- if (callback)
247
+ if (callback) {
228
248
  callback(null, { id });
249
+ }
229
250
  }
230
251
  else {
231
252
  ret.setObject(id, obj, callback);
@@ -237,117 +258,134 @@ function createAdapterMock(db, options = {}) {
237
258
  target._id = id;
238
259
  db.publishObject(target);
239
260
  const callback = getCallback(...args);
240
- if (callback)
261
+ if (callback) {
241
262
  callback(null, { id: target._id, value: target }, id);
263
+ }
242
264
  }),
243
265
  findForeignObject: (0, sinon_1.stub)(),
244
266
  delForeignObject: ((id, ...args) => {
245
267
  db.deleteObject(id);
246
268
  const callback = getCallback(...args);
247
- if (callback)
269
+ if (callback) {
248
270
  callback(undefined);
271
+ }
249
272
  }),
250
273
  setState: ((id, state, ...args) => {
251
274
  const callback = getCallback(...args);
252
- if (!id.startsWith(ret.namespace))
253
- id = ret.namespace + "." + id;
275
+ if (!id.startsWith(ret.namespace)) {
276
+ id = `${ret.namespace}.${id}`;
277
+ }
254
278
  let ack;
255
- if (state != null && typeof state === "object") {
279
+ if (state != null && typeof state === 'object') {
256
280
  ack = !!state.ack;
257
281
  state = state.val;
258
282
  }
259
283
  else {
260
- ack = typeof args[0] === "boolean" ? args[0] : false;
284
+ ack = typeof args[0] === 'boolean' ? args[0] : false;
261
285
  }
262
286
  db.publishState(id, { val: state, ack });
263
- if (callback)
287
+ if (callback) {
264
288
  callback(null, id);
289
+ }
265
290
  }),
266
291
  setStateChanged: ((id, state, ...args) => {
267
292
  const callback = getCallback(...args);
268
293
  let ack;
269
- if (state != null && typeof state === "object") {
294
+ if (state != null && typeof state === 'object') {
270
295
  ack = !!state.ack;
271
296
  state = state.val;
272
297
  }
273
298
  else {
274
- ack = typeof args[0] === "boolean" ? args[0] : false;
299
+ ack = typeof args[0] === 'boolean' ? args[0] : false;
300
+ }
301
+ if (!id.startsWith(ret.namespace)) {
302
+ id = `${ret.namespace}.${id}`;
275
303
  }
276
- if (!id.startsWith(ret.namespace))
277
- id = ret.namespace + "." + id;
278
304
  if (!db.hasState(id) || db.getState(id).val !== state) {
279
305
  db.publishState(id, { val: state, ack });
280
306
  }
281
- if (callback)
307
+ if (callback) {
282
308
  callback(null, id);
309
+ }
283
310
  }),
284
311
  setForeignState: ((id, state, ...args) => {
285
312
  const callback = getCallback(...args);
286
313
  let ack;
287
- if (state != null && typeof state === "object") {
314
+ if (state != null && typeof state === 'object') {
288
315
  ack = !!state.ack;
289
316
  state = state.val;
290
317
  }
291
318
  else {
292
- ack = typeof args[0] === "boolean" ? args[0] : false;
319
+ ack = typeof args[0] === 'boolean' ? args[0] : false;
293
320
  }
294
321
  db.publishState(id, { val: state, ack });
295
- if (callback)
322
+ if (callback) {
296
323
  callback(null, id);
324
+ }
297
325
  }),
298
326
  setForeignStateChanged: ((id, state, ...args) => {
299
327
  const callback = getCallback(...args);
300
328
  let ack;
301
- if (state != null && typeof state === "object") {
329
+ if (state != null && typeof state === 'object') {
302
330
  ack = !!state.ack;
303
331
  state = state.val;
304
332
  }
305
333
  else {
306
- ack = typeof args[0] === "boolean" ? args[0] : false;
334
+ ack = typeof args[0] === 'boolean' ? args[0] : false;
307
335
  }
308
336
  if (!db.hasState(id) || db.getState(id).val !== state) {
309
337
  db.publishState(id, { val: state, ack });
310
338
  }
311
- if (callback)
339
+ if (callback) {
312
340
  callback(null, id);
341
+ }
313
342
  }),
314
343
  getState: ((id, ...args) => {
315
- if (!id.startsWith(ret.namespace))
316
- id = ret.namespace + "." + id;
344
+ if (!id.startsWith(ret.namespace)) {
345
+ id = `${ret.namespace}.${id}`;
346
+ }
317
347
  const callback = getCallback(...args);
318
- if (callback)
348
+ if (callback) {
319
349
  callback(null, db.getState(id));
350
+ }
320
351
  }),
321
352
  getForeignState: ((id, ...args) => {
322
353
  const callback = getCallback(...args);
323
- if (callback)
354
+ if (callback) {
324
355
  callback(null, db.getState(id));
356
+ }
325
357
  }),
326
358
  getStates: ((pattern, ...args) => {
327
- if (!pattern.startsWith(ret.namespace))
328
- pattern = ret.namespace + "." + pattern;
359
+ if (!pattern.startsWith(ret.namespace)) {
360
+ pattern = `${ret.namespace}.${pattern}`;
361
+ }
329
362
  const callback = getCallback(...args);
330
- if (callback)
363
+ if (callback) {
331
364
  callback(null, db.getStates(pattern));
365
+ }
332
366
  }),
333
367
  getForeignStates: ((pattern, ...args) => {
334
368
  const callback = getCallback(...args);
335
- if (callback)
369
+ if (callback) {
336
370
  callback(null, db.getStates(pattern));
371
+ }
337
372
  }),
338
373
  delState: ((id, ...args) => {
339
- if (!id.startsWith(ret.namespace))
340
- id = ret.namespace + "." + id;
374
+ if (!id.startsWith(ret.namespace)) {
375
+ id = `${ret.namespace}.${id}`;
376
+ }
341
377
  db.deleteState(id);
342
378
  const callback = getCallback(...args);
343
- if (callback)
379
+ if (callback) {
344
380
  callback(undefined);
381
+ }
345
382
  }),
346
383
  delForeignState: ((id, ...args) => {
347
384
  db.deleteState(id);
348
385
  const callback = getCallback(...args);
349
- if (callback)
386
+ if (callback) {
350
387
  callback(undefined);
388
+ }
351
389
  }),
352
390
  getHistory: asyncEnabledStub,
353
391
  setBinaryState: asyncEnabledStub,
@@ -387,16 +425,16 @@ function createAdapterMock(db, options = {}) {
387
425
  formatValue: (0, sinon_1.stub)(),
388
426
  formatDate: (0, sinon_1.stub)(),
389
427
  terminate: ((reason, exitCode) => {
390
- if (typeof reason === "number") {
428
+ if (typeof reason === 'number') {
391
429
  // Only the exit code was passed
392
430
  exitCode = reason;
393
431
  reason = undefined;
394
432
  }
395
- const errorMessage = `Adapter.terminate was called${typeof exitCode === "number" ? ` (exit code ${exitCode})` : ""}: ${reason ? reason : "Without reason"}`;
433
+ const errorMessage = `Adapter.terminate was called${typeof exitCode === 'number' ? ` (exit code ${exitCode})` : ''}: ${reason ? reason : 'Without reason'}`;
396
434
  // Terminates execution by
397
435
  const err = new Error(errorMessage);
398
436
  // @ts-expect-error I'm too lazy to add terminateReason to the error type
399
- err.terminateReason = reason || "no reason given!";
437
+ err.terminateReason = reason || 'no reason given!';
400
438
  throw err;
401
439
  }),
402
440
  supportsFeature: (0, sinon_1.stub)(),
@@ -406,19 +444,19 @@ function createAdapterMock(db, options = {}) {
406
444
  on: ((event, handler) => {
407
445
  // Remember the event handlers so we can call them on demand
408
446
  switch (event) {
409
- case "ready":
447
+ case 'ready':
410
448
  ret.readyHandler = handler;
411
449
  break;
412
- case "message":
450
+ case 'message':
413
451
  ret.messageHandler = handler;
414
452
  break;
415
- case "objectChange":
453
+ case 'objectChange':
416
454
  ret.objectChangeHandler = handler;
417
455
  break;
418
- case "stateChange":
456
+ case 'stateChange':
419
457
  ret.stateChangeHandler = handler;
420
458
  break;
421
- case "unload":
459
+ case 'unload':
422
460
  ret.unloadHandler = handler;
423
461
  break;
424
462
  }
@@ -427,38 +465,38 @@ function createAdapterMock(db, options = {}) {
427
465
  removeListener: ((event, _listener) => {
428
466
  // TODO This is not entirely correct
429
467
  switch (event) {
430
- case "ready":
468
+ case 'ready':
431
469
  ret.readyHandler = undefined;
432
470
  break;
433
- case "message":
471
+ case 'message':
434
472
  ret.messageHandler = undefined;
435
473
  break;
436
- case "objectChange":
474
+ case 'objectChange':
437
475
  ret.objectChangeHandler = undefined;
438
476
  break;
439
- case "stateChange":
477
+ case 'stateChange':
440
478
  ret.stateChangeHandler = undefined;
441
479
  break;
442
- case "unload":
480
+ case 'unload':
443
481
  ret.unloadHandler = undefined;
444
482
  break;
445
483
  }
446
484
  return ret;
447
485
  }),
448
486
  removeAllListeners: ((event) => {
449
- if (!event || event === "ready") {
487
+ if (!event || event === 'ready') {
450
488
  ret.readyHandler = undefined;
451
489
  }
452
- if (!event || event === "message") {
490
+ if (!event || event === 'message') {
453
491
  ret.messageHandler = undefined;
454
492
  }
455
- if (!event || event === "objectChange") {
493
+ if (!event || event === 'objectChange') {
456
494
  ret.objectChangeHandler = undefined;
457
495
  }
458
- if (!event || event === "stateChange") {
496
+ if (!event || event === 'stateChange') {
459
497
  ret.stateChangeHandler = undefined;
460
498
  }
461
- if (!event || event === "unload") {
499
+ if (!event || event === 'unload') {
462
500
  ret.unloadHandler = undefined;
463
501
  }
464
502
  return ret;
@@ -479,10 +517,7 @@ function createAdapterMock(db, options = {}) {
479
517
  ret.resetMockBehavior();
480
518
  },
481
519
  });
482
- (0, tools_1.stubAndPromisifyImplementedMethods)(ret, implementedMethods, [
483
- "getObjectView",
484
- "getObjectList",
485
- ]);
520
+ (0, tools_1.stubAndPromisifyImplementedMethods)(ret, implementedMethods, ['getObjectView', 'getObjectList']);
486
521
  // Access the options object directly, so we can react to later changes
487
522
  Object.defineProperties(ret, {
488
523
  readyHandler: {
@@ -528,4 +563,3 @@ function createAdapterMock(db, options = {}) {
528
563
  });
529
564
  return ret;
530
565
  }
531
- exports.createAdapterMock = createAdapterMock;
@@ -1,10 +1,5 @@
1
- /// <reference types="iobroker" />
2
- import { MockAdapter } from "./mockAdapter";
3
- import type { MockDatabase } from "./mockDatabase";
4
- interface MockAdapterConstructor {
5
- new (nameOrOptions: string | ioBroker.AdapterOptions): MockAdapter;
6
- (nameOrOptions: string | ioBroker.AdapterOptions): MockAdapter;
7
- }
1
+ import { type MockAdapter } from './mockAdapter';
2
+ import type { MockDatabase } from './mockDatabase';
8
3
  export interface MockAdapterCoreOptions {
9
4
  onAdapterCreated?: (adapter: MockAdapter) => void;
10
5
  adapterDir?: string;
@@ -12,9 +7,8 @@ export interface MockAdapterCoreOptions {
12
7
  export declare function mockAdapterCore(database: MockDatabase, options?: MockAdapterCoreOptions): {
13
8
  controllerDir: string;
14
9
  getConfig: () => Record<string, any>;
15
- Adapter: MockAdapterConstructor;
16
- adapter: MockAdapterConstructor;
10
+ Adapter: (this: MockAdapter | void, nameOrOptions: string | ioBroker.AdapterOptions) => MockAdapter;
11
+ adapter: (this: MockAdapter | void, nameOrOptions: string | ioBroker.AdapterOptions) => MockAdapter;
17
12
  getAbsoluteDefaultDataDir: () => string;
18
13
  getAbsoluteInstanceDataDir: (adapterObject: MockAdapter) => string;
19
14
  };
20
- export {};