@matterbridge/jest-utils 3.9.1-dev-20260614-89d7aeb → 3.9.1-dev-20260617-b1e1b99
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 +5 -3
- package/dist/jestMatterTest.d.ts +4 -8
- package/dist/jestMatterTest.js +22 -31
- package/dist/jestSetupTest.d.ts +1 -2
- package/dist/jestSetupTest.js +18 -13
- package/dist/matterRequest.d.ts +1 -1
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -6,10 +6,12 @@
|
|
|
6
6
|
[](https://hub.docker.com/r/luligu/matterbridge)
|
|
7
7
|

|
|
8
8
|

|
|
9
|
-
[](https://codecov.io/gh/Luligu/matterbridge)
|
|
10
|
+
[](https://vitest.dev)
|
|
11
|
+
[](https://oxc.rs/docs/guide/usage/formatter.html)
|
|
12
|
+
[](https://oxc.rs/docs/guide/usage/linter.html)
|
|
12
13
|
[](https://www.typescriptlang.org/)
|
|
14
|
+
[](https://github.com/microsoft/typescript-go)
|
|
13
15
|
[](https://nodejs.org/)
|
|
14
16
|
[](https://matterbridge.io)
|
|
15
17
|
|
package/dist/jestMatterTest.d.ts
CHANGED
|
@@ -10,14 +10,10 @@ export declare let aggregator: Endpoint<AggregatorEndpoint>;
|
|
|
10
10
|
export declare function createTestEnvironment(): Promise<Environment>;
|
|
11
11
|
export declare function destroyTestEnvironment(): Promise<void>;
|
|
12
12
|
export declare function getMatterbridge(): PlatformMatterbridge;
|
|
13
|
-
export declare const addBridgedEndpoint:
|
|
14
|
-
export declare const removeBridgedEndpoint:
|
|
15
|
-
export declare const removeAllBridgedEndpoints:
|
|
16
|
-
export declare const addVirtualEndpoint:
|
|
17
|
-
export declare const addBridgedEndpointMatterbridgeSpy: import("jest-mock").Mock<(pluginName: string, device: Endpoint) => Promise<boolean>>;
|
|
18
|
-
export declare const removeBridgedEndpointMatterbridgeSpy: import("jest-mock").Mock<(pluginName: string, device: Endpoint) => Promise<boolean>>;
|
|
19
|
-
export declare const removeAllBridgedEndpointsMatterbridgeSpy: import("jest-mock").Mock<(pluginName: string, _delay?: number) => Promise<boolean>>;
|
|
20
|
-
export declare const addVirtualEndpointMatterbridgeSpy: import("jest-mock").Mock<(pluginName: string, name: string, type: 'light' | 'outlet' | 'switch' | 'mounted_switch', callback: () => Promise<void>) => Promise<boolean>>;
|
|
13
|
+
export declare const addBridgedEndpoint: (pluginName: string, device: Endpoint) => Promise<boolean>;
|
|
14
|
+
export declare const removeBridgedEndpoint: (pluginName: string, device: Endpoint) => Promise<boolean>;
|
|
15
|
+
export declare const removeAllBridgedEndpoints: (_pluginName: string, _delay?: number) => Promise<boolean>;
|
|
16
|
+
export declare const addVirtualEndpoint: (pluginName: string, name: string, type: "light" | "outlet" | "switch" | "mounted_switch", callback: () => Promise<void>) => Promise<boolean>;
|
|
21
17
|
export declare function addMatterbridge(platform: object): void;
|
|
22
18
|
export declare function flushAllEndpointNumberPersistence(targetServer: ServerNode, rounds?: number, ticks?: number, microTurns?: number, pause?: number): Promise<void>;
|
|
23
19
|
export declare function assertAllEndpointNumbersPersisted(targetServer: ServerNode): Promise<number>;
|
package/dist/jestMatterTest.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import '@matter/nodejs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import { inspect } from 'node:util';
|
|
4
|
-
import { jest } from '@jest/globals';
|
|
5
3
|
import { Environment, Lifecycle, LogFormat as MatterLogFormat, LogLevel as MatterLogLevel } from '@matter/general';
|
|
6
4
|
import { Endpoint, ServerNode, ServerNodeStore } from '@matter/node';
|
|
7
5
|
import { BridgedDeviceBasicInformationServer } from '@matter/node/behaviors/bridged-device-basic-information';
|
|
@@ -11,12 +9,14 @@ import { MountedOnOffControlDevice } from '@matter/node/devices/mounted-on-off-c
|
|
|
11
9
|
import { AggregatorEndpoint } from '@matter/node/endpoints';
|
|
12
10
|
import { DeviceTypeId, VendorId } from '@matter/types/datatype';
|
|
13
11
|
import { MATTER_STORAGE_DIR } from '@matterbridge/types';
|
|
12
|
+
import { inspectError } from '@matterbridge/utils/error';
|
|
14
13
|
import { er, rs } from 'node-ansi-logger';
|
|
15
14
|
import { flushAsync } from './flushAsync.js';
|
|
16
|
-
import { HOMEDIR, NAME } from './jestSetupTest.js';
|
|
15
|
+
import { HOMEDIR, log, NAME } from './jestSetupTest.js';
|
|
17
16
|
export let environment;
|
|
18
17
|
export let server;
|
|
19
18
|
export let aggregator;
|
|
19
|
+
const noop = () => undefined;
|
|
20
20
|
export async function createTestEnvironment() {
|
|
21
21
|
expect(NAME).toBeDefined();
|
|
22
22
|
expect(typeof NAME).toBe('string');
|
|
@@ -76,7 +76,7 @@ export function getMatterbridge() {
|
|
|
76
76
|
};
|
|
77
77
|
return matterbridge;
|
|
78
78
|
}
|
|
79
|
-
export const addBridgedEndpoint =
|
|
79
|
+
export const addBridgedEndpoint = async (pluginName, device) => {
|
|
80
80
|
try {
|
|
81
81
|
await aggregator.add(device);
|
|
82
82
|
return Promise.resolve(true);
|
|
@@ -84,8 +84,8 @@ export const addBridgedEndpoint = jest.fn(async (pluginName, device) => {
|
|
|
84
84
|
catch (error) {
|
|
85
85
|
return Promise.reject(error);
|
|
86
86
|
}
|
|
87
|
-
}
|
|
88
|
-
export const removeBridgedEndpoint =
|
|
87
|
+
};
|
|
88
|
+
export const removeBridgedEndpoint = async (pluginName, device) => {
|
|
89
89
|
try {
|
|
90
90
|
await device.delete();
|
|
91
91
|
return Promise.resolve(true);
|
|
@@ -93,8 +93,8 @@ export const removeBridgedEndpoint = jest.fn(async (pluginName, device) => {
|
|
|
93
93
|
catch (error) {
|
|
94
94
|
return Promise.reject(error);
|
|
95
95
|
}
|
|
96
|
-
}
|
|
97
|
-
export const removeAllBridgedEndpoints =
|
|
96
|
+
};
|
|
97
|
+
export const removeAllBridgedEndpoints = async (_pluginName, _delay = 0) => {
|
|
98
98
|
try {
|
|
99
99
|
for (const device of aggregator.parts) {
|
|
100
100
|
await device.delete();
|
|
@@ -104,8 +104,8 @@ export const removeAllBridgedEndpoints = jest.fn(async (pluginName, _delay = 0)
|
|
|
104
104
|
catch (error) {
|
|
105
105
|
return Promise.reject(error);
|
|
106
106
|
}
|
|
107
|
-
}
|
|
108
|
-
export const addVirtualEndpoint =
|
|
107
|
+
};
|
|
108
|
+
export const addVirtualEndpoint = async (pluginName, name, type, callback) => {
|
|
109
109
|
try {
|
|
110
110
|
const device = new Endpoint(MountedOnOffControlDevice.with(BridgedDeviceBasicInformationServer), {
|
|
111
111
|
id: name.replaceAll(' ', '') + ':' + type,
|
|
@@ -121,8 +121,8 @@ export const addVirtualEndpoint = jest.fn(async (pluginName, name, type, callbac
|
|
|
121
121
|
});
|
|
122
122
|
device.events.onOff.onOff$Changed.on((value) => {
|
|
123
123
|
if (value) {
|
|
124
|
-
void callback().catch(
|
|
125
|
-
void device.setStateOf(OnOffServer, { onOff: false }).catch(
|
|
124
|
+
void callback().catch(noop);
|
|
125
|
+
void device.setStateOf(OnOffServer, { onOff: false }).catch(noop);
|
|
126
126
|
}
|
|
127
127
|
});
|
|
128
128
|
await aggregator.add(device);
|
|
@@ -136,11 +136,7 @@ export const addVirtualEndpoint = jest.fn(async (pluginName, name, type, callbac
|
|
|
136
136
|
catch (error) {
|
|
137
137
|
return Promise.reject(error);
|
|
138
138
|
}
|
|
139
|
-
}
|
|
140
|
-
export const addBridgedEndpointMatterbridgeSpy = addBridgedEndpoint;
|
|
141
|
-
export const removeBridgedEndpointMatterbridgeSpy = removeBridgedEndpoint;
|
|
142
|
-
export const removeAllBridgedEndpointsMatterbridgeSpy = removeAllBridgedEndpoints;
|
|
143
|
-
export const addVirtualEndpointMatterbridgeSpy = addVirtualEndpoint;
|
|
139
|
+
};
|
|
144
140
|
export function addMatterbridge(platform) {
|
|
145
141
|
expect(platform).toBeDefined();
|
|
146
142
|
platform.setMatterNode(addBridgedEndpoint, removeBridgedEndpoint, removeAllBridgedEndpoints, addVirtualEndpoint);
|
|
@@ -163,10 +159,8 @@ function collectAllEndpoints(root) {
|
|
|
163
159
|
const list = [];
|
|
164
160
|
const walk = (ep) => {
|
|
165
161
|
list.push(ep);
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
walk(child);
|
|
169
|
-
}
|
|
162
|
+
for (const child of ep.parts) {
|
|
163
|
+
walk(child);
|
|
170
164
|
}
|
|
171
165
|
};
|
|
172
166
|
walk(root);
|
|
@@ -188,9 +182,8 @@ export async function assertAllEndpointNumbersPersisted(targetServer) {
|
|
|
188
182
|
return all.length;
|
|
189
183
|
}
|
|
190
184
|
export async function closeServerNodeStores(targetServer) {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
await targetServer?.env.get(ServerNodeStore)?.endpointStores.close();
|
|
185
|
+
const resolvedTargetServer = targetServer ?? server;
|
|
186
|
+
await resolvedTargetServer?.env.get(ServerNodeStore)?.endpointStores.close();
|
|
194
187
|
}
|
|
195
188
|
export async function createServerNode(port, deviceType = DeviceTypeId(0x000e), ticks = 1, microTurns = 1, pause = 10) {
|
|
196
189
|
const { randomBytes } = await import('node:crypto');
|
|
@@ -247,7 +240,7 @@ export async function startServerNode(ticks = 1, microTurns = 1, pause = 10) {
|
|
|
247
240
|
throw new Error('Server node and aggregator must be created before starting the server. Call createServerNode() first.');
|
|
248
241
|
}
|
|
249
242
|
await new Promise((resolve, reject) => {
|
|
250
|
-
server.lifecycle.online.on(
|
|
243
|
+
server.lifecycle.online.on(() => {
|
|
251
244
|
resolve();
|
|
252
245
|
});
|
|
253
246
|
server.start().catch((err) => reject(err));
|
|
@@ -300,9 +293,8 @@ export async function addDevice(owner, device, rounds = 3, pause = 10) {
|
|
|
300
293
|
await owner.add(device);
|
|
301
294
|
}
|
|
302
295
|
catch (error) {
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
process.stderr.write(`${er}Error adding device ${device.maybeId}.${device.maybeNumber}: ${errorMessage}${rs}\nStack: ${errorInspect}\n`);
|
|
296
|
+
inspectError(log, `Error adding device ${device.maybeId}.${device.maybeNumber}`, error);
|
|
297
|
+
process.stderr.write(`${er}Error adding device ${device.maybeId}.${device.maybeNumber}${rs}\n`);
|
|
306
298
|
return false;
|
|
307
299
|
}
|
|
308
300
|
await device.construction.ready;
|
|
@@ -328,9 +320,8 @@ export async function deleteDevice(owner, device, rounds = 3, pause = 10) {
|
|
|
328
320
|
await device.delete();
|
|
329
321
|
}
|
|
330
322
|
catch (error) {
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
process.stderr.write(`${er}Error deleting device ${device.maybeId}.${device.maybeNumber}: ${errorMessage}${rs}\nStack: ${errorInspect}\n`);
|
|
323
|
+
inspectError(log, `Error deleting device ${device.maybeId}.${device.maybeNumber}`, error);
|
|
324
|
+
process.stderr.write(`${er}Error deleting device ${device.maybeId}.${device.maybeNumber}${rs}\n`);
|
|
334
325
|
return false;
|
|
335
326
|
}
|
|
336
327
|
expect(owner.parts.has(device)).toBeFalsy();
|
package/dist/jestSetupTest.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { jest } from '@jest/globals';
|
|
2
1
|
import { AnsiLogger } from 'node-ansi-logger';
|
|
3
2
|
export declare const originalProcessArgv: readonly string[];
|
|
4
3
|
export declare const originalProcessEnv: Readonly<Record<string, string | undefined>>;
|
|
@@ -17,5 +16,5 @@ export declare let consoleErrorSpy: jest.SpiedFunction<typeof console.error>;
|
|
|
17
16
|
export declare let NAME: string;
|
|
18
17
|
export declare let HOMEDIR: string;
|
|
19
18
|
export declare let log: AnsiLogger;
|
|
20
|
-
export declare function setupTest(name: string, debug?: boolean): Promise<void>;
|
|
19
|
+
export declare function setupTest(name: string, debug?: boolean, argv?: string[], env?: Record<string, string>): Promise<void>;
|
|
21
20
|
export declare function setDebug(debug: boolean): Promise<void>;
|
package/dist/jestSetupTest.js
CHANGED
|
@@ -18,12 +18,17 @@ export let consoleErrorSpy;
|
|
|
18
18
|
export let NAME;
|
|
19
19
|
export let HOMEDIR;
|
|
20
20
|
export let log;
|
|
21
|
-
|
|
21
|
+
const noop = () => undefined;
|
|
22
|
+
export async function setupTest(name, debug = false, argv = [], env = {}) {
|
|
22
23
|
expect(name).toBeDefined();
|
|
23
24
|
expect(typeof name).toBe('string');
|
|
24
25
|
expect(name.length).toBeGreaterThanOrEqual(4);
|
|
25
26
|
NAME = name;
|
|
26
27
|
HOMEDIR = path.join('.cache', 'jest', name);
|
|
28
|
+
process.argv = ['jest', name, ...argv];
|
|
29
|
+
for (const [key, value] of Object.entries(env)) {
|
|
30
|
+
process.env[key] = value;
|
|
31
|
+
}
|
|
27
32
|
log = new AnsiLogger({ logName: name, logTimestampFormat: 4, logLevel: "debug" });
|
|
28
33
|
rmSync(HOMEDIR, { recursive: true, force: true });
|
|
29
34
|
mkdirSync(HOMEDIR, { recursive: true });
|
|
@@ -43,12 +48,12 @@ export async function setupTest(name, debug = false) {
|
|
|
43
48
|
consoleErrorSpy = jest.spyOn(console, 'error');
|
|
44
49
|
}
|
|
45
50
|
else {
|
|
46
|
-
loggerLogSpy = jest.spyOn(AnsiLogger.prototype, 'log').mockImplementation(
|
|
47
|
-
consoleLogSpy = jest.spyOn(console, 'log').mockImplementation(
|
|
48
|
-
consoleDebugSpy = jest.spyOn(console, 'debug').mockImplementation(
|
|
49
|
-
consoleInfoSpy = jest.spyOn(console, 'info').mockImplementation(
|
|
50
|
-
consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementation(
|
|
51
|
-
consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(
|
|
51
|
+
loggerLogSpy = jest.spyOn(AnsiLogger.prototype, 'log').mockImplementation(noop);
|
|
52
|
+
consoleLogSpy = jest.spyOn(console, 'log').mockImplementation(noop);
|
|
53
|
+
consoleDebugSpy = jest.spyOn(console, 'debug').mockImplementation(noop);
|
|
54
|
+
consoleInfoSpy = jest.spyOn(console, 'info').mockImplementation(noop);
|
|
55
|
+
consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementation(noop);
|
|
56
|
+
consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(noop);
|
|
52
57
|
}
|
|
53
58
|
}
|
|
54
59
|
export async function setDebug(debug) {
|
|
@@ -68,11 +73,11 @@ export async function setDebug(debug) {
|
|
|
68
73
|
consoleErrorSpy = jest.spyOn(console, 'error');
|
|
69
74
|
}
|
|
70
75
|
else {
|
|
71
|
-
loggerLogSpy = jest.spyOn(AnsiLogger.prototype, 'log').mockImplementation(
|
|
72
|
-
consoleLogSpy = jest.spyOn(console, 'log').mockImplementation(
|
|
73
|
-
consoleDebugSpy = jest.spyOn(console, 'debug').mockImplementation(
|
|
74
|
-
consoleInfoSpy = jest.spyOn(console, 'info').mockImplementation(
|
|
75
|
-
consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementation(
|
|
76
|
-
consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(
|
|
76
|
+
loggerLogSpy = jest.spyOn(AnsiLogger.prototype, 'log').mockImplementation(noop);
|
|
77
|
+
consoleLogSpy = jest.spyOn(console, 'log').mockImplementation(noop);
|
|
78
|
+
consoleDebugSpy = jest.spyOn(console, 'debug').mockImplementation(noop);
|
|
79
|
+
consoleInfoSpy = jest.spyOn(console, 'info').mockImplementation(noop);
|
|
80
|
+
consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementation(noop);
|
|
81
|
+
consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(noop);
|
|
77
82
|
}
|
|
78
83
|
}
|
package/dist/matterRequest.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ColorControl } from '@matter/types/clusters/color-control';
|
|
2
|
-
import {
|
|
2
|
+
import type { LevelControl } from '@matter/types/clusters/level-control';
|
|
3
3
|
export declare function getMoveToLevelRequest(level: number, transitionTime: number, executeIfOff: boolean): LevelControl.MoveToLevelRequest;
|
|
4
4
|
export declare function getMoveToColorTemperatureRequest(colorTemperatureMireds: number, transitionTime: number, executeIfOff: boolean): ColorControl.MoveToColorTemperatureRequest;
|
|
5
5
|
export declare function getMoveToHueRequest(hue: number, transitionTime: number, executeIfOff: boolean): ColorControl.MoveToHueRequest;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@matterbridge/jest-utils",
|
|
3
|
-
"version": "3.9.1-dev-
|
|
3
|
+
"version": "3.9.1-dev-20260617-b1e1b99",
|
|
4
4
|
"description": "Matterbridge jest utility library",
|
|
5
5
|
"author": "https://github.com/Luligu",
|
|
6
6
|
"homepage": "https://matterbridge.io/",
|
|
@@ -65,7 +65,9 @@
|
|
|
65
65
|
"CHANGELOG.md"
|
|
66
66
|
],
|
|
67
67
|
"dependencies": {
|
|
68
|
-
"@
|
|
68
|
+
"@matter/main": "0.17.3",
|
|
69
|
+
"@matterbridge/types": "3.9.1-dev-20260617-b1e1b99",
|
|
70
|
+
"@matterbridge/utils": "3.9.1-dev-20260617-b1e1b99",
|
|
69
71
|
"node-ansi-logger": "3.3.0-dev-20260607-585945a"
|
|
70
72
|
}
|
|
71
73
|
}
|