@matterbridge/test-utils 3.10.13-dev-20261005-49e0dbd → 3.10.13-dev-20261007-320f739
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/dist/buntest/matterTest.js +1 -1
- package/dist/buntest/matterTest.js.map +1 -1
- package/dist/buntest/setupTest.d.ts +36 -3
- package/dist/buntest/setupTest.d.ts.map +1 -1
- package/dist/buntest/setupTest.js +139 -50
- package/dist/buntest/setupTest.js.map +1 -1
- package/dist/export.d.ts +1 -0
- package/dist/export.d.ts.map +1 -1
- package/dist/export.js +1 -0
- package/dist/export.js.map +1 -1
- package/dist/freePort.d.ts +30 -0
- package/dist/freePort.d.ts.map +1 -0
- package/dist/freePort.js +50 -0
- package/dist/freePort.js.map +1 -0
- package/dist/inspectError.d.ts +35 -0
- package/dist/inspectError.d.ts.map +1 -0
- package/dist/inspectError.js +42 -0
- package/dist/inspectError.js.map +1 -0
- package/dist/jest/matterTest.js +1 -1
- package/dist/jest/matterTest.js.map +1 -1
- package/dist/jest/setupTest.d.ts +35 -2
- package/dist/jest/setupTest.d.ts.map +1 -1
- package/dist/jest/setupTest.js +139 -51
- package/dist/jest/setupTest.js.map +1 -1
- package/dist/vitest/matterTest.js +1 -1
- package/dist/vitest/matterTest.js.map +1 -1
- package/dist/vitest/setupTest.d.ts +35 -2
- package/dist/vitest/setupTest.d.ts.map +1 -1
- package/dist/vitest/setupTest.js +138 -49
- package/dist/vitest/setupTest.js.map +1 -1
- package/package.json +26 -3
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @description This file contains the Vitest base helpers.
|
|
4
4
|
* @author Luca Liguori
|
|
5
5
|
* @created 2025-12-31
|
|
6
|
-
* @version 1.
|
|
6
|
+
* @version 1.1.0
|
|
7
7
|
* @license Apache-2.0
|
|
8
8
|
*
|
|
9
9
|
* Copyright 2025, 2026, 2027 Luca Liguori.
|
|
@@ -46,17 +46,50 @@ export declare let log: AnsiLogger;
|
|
|
46
46
|
* - process.argv will be set to ['vitest', name, ...argv]
|
|
47
47
|
* - the provided environment variables will be set on process.env
|
|
48
48
|
*
|
|
49
|
-
* @param {string} name The name of the test suite.
|
|
49
|
+
* @param {string} name The name of the test suite. Letters, digits, underscores and dashes only.
|
|
50
50
|
* @param {boolean} debug If true, the logging is not mocked.
|
|
51
51
|
* @param {string[]} argv Additional process.argv arguments to set after the 'vitest' and name entries.
|
|
52
52
|
* @param {Record<string, string>} env Environment variables to set on process.env.
|
|
53
|
+
*
|
|
54
|
+
* @throws {Error} When the name is shorter than four characters or contains characters that could escape the home directory.
|
|
55
|
+
*
|
|
56
|
+
* @remarks Logs an error and returns without doing anything when the same name is set up more than
|
|
57
|
+
* once. Call it once per test file, or call resetTest() first.
|
|
58
|
+
*
|
|
59
|
+
* Use `vi.restoreAllMocks()` only in `afterAll`, together with resetTest(). In `afterEach`, a
|
|
60
|
+
* `beforeEach` or a test body it also restores the logger and console spies installed here, so the
|
|
61
|
+
* exported spies stop recording for the rest of the file. To clean up after each test, restore only
|
|
62
|
+
* the spies that test created, for example by keeping them in a list and calling `mockRestore()` on
|
|
63
|
+
* each one in `afterEach`.
|
|
53
64
|
*/
|
|
54
65
|
export declare function setupTest(name: string, debug?: boolean, argv?: string[], env?: Record<string, string>): Promise<void>;
|
|
55
66
|
/**
|
|
56
67
|
* Set or unset the debug mode.
|
|
57
68
|
*
|
|
69
|
+
* Logs an error and does nothing when called before setupTest(), since there are no spies to switch over.
|
|
70
|
+
*
|
|
58
71
|
* @param {boolean} debug If true, the logging is not mocked.
|
|
59
72
|
* @returns {Promise<void>} A promise that resolves when the debug mode is set.
|
|
60
73
|
*/
|
|
61
74
|
export declare function setDebug(debug: boolean): Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* Undo what setupTest() did:
|
|
77
|
+
* - restores AnsiLogger.prototype and the console methods
|
|
78
|
+
* - restores process.argv and process.env to the values captured when this module was loaded
|
|
79
|
+
* - lets setupTest() run again for the same suite name
|
|
80
|
+
*
|
|
81
|
+
* Does nothing harmful when setupTest() has not run. It does not remove the home directory, so
|
|
82
|
+
* anything written there is still available afterwards.
|
|
83
|
+
*
|
|
84
|
+
* @returns {void}
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* afterAll(() => {
|
|
89
|
+
* // Reset the test environment before the next test.
|
|
90
|
+
* resetTest();
|
|
91
|
+
* });
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
export declare function resetTest(): void;
|
|
62
95
|
//# sourceMappingURL=setupTest.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setupTest.d.ts","sourceRoot":"","sources":["../../src/vitest/setupTest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAKH,OAAO,EAAE,UAAU,EAA6B,MAAM,kBAAkB,CAAC;AACzE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAE3C,eAAO,MAAM,mBAAmB,mBAAmC,CAAC;AACpE,eAAO,MAAM,kBAAkB,8CAA0E,CAAC;AAG1G,eAAO,IAAI,YAAY,EAAE,YAAY,CAAC,OAAO,UAAU,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;AACvE,eAAO,IAAI,cAAc,EAAE,YAAY,CAAC,OAAO,UAAU,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AAC3E,eAAO,IAAI,aAAa,EAAE,YAAY,CAAC,OAAO,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;AACzE,eAAO,IAAI,eAAe,EAAE,YAAY,CAAC,OAAO,UAAU,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;AAC7E,eAAO,IAAI,aAAa,EAAE,YAAY,CAAC,OAAO,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;AACzE,eAAO,IAAI,cAAc,EAAE,YAAY,CAAC,OAAO,UAAU,CAAC,SAAS,CAAC,KAAK,C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BG;AACH,wBAAgB,SAAS,IAAI,IAAI,CAgBhC"}
|
package/dist/vitest/setupTest.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @description This file contains the Vitest base helpers.
|
|
4
4
|
* @author Luca Liguori
|
|
5
5
|
* @created 2025-12-31
|
|
6
|
-
* @version 1.
|
|
6
|
+
* @version 1.1.0
|
|
7
7
|
* @license Apache-2.0
|
|
8
8
|
*
|
|
9
9
|
* Copyright 2025, 2026, 2027 Luca Liguori.
|
|
@@ -43,6 +43,74 @@ export let NAME;
|
|
|
43
43
|
export let HOMEDIR;
|
|
44
44
|
export let log;
|
|
45
45
|
const noop = () => undefined;
|
|
46
|
+
// Names are joined into HOMEDIR and that directory is removed, so anything that could escape
|
|
47
|
+
// .cache/vitest is rejected: path.join('.cache', 'vitest', '../../src') collapses to 'src'.
|
|
48
|
+
const VALID_NAME = /^[A-Za-z0-9_-]+$/;
|
|
49
|
+
// True once installSpies() has installed the spies.
|
|
50
|
+
let initialized = false;
|
|
51
|
+
// Suite names already set up. Test files share one module registry, so 'called once' can only be
|
|
52
|
+
// enforced per suite name: one setupTest() call per test file, not one per process.
|
|
53
|
+
const configured = new Set();
|
|
54
|
+
/**
|
|
55
|
+
* The spies currently installed, in a shape that only exposes what the restore loop needs.
|
|
56
|
+
*
|
|
57
|
+
* @returns {{ mockRestore: () => void }[]} The installed logger and console spies.
|
|
58
|
+
*/
|
|
59
|
+
function installedSpies() {
|
|
60
|
+
return [
|
|
61
|
+
loggerLogSpy,
|
|
62
|
+
loggerDebugSpy,
|
|
63
|
+
loggerInfoSpy,
|
|
64
|
+
loggerNoticeSpy,
|
|
65
|
+
loggerWarnSpy,
|
|
66
|
+
loggerErrorSpy,
|
|
67
|
+
loggerFatalSpy,
|
|
68
|
+
consoleLogSpy,
|
|
69
|
+
consoleDebugSpy,
|
|
70
|
+
consoleInfoSpy,
|
|
71
|
+
consoleWarnSpy,
|
|
72
|
+
consoleErrorSpy,
|
|
73
|
+
];
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Install the logger and console spies, replacing any that are already installed.
|
|
77
|
+
*
|
|
78
|
+
* `vi.spyOn` returns the mock already attached to a target instead of wrapping it again, so every
|
|
79
|
+
* previous spy is restored first. Without that, a mocked implementation would survive into debug
|
|
80
|
+
* mode and the output would stay silenced.
|
|
81
|
+
*
|
|
82
|
+
* @param {boolean} debug If true, the spies pass the calls through to the original implementation.
|
|
83
|
+
* @returns {Promise<void>} A promise that resolves once the spies are installed.
|
|
84
|
+
*/
|
|
85
|
+
async function installSpies(debug) {
|
|
86
|
+
const { vi } = await import('vitest');
|
|
87
|
+
if (initialized) {
|
|
88
|
+
for (const spy of installedSpies()) {
|
|
89
|
+
spy.mockRestore();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
loggerLogSpy = vi.spyOn(AnsiLogger.prototype, 'log');
|
|
93
|
+
loggerDebugSpy = vi.spyOn(AnsiLogger.prototype, 'debug');
|
|
94
|
+
loggerInfoSpy = vi.spyOn(AnsiLogger.prototype, 'info');
|
|
95
|
+
loggerNoticeSpy = vi.spyOn(AnsiLogger.prototype, 'notice');
|
|
96
|
+
loggerWarnSpy = vi.spyOn(AnsiLogger.prototype, 'warn');
|
|
97
|
+
loggerErrorSpy = vi.spyOn(AnsiLogger.prototype, 'error');
|
|
98
|
+
loggerFatalSpy = vi.spyOn(AnsiLogger.prototype, 'fatal');
|
|
99
|
+
consoleLogSpy = vi.spyOn(console, 'log');
|
|
100
|
+
consoleDebugSpy = vi.spyOn(console, 'debug');
|
|
101
|
+
consoleInfoSpy = vi.spyOn(console, 'info');
|
|
102
|
+
consoleWarnSpy = vi.spyOn(console, 'warn');
|
|
103
|
+
consoleErrorSpy = vi.spyOn(console, 'error');
|
|
104
|
+
if (!debug) {
|
|
105
|
+
loggerLogSpy.mockImplementation(noop);
|
|
106
|
+
consoleLogSpy.mockImplementation(noop);
|
|
107
|
+
consoleDebugSpy.mockImplementation(noop);
|
|
108
|
+
consoleInfoSpy.mockImplementation(noop);
|
|
109
|
+
consoleWarnSpy.mockImplementation(noop);
|
|
110
|
+
consoleErrorSpy.mockImplementation(noop);
|
|
111
|
+
}
|
|
112
|
+
initialized = true;
|
|
113
|
+
}
|
|
46
114
|
/**
|
|
47
115
|
* Setup the Vitest environment:
|
|
48
116
|
* - it will remove any existing home directory
|
|
@@ -50,15 +118,35 @@ const noop = () => undefined;
|
|
|
50
118
|
* - process.argv will be set to ['vitest', name, ...argv]
|
|
51
119
|
* - the provided environment variables will be set on process.env
|
|
52
120
|
*
|
|
53
|
-
* @param {string} name The name of the test suite.
|
|
121
|
+
* @param {string} name The name of the test suite. Letters, digits, underscores and dashes only.
|
|
54
122
|
* @param {boolean} debug If true, the logging is not mocked.
|
|
55
123
|
* @param {string[]} argv Additional process.argv arguments to set after the 'vitest' and name entries.
|
|
56
124
|
* @param {Record<string, string>} env Environment variables to set on process.env.
|
|
125
|
+
*
|
|
126
|
+
* @throws {Error} When the name is shorter than four characters or contains characters that could escape the home directory.
|
|
127
|
+
*
|
|
128
|
+
* @remarks Logs an error and returns without doing anything when the same name is set up more than
|
|
129
|
+
* once. Call it once per test file, or call resetTest() first.
|
|
130
|
+
*
|
|
131
|
+
* Use `vi.restoreAllMocks()` only in `afterAll`, together with resetTest(). In `afterEach`, a
|
|
132
|
+
* `beforeEach` or a test body it also restores the logger and console spies installed here, so the
|
|
133
|
+
* exported spies stop recording for the rest of the file. To clean up after each test, restore only
|
|
134
|
+
* the spies that test created, for example by keeping them in a list and calling `mockRestore()` on
|
|
135
|
+
* each one in `afterEach`.
|
|
57
136
|
*/
|
|
58
137
|
export async function setupTest(name, debug = false, argv = [], env = {}) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
138
|
+
if (typeof name !== 'string' || name.length < 4) {
|
|
139
|
+
throw new Error(`setupTest: invalid name '${name}'. Use at least four characters.`);
|
|
140
|
+
}
|
|
141
|
+
if (!VALID_NAME.test(name)) {
|
|
142
|
+
throw new Error(`setupTest: invalid name '${name}'. Use letters, digits, underscores and dashes only.`);
|
|
143
|
+
}
|
|
144
|
+
if (configured.has(name)) {
|
|
145
|
+
// Written to stderr, not console.error, so the message survives a mocked console
|
|
146
|
+
process.stderr.write(`setupTest: '${name}' has already been set up. Call setupTest() once per test file.\n`);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
configured.add(name);
|
|
62
150
|
NAME = name;
|
|
63
151
|
HOMEDIR = path.join('.cache', 'vitest', name);
|
|
64
152
|
process.argv = ['vitest', name, ...argv];
|
|
@@ -71,59 +159,60 @@ export async function setupTest(name, debug = false, argv = [], env = {}) {
|
|
|
71
159
|
// Cleanup any existing home directory
|
|
72
160
|
rmSync(HOMEDIR, { recursive: true, force: true });
|
|
73
161
|
mkdirSync(HOMEDIR, { recursive: true });
|
|
74
|
-
|
|
75
|
-
loggerDebugSpy = vi.spyOn(AnsiLogger.prototype, 'debug');
|
|
76
|
-
loggerInfoSpy = vi.spyOn(AnsiLogger.prototype, 'info');
|
|
77
|
-
loggerNoticeSpy = vi.spyOn(AnsiLogger.prototype, 'notice');
|
|
78
|
-
loggerWarnSpy = vi.spyOn(AnsiLogger.prototype, 'warn');
|
|
79
|
-
loggerErrorSpy = vi.spyOn(AnsiLogger.prototype, 'error');
|
|
80
|
-
loggerFatalSpy = vi.spyOn(AnsiLogger.prototype, 'fatal');
|
|
81
|
-
if (debug) {
|
|
82
|
-
loggerLogSpy = vi.spyOn(AnsiLogger.prototype, 'log');
|
|
83
|
-
consoleLogSpy = vi.spyOn(console, 'log');
|
|
84
|
-
consoleDebugSpy = vi.spyOn(console, 'debug');
|
|
85
|
-
consoleInfoSpy = vi.spyOn(console, 'info');
|
|
86
|
-
consoleWarnSpy = vi.spyOn(console, 'warn');
|
|
87
|
-
consoleErrorSpy = vi.spyOn(console, 'error');
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
loggerLogSpy = vi.spyOn(AnsiLogger.prototype, 'log').mockImplementation(noop);
|
|
91
|
-
consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(noop);
|
|
92
|
-
consoleDebugSpy = vi.spyOn(console, 'debug').mockImplementation(noop);
|
|
93
|
-
consoleInfoSpy = vi.spyOn(console, 'info').mockImplementation(noop);
|
|
94
|
-
consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(noop);
|
|
95
|
-
consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(noop);
|
|
96
|
-
}
|
|
162
|
+
await installSpies(debug);
|
|
97
163
|
}
|
|
98
164
|
/**
|
|
99
165
|
* Set or unset the debug mode.
|
|
100
166
|
*
|
|
167
|
+
* Logs an error and does nothing when called before setupTest(), since there are no spies to switch over.
|
|
168
|
+
*
|
|
101
169
|
* @param {boolean} debug If true, the logging is not mocked.
|
|
102
170
|
* @returns {Promise<void>} A promise that resolves when the debug mode is set.
|
|
103
171
|
*/
|
|
104
172
|
export async function setDebug(debug) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
173
|
+
if (!initialized) {
|
|
174
|
+
// Written to stderr, not console.error, so the message survives a mocked console
|
|
175
|
+
process.stderr.write('setDebug() called before setupTest(): no spies to switch, ignoring.\n');
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
await installSpies(debug);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Undo what setupTest() did:
|
|
182
|
+
* - restores AnsiLogger.prototype and the console methods
|
|
183
|
+
* - restores process.argv and process.env to the values captured when this module was loaded
|
|
184
|
+
* - lets setupTest() run again for the same suite name
|
|
185
|
+
*
|
|
186
|
+
* Does nothing harmful when setupTest() has not run. It does not remove the home directory, so
|
|
187
|
+
* anything written there is still available afterwards.
|
|
188
|
+
*
|
|
189
|
+
* @returns {void}
|
|
190
|
+
*
|
|
191
|
+
* @example
|
|
192
|
+
* ```typescript
|
|
193
|
+
* afterAll(() => {
|
|
194
|
+
* // Reset the test environment before the next test.
|
|
195
|
+
* resetTest();
|
|
196
|
+
* });
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
export function resetTest() {
|
|
200
|
+
if (initialized) {
|
|
201
|
+
for (const spy of installedSpies()) {
|
|
202
|
+
spy.mockRestore();
|
|
203
|
+
}
|
|
204
|
+
initialized = false;
|
|
205
|
+
}
|
|
206
|
+
if (NAME)
|
|
207
|
+
configured.delete(NAME);
|
|
208
|
+
process.argv = [...originalProcessArgv];
|
|
209
|
+
for (const key of Object.keys(process.env)) {
|
|
210
|
+
if (!(key in originalProcessEnv))
|
|
211
|
+
Reflect.deleteProperty(process.env, key);
|
|
119
212
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
consoleDebugSpy = vi.spyOn(console, 'debug').mockImplementation(noop);
|
|
124
|
-
consoleInfoSpy = vi.spyOn(console, 'info').mockImplementation(noop);
|
|
125
|
-
consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(noop);
|
|
126
|
-
consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(noop);
|
|
213
|
+
for (const [key, value] of Object.entries(originalProcessEnv)) {
|
|
214
|
+
if (value !== undefined)
|
|
215
|
+
process.env[key] = value;
|
|
127
216
|
}
|
|
128
217
|
}
|
|
129
218
|
//# sourceMappingURL=setupTest.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setupTest.js","sourceRoot":"","sources":["../../src/vitest/setupTest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,UAAU,EAA6B,MAAM,kBAAkB,CAAC;AAGzE,MAAM,CAAC,M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CAAC,GAAG,CAAC,EAAE,CAAC;QAC3C,IAAI,CAAC,CAAC,GAAG,IAAI,kBAAkB,CAAC;YAAE,OAAO,CAAC,cAAc,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAC7E,CAAC;IACD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,kBAAkB,CAAC,EAAE,CAAC;QAC9D,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IACpD,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@matterbridge/test-utils",
|
|
3
|
-
"version": "3.10.13-dev-
|
|
3
|
+
"version": "3.10.13-dev-20261007-320f739",
|
|
4
4
|
"description": "Matterbridge common and framework-specific test utilities",
|
|
5
5
|
"author": "https://github.com/Luligu",
|
|
6
6
|
"homepage": "https://matterbridge.io/",
|
|
@@ -58,13 +58,37 @@
|
|
|
58
58
|
"types": "./dist/jest/export.d.ts",
|
|
59
59
|
"import": "./dist/jest/export.js"
|
|
60
60
|
},
|
|
61
|
+
"./jest/setup": {
|
|
62
|
+
"types": "./dist/jest/setupTest.d.ts",
|
|
63
|
+
"import": "./dist/jest/setupTest.js"
|
|
64
|
+
},
|
|
65
|
+
"./jest/matter": {
|
|
66
|
+
"types": "./dist/jest/matterTest.d.ts",
|
|
67
|
+
"import": "./dist/jest/matterTest.js"
|
|
68
|
+
},
|
|
61
69
|
"./vitest": {
|
|
62
70
|
"types": "./dist/vitest/export.d.ts",
|
|
63
71
|
"import": "./dist/vitest/export.js"
|
|
64
72
|
},
|
|
73
|
+
"./vitest/setup": {
|
|
74
|
+
"types": "./dist/vitest/setupTest.d.ts",
|
|
75
|
+
"import": "./dist/vitest/setupTest.js"
|
|
76
|
+
},
|
|
77
|
+
"./vitest/matter": {
|
|
78
|
+
"types": "./dist/vitest/matterTest.d.ts",
|
|
79
|
+
"import": "./dist/vitest/matterTest.js"
|
|
80
|
+
},
|
|
65
81
|
"./buntest": {
|
|
66
82
|
"types": "./dist/buntest/export.d.ts",
|
|
67
83
|
"import": "./dist/buntest/export.js"
|
|
84
|
+
},
|
|
85
|
+
"./buntest/setup": {
|
|
86
|
+
"types": "./dist/buntest/setupTest.d.ts",
|
|
87
|
+
"import": "./dist/buntest/setupTest.js"
|
|
88
|
+
},
|
|
89
|
+
"./buntest/matter": {
|
|
90
|
+
"types": "./dist/buntest/matterTest.d.ts",
|
|
91
|
+
"import": "./dist/buntest/matterTest.js"
|
|
68
92
|
}
|
|
69
93
|
},
|
|
70
94
|
"engines": {
|
|
@@ -84,8 +108,7 @@
|
|
|
84
108
|
},
|
|
85
109
|
"dependencies": {
|
|
86
110
|
"@matter/main": "0.17.9",
|
|
87
|
-
"@matterbridge/types": "3.10.13-dev-
|
|
88
|
-
"@matterbridge/utils": "3.10.13-dev-20261005-49e0dbd",
|
|
111
|
+
"@matterbridge/types": "3.10.13-dev-20261007-320f739",
|
|
89
112
|
"node-ansi-logger": "3.3.1"
|
|
90
113
|
}
|
|
91
114
|
}
|