@fedify/testing 2.0.1-dev.401 → 2.0.2-dev.407
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/mod.d.cts +121 -113
- package/dist/mod.d.ts +121 -113
- package/package.json +2 -2
package/dist/mod.d.cts
CHANGED
|
@@ -3,48 +3,51 @@ import { Activity } from "@fedify/vocab";
|
|
|
3
3
|
import { MessageQueue } from "@fedify/fedify";
|
|
4
4
|
|
|
5
5
|
//#region src/context.d.ts
|
|
6
|
+
// NOTE: Copied from @fedify/fedify/testing/context.ts
|
|
7
|
+
// Not exported - used internally only. Public API is in mock.ts
|
|
6
8
|
declare function createContext<TContextData>(values: Partial<Context<TContextData>> & {
|
|
7
9
|
url?: URL;
|
|
8
10
|
data: TContextData;
|
|
9
11
|
federation: Federation<TContextData>;
|
|
10
12
|
}): Context<TContextData>;
|
|
11
13
|
/**
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
* Creates a RequestContext for testing purposes.
|
|
15
|
+
* Not exported - used internally only. Public API is in mock.ts
|
|
16
|
+
* @param args Partial RequestContext properties
|
|
17
|
+
* @returns A RequestContext instance
|
|
18
|
+
* @since 1.8.0
|
|
19
|
+
*/
|
|
18
20
|
declare function createRequestContext<TContextData>(args: Partial<RequestContext<TContextData>> & {
|
|
19
21
|
url: URL;
|
|
20
22
|
data: TContextData;
|
|
21
23
|
federation: Federation<TContextData>;
|
|
22
24
|
}): RequestContext<TContextData>;
|
|
23
25
|
/**
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
* Test-specific InboxContext type alias.
|
|
27
|
+
* This indirection helps avoid JSR type analyzer issues.
|
|
28
|
+
* @since 1.9.1
|
|
29
|
+
*/
|
|
28
30
|
type TestInboxContext<TContextData> = InboxContext<TContextData>;
|
|
29
31
|
/**
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
* Creates an InboxContext for testing purposes.
|
|
33
|
+
* Not exported - used internally only. Public API is in mock.ts
|
|
34
|
+
* @param args Partial InboxContext properties
|
|
35
|
+
* @returns An InboxContext instance
|
|
36
|
+
* @since 1.8.0
|
|
37
|
+
*/
|
|
36
38
|
declare function createInboxContext<TContextData>(args: Partial<InboxContext<TContextData>> & {
|
|
37
39
|
url?: URL;
|
|
38
40
|
data: TContextData;
|
|
39
41
|
recipient?: string | null;
|
|
40
42
|
federation: Federation<TContextData>;
|
|
41
43
|
}): TestInboxContext<TContextData>;
|
|
44
|
+
// Export for internal use by mock.ts only
|
|
42
45
|
//#endregion
|
|
43
46
|
//#region src/mock.d.ts
|
|
44
47
|
/**
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
+
* Represents a sent activity with metadata about how it was sent.
|
|
49
|
+
* @since 1.8.0
|
|
50
|
+
*/
|
|
48
51
|
interface SentActivity {
|
|
49
52
|
/** Whether the activity was queued or sent immediately. */
|
|
50
53
|
queued: boolean;
|
|
@@ -56,12 +59,14 @@ interface SentActivity {
|
|
|
56
59
|
sentOrder: number;
|
|
57
60
|
}
|
|
58
61
|
/**
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
62
|
+
* A mock Context interface for testing purposes.
|
|
63
|
+
* Extends the standard Context interface with additional testing utilities.
|
|
64
|
+
* @since 1.9.1
|
|
65
|
+
*/
|
|
63
66
|
interface TestContext<TContextData> extends Omit<Context<TContextData>, "clone">, Pick<RequestContext<TContextData>, "request" | "url" | "getActor" | "getObject" | "getSignedKey" | "getSignedKeyOwner" | "sendActivity" | "routeActivity"> {
|
|
67
|
+
// Override clone to return TestContext
|
|
64
68
|
clone(data: TContextData): TestContext<TContextData>;
|
|
69
|
+
// Test-specific methods
|
|
65
70
|
getSentActivities(): Array<{
|
|
66
71
|
sender: any;
|
|
67
72
|
recipients: any;
|
|
@@ -70,54 +75,57 @@ interface TestContext<TContextData> extends Omit<Context<TContextData>, "clone">
|
|
|
70
75
|
reset(): void;
|
|
71
76
|
}
|
|
72
77
|
/**
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
78
|
+
* A mock Federation interface for testing purposes.
|
|
79
|
+
* Extends the standard Federation interface with additional testing utilities.
|
|
80
|
+
* @since 1.9.1
|
|
81
|
+
*/
|
|
77
82
|
interface TestFederation<TContextData> extends Omit<Federation<TContextData>, "createContext"> {
|
|
83
|
+
// Test-specific properties
|
|
78
84
|
sentActivities: SentActivity[];
|
|
79
85
|
queueStarted: boolean;
|
|
80
86
|
sentCounter: number;
|
|
87
|
+
// Test-specific methods
|
|
81
88
|
receiveActivity(activity: Activity): Promise<void>;
|
|
82
89
|
reset(): void;
|
|
90
|
+
// Override createContext to return TestContext
|
|
83
91
|
createContext(baseUrlOrRequest: URL | Request, contextData: TContextData): TestContext<TContextData>;
|
|
84
92
|
}
|
|
85
93
|
/**
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
94
|
+
* Creates a mock Federation instance for testing purposes.
|
|
95
|
+
*
|
|
96
|
+
* @template TContextData The type of context data to use
|
|
97
|
+
* @param options Optional configuration for the mock federation
|
|
98
|
+
* @returns A Federation instance that can be used for testing
|
|
99
|
+
* @since 1.9.1
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```typescript
|
|
103
|
+
* import { Create } from "@fedify/vocab";
|
|
104
|
+
* import { createFederation } from "@fedify/testing";
|
|
105
|
+
*
|
|
106
|
+
* // Create a mock federation with contextData
|
|
107
|
+
* const federation = createFederation<{ userId: string }>({
|
|
108
|
+
* contextData: { userId: "test-user" }
|
|
109
|
+
* });
|
|
110
|
+
*
|
|
111
|
+
* // Set up inbox listeners
|
|
112
|
+
* federation
|
|
113
|
+
* .setInboxListeners("/users/{identifier}/inbox")
|
|
114
|
+
* .on(Create, async (ctx, activity) => {
|
|
115
|
+
* console.log("Received:", activity);
|
|
116
|
+
* });
|
|
117
|
+
*
|
|
118
|
+
* // Simulate receiving an activity
|
|
119
|
+
* const createActivity = new Create({
|
|
120
|
+
* id: new URL("https://example.com/create/1"),
|
|
121
|
+
* actor: new URL("https://example.com/users/alice")
|
|
122
|
+
* });
|
|
123
|
+
* await federation.receiveActivity(createActivity);
|
|
124
|
+
*
|
|
125
|
+
* // Check sent activities
|
|
126
|
+
* console.log(federation.sentActivities);
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
121
129
|
declare function createFederation<TContextData>(options?: {
|
|
122
130
|
contextData?: TContextData;
|
|
123
131
|
origin?: string;
|
|
@@ -126,62 +134,62 @@ declare function createFederation<TContextData>(options?: {
|
|
|
126
134
|
//#endregion
|
|
127
135
|
//#region src/mq-tester.d.ts
|
|
128
136
|
/**
|
|
129
|
-
|
|
130
|
-
|
|
137
|
+
* Options for {@link testMessageQueue}.
|
|
138
|
+
*/
|
|
131
139
|
interface TestMessageQueueOptions {
|
|
132
140
|
/**
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
141
|
+
* Whether to test ordering key support. If `true`, tests will verify that
|
|
142
|
+
* messages with the same ordering key are processed in order, while messages
|
|
143
|
+
* with different ordering keys can be processed in parallel.
|
|
144
|
+
*
|
|
145
|
+
* Set this to `true` only if your message queue implementation supports
|
|
146
|
+
* the `orderingKey` option.
|
|
147
|
+
*
|
|
148
|
+
* @default false
|
|
149
|
+
*/
|
|
142
150
|
readonly testOrderingKey?: boolean;
|
|
143
151
|
}
|
|
144
152
|
/**
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
153
|
+
* Tests a {@link MessageQueue} implementation with a standard set of tests.
|
|
154
|
+
*
|
|
155
|
+
* This function runs tests for:
|
|
156
|
+
* - `enqueue()`: Basic message enqueueing
|
|
157
|
+
* - `enqueue()` with delay: Delayed message enqueueing
|
|
158
|
+
* - `enqueueMany()`: Bulk message enqueueing
|
|
159
|
+
* - `enqueueMany()` with delay: Delayed bulk message enqueueing
|
|
160
|
+
* - Multiple listeners: Ensures messages are processed by only one listener
|
|
161
|
+
* - Ordering key support (optional): Ensures messages with the same ordering
|
|
162
|
+
* key are processed in order
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```typescript ignore
|
|
166
|
+
* import { test } from "@fedify/fixture";
|
|
167
|
+
* import { testMessageQueue } from "@fedify/testing";
|
|
168
|
+
* import { MyMessageQueue } from "./my-mq.ts";
|
|
169
|
+
*
|
|
170
|
+
* test("MyMessageQueue", () =>
|
|
171
|
+
* testMessageQueue(
|
|
172
|
+
* () => new MyMessageQueue(),
|
|
173
|
+
* async ({ mq1, mq2, controller }) => {
|
|
174
|
+
* controller.abort();
|
|
175
|
+
* await mq1.close();
|
|
176
|
+
* await mq2.close();
|
|
177
|
+
* },
|
|
178
|
+
* { testOrderingKey: true }, // Enable ordering key tests
|
|
179
|
+
* )
|
|
180
|
+
* );
|
|
181
|
+
* ```
|
|
182
|
+
*
|
|
183
|
+
* @param getMessageQueue A factory function that creates a new message queue
|
|
184
|
+
* instance. It should return a new instance each time
|
|
185
|
+
* to ensure test isolation, but both instances should
|
|
186
|
+
* share the same underlying storage/channel.
|
|
187
|
+
* @param onFinally A cleanup function called after all tests complete.
|
|
188
|
+
* It receives both message queue instances and the abort
|
|
189
|
+
* controller used for the listeners.
|
|
190
|
+
* @param options Optional configuration for the test suite.
|
|
191
|
+
* @returns A promise that resolves when all tests pass.
|
|
192
|
+
*/
|
|
185
193
|
declare function testMessageQueue<MQ extends MessageQueue>(getMessageQueue: () => MQ | Promise<MQ>, onFinally: ({
|
|
186
194
|
mq1,
|
|
187
195
|
mq2,
|
package/dist/mod.d.ts
CHANGED
|
@@ -4,48 +4,51 @@ import { Context, Federation, InboxContext, RequestContext } from "@fedify/fedif
|
|
|
4
4
|
import { MessageQueue } from "@fedify/fedify";
|
|
5
5
|
|
|
6
6
|
//#region src/context.d.ts
|
|
7
|
+
// NOTE: Copied from @fedify/fedify/testing/context.ts
|
|
8
|
+
// Not exported - used internally only. Public API is in mock.ts
|
|
7
9
|
declare function createContext<TContextData>(values: Partial<Context<TContextData>> & {
|
|
8
10
|
url?: URL;
|
|
9
11
|
data: TContextData;
|
|
10
12
|
federation: Federation<TContextData>;
|
|
11
13
|
}): Context<TContextData>;
|
|
12
14
|
/**
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
* Creates a RequestContext for testing purposes.
|
|
16
|
+
* Not exported - used internally only. Public API is in mock.ts
|
|
17
|
+
* @param args Partial RequestContext properties
|
|
18
|
+
* @returns A RequestContext instance
|
|
19
|
+
* @since 1.8.0
|
|
20
|
+
*/
|
|
19
21
|
declare function createRequestContext<TContextData>(args: Partial<RequestContext<TContextData>> & {
|
|
20
22
|
url: URL;
|
|
21
23
|
data: TContextData;
|
|
22
24
|
federation: Federation<TContextData>;
|
|
23
25
|
}): RequestContext<TContextData>;
|
|
24
26
|
/**
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
* Test-specific InboxContext type alias.
|
|
28
|
+
* This indirection helps avoid JSR type analyzer issues.
|
|
29
|
+
* @since 1.9.1
|
|
30
|
+
*/
|
|
29
31
|
type TestInboxContext<TContextData> = InboxContext<TContextData>;
|
|
30
32
|
/**
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
* Creates an InboxContext for testing purposes.
|
|
34
|
+
* Not exported - used internally only. Public API is in mock.ts
|
|
35
|
+
* @param args Partial InboxContext properties
|
|
36
|
+
* @returns An InboxContext instance
|
|
37
|
+
* @since 1.8.0
|
|
38
|
+
*/
|
|
37
39
|
declare function createInboxContext<TContextData>(args: Partial<InboxContext<TContextData>> & {
|
|
38
40
|
url?: URL;
|
|
39
41
|
data: TContextData;
|
|
40
42
|
recipient?: string | null;
|
|
41
43
|
federation: Federation<TContextData>;
|
|
42
44
|
}): TestInboxContext<TContextData>;
|
|
45
|
+
// Export for internal use by mock.ts only
|
|
43
46
|
//#endregion
|
|
44
47
|
//#region src/mock.d.ts
|
|
45
48
|
/**
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
+
* Represents a sent activity with metadata about how it was sent.
|
|
50
|
+
* @since 1.8.0
|
|
51
|
+
*/
|
|
49
52
|
interface SentActivity {
|
|
50
53
|
/** Whether the activity was queued or sent immediately. */
|
|
51
54
|
queued: boolean;
|
|
@@ -57,12 +60,14 @@ interface SentActivity {
|
|
|
57
60
|
sentOrder: number;
|
|
58
61
|
}
|
|
59
62
|
/**
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
63
|
+
* A mock Context interface for testing purposes.
|
|
64
|
+
* Extends the standard Context interface with additional testing utilities.
|
|
65
|
+
* @since 1.9.1
|
|
66
|
+
*/
|
|
64
67
|
interface TestContext<TContextData> extends Omit<Context<TContextData>, "clone">, Pick<RequestContext<TContextData>, "request" | "url" | "getActor" | "getObject" | "getSignedKey" | "getSignedKeyOwner" | "sendActivity" | "routeActivity"> {
|
|
68
|
+
// Override clone to return TestContext
|
|
65
69
|
clone(data: TContextData): TestContext<TContextData>;
|
|
70
|
+
// Test-specific methods
|
|
66
71
|
getSentActivities(): Array<{
|
|
67
72
|
sender: any;
|
|
68
73
|
recipients: any;
|
|
@@ -71,54 +76,57 @@ interface TestContext<TContextData> extends Omit<Context<TContextData>, "clone">
|
|
|
71
76
|
reset(): void;
|
|
72
77
|
}
|
|
73
78
|
/**
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
79
|
+
* A mock Federation interface for testing purposes.
|
|
80
|
+
* Extends the standard Federation interface with additional testing utilities.
|
|
81
|
+
* @since 1.9.1
|
|
82
|
+
*/
|
|
78
83
|
interface TestFederation<TContextData> extends Omit<Federation<TContextData>, "createContext"> {
|
|
84
|
+
// Test-specific properties
|
|
79
85
|
sentActivities: SentActivity[];
|
|
80
86
|
queueStarted: boolean;
|
|
81
87
|
sentCounter: number;
|
|
88
|
+
// Test-specific methods
|
|
82
89
|
receiveActivity(activity: Activity): Promise<void>;
|
|
83
90
|
reset(): void;
|
|
91
|
+
// Override createContext to return TestContext
|
|
84
92
|
createContext(baseUrlOrRequest: URL | Request, contextData: TContextData): TestContext<TContextData>;
|
|
85
93
|
}
|
|
86
94
|
/**
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
95
|
+
* Creates a mock Federation instance for testing purposes.
|
|
96
|
+
*
|
|
97
|
+
* @template TContextData The type of context data to use
|
|
98
|
+
* @param options Optional configuration for the mock federation
|
|
99
|
+
* @returns A Federation instance that can be used for testing
|
|
100
|
+
* @since 1.9.1
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```typescript
|
|
104
|
+
* import { Create } from "@fedify/vocab";
|
|
105
|
+
* import { createFederation } from "@fedify/testing";
|
|
106
|
+
*
|
|
107
|
+
* // Create a mock federation with contextData
|
|
108
|
+
* const federation = createFederation<{ userId: string }>({
|
|
109
|
+
* contextData: { userId: "test-user" }
|
|
110
|
+
* });
|
|
111
|
+
*
|
|
112
|
+
* // Set up inbox listeners
|
|
113
|
+
* federation
|
|
114
|
+
* .setInboxListeners("/users/{identifier}/inbox")
|
|
115
|
+
* .on(Create, async (ctx, activity) => {
|
|
116
|
+
* console.log("Received:", activity);
|
|
117
|
+
* });
|
|
118
|
+
*
|
|
119
|
+
* // Simulate receiving an activity
|
|
120
|
+
* const createActivity = new Create({
|
|
121
|
+
* id: new URL("https://example.com/create/1"),
|
|
122
|
+
* actor: new URL("https://example.com/users/alice")
|
|
123
|
+
* });
|
|
124
|
+
* await federation.receiveActivity(createActivity);
|
|
125
|
+
*
|
|
126
|
+
* // Check sent activities
|
|
127
|
+
* console.log(federation.sentActivities);
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
122
130
|
declare function createFederation<TContextData>(options?: {
|
|
123
131
|
contextData?: TContextData;
|
|
124
132
|
origin?: string;
|
|
@@ -127,62 +135,62 @@ declare function createFederation<TContextData>(options?: {
|
|
|
127
135
|
//#endregion
|
|
128
136
|
//#region src/mq-tester.d.ts
|
|
129
137
|
/**
|
|
130
|
-
|
|
131
|
-
|
|
138
|
+
* Options for {@link testMessageQueue}.
|
|
139
|
+
*/
|
|
132
140
|
interface TestMessageQueueOptions {
|
|
133
141
|
/**
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
142
|
+
* Whether to test ordering key support. If `true`, tests will verify that
|
|
143
|
+
* messages with the same ordering key are processed in order, while messages
|
|
144
|
+
* with different ordering keys can be processed in parallel.
|
|
145
|
+
*
|
|
146
|
+
* Set this to `true` only if your message queue implementation supports
|
|
147
|
+
* the `orderingKey` option.
|
|
148
|
+
*
|
|
149
|
+
* @default false
|
|
150
|
+
*/
|
|
143
151
|
readonly testOrderingKey?: boolean;
|
|
144
152
|
}
|
|
145
153
|
/**
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
154
|
+
* Tests a {@link MessageQueue} implementation with a standard set of tests.
|
|
155
|
+
*
|
|
156
|
+
* This function runs tests for:
|
|
157
|
+
* - `enqueue()`: Basic message enqueueing
|
|
158
|
+
* - `enqueue()` with delay: Delayed message enqueueing
|
|
159
|
+
* - `enqueueMany()`: Bulk message enqueueing
|
|
160
|
+
* - `enqueueMany()` with delay: Delayed bulk message enqueueing
|
|
161
|
+
* - Multiple listeners: Ensures messages are processed by only one listener
|
|
162
|
+
* - Ordering key support (optional): Ensures messages with the same ordering
|
|
163
|
+
* key are processed in order
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* ```typescript ignore
|
|
167
|
+
* import { test } from "@fedify/fixture";
|
|
168
|
+
* import { testMessageQueue } from "@fedify/testing";
|
|
169
|
+
* import { MyMessageQueue } from "./my-mq.ts";
|
|
170
|
+
*
|
|
171
|
+
* test("MyMessageQueue", () =>
|
|
172
|
+
* testMessageQueue(
|
|
173
|
+
* () => new MyMessageQueue(),
|
|
174
|
+
* async ({ mq1, mq2, controller }) => {
|
|
175
|
+
* controller.abort();
|
|
176
|
+
* await mq1.close();
|
|
177
|
+
* await mq2.close();
|
|
178
|
+
* },
|
|
179
|
+
* { testOrderingKey: true }, // Enable ordering key tests
|
|
180
|
+
* )
|
|
181
|
+
* );
|
|
182
|
+
* ```
|
|
183
|
+
*
|
|
184
|
+
* @param getMessageQueue A factory function that creates a new message queue
|
|
185
|
+
* instance. It should return a new instance each time
|
|
186
|
+
* to ensure test isolation, but both instances should
|
|
187
|
+
* share the same underlying storage/channel.
|
|
188
|
+
* @param onFinally A cleanup function called after all tests complete.
|
|
189
|
+
* It receives both message queue instances and the abort
|
|
190
|
+
* controller used for the listeners.
|
|
191
|
+
* @param options Optional configuration for the test suite.
|
|
192
|
+
* @returns A promise that resolves when all tests pass.
|
|
193
|
+
*/
|
|
186
194
|
declare function testMessageQueue<MQ extends MessageQueue>(getMessageQueue: () => MQ | Promise<MQ>, onFinally: ({
|
|
187
195
|
mq1,
|
|
188
196
|
mq2,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fedify/testing",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2-dev.407+6f4b2e28",
|
|
4
4
|
"description": "Testing utilities for Fedify applications",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fedify",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"package.json"
|
|
51
51
|
],
|
|
52
52
|
"peerDependencies": {
|
|
53
|
-
"@fedify/fedify": "^2.0.
|
|
53
|
+
"@fedify/fedify": "^2.0.2-dev.407+6f4b2e28"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"es-toolkit": "1.43.0"
|