@fedify/testing 2.4.0-pr.936.41 → 2.5.0-dev.2271
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 +27 -0
- package/dist/mod.cjs +586 -173
- package/dist/mod.d.cts +72 -6
- package/dist/mod.d.ts +72 -6
- package/dist/mod.js +476 -71
- package/package.json +5 -3
package/dist/mod.d.cts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/// <reference lib="esnext.temporal" />
|
|
2
|
-
import { Context, Federation, InboxContext, OutboxContext, RequestContext } from "@fedify/fedify/federation";
|
|
2
|
+
import { Context, Federation, InboxContext, OutboxContext, PortableRequest, RequestContext } from "@fedify/fedify/federation";
|
|
3
3
|
import { Activity } from "@fedify/vocab";
|
|
4
|
-
import {
|
|
4
|
+
import { DocumentLoader, PortableObjectVerifier } from "@fedify/vocab-runtime";
|
|
5
|
+
import { KvStore, MessageQueue } from "@fedify/fedify";
|
|
5
6
|
|
|
6
7
|
//#region src/context.d.ts
|
|
7
8
|
declare function createContext<TContextData>(values: Partial<Context<TContextData>> & {
|
|
@@ -22,6 +23,10 @@ declare function createRequestContext<TContextData>(args: Partial<RequestContext
|
|
|
22
23
|
federation: Federation<TContextData>;
|
|
23
24
|
}): RequestContext<TContextData>;
|
|
24
25
|
/**
|
|
26
|
+
* The default implementation of `RequestContext.isSignedByAudience()` for
|
|
27
|
+
* testing, which checks the audience against `getSignedKeyOwner()`.
|
|
28
|
+
*/
|
|
29
|
+
/**
|
|
25
30
|
* Test-specific InboxContext type alias.
|
|
26
31
|
* This indirection helps avoid JSR type analyzer issues.
|
|
27
32
|
* @since 1.9.1
|
|
@@ -82,7 +87,7 @@ interface SentActivity {
|
|
|
82
87
|
* Extends the standard Context interface with additional testing utilities.
|
|
83
88
|
* @since 1.9.1
|
|
84
89
|
*/
|
|
85
|
-
interface TestContext<TContextData> extends Omit<Context<TContextData>, "clone">, Pick<RequestContext<TContextData>, "request" | "url" | "getActor" | "getObject" | "getSignedKey" | "getSignedKeyOwner" | "sendActivity" | "routeActivity"> {
|
|
90
|
+
interface TestContext<TContextData> extends Omit<Context<TContextData>, "clone">, Pick<RequestContext<TContextData>, "request" | "url" | "portableRequest" | "getActor" | "getObject" | "getSignedKey" | "getSignedKeyOwner" | "isSignedByAudience" | "sendActivity" | "routeActivity"> {
|
|
86
91
|
clone(data: TContextData): TestContext<TContextData>;
|
|
87
92
|
getSentActivities(): Array<{
|
|
88
93
|
sender: any;
|
|
@@ -104,7 +109,13 @@ interface TestFederation<TContextData> extends Omit<Federation<TContextData>, "c
|
|
|
104
109
|
receiveActivity(activity: Activity): Promise<void>;
|
|
105
110
|
postOutboxActivity(identifier: string, activity: Activity): Promise<void>;
|
|
106
111
|
reset(): void;
|
|
107
|
-
createContext(
|
|
112
|
+
createContext(baseUrl: URL, contextData: TContextData): TestContext<TContextData>;
|
|
113
|
+
createContext(request: Request, contextData: TContextData, options?: {
|
|
114
|
+
portableRequest?: PortableRequest;
|
|
115
|
+
}): TestContext<TContextData>;
|
|
116
|
+
createContext(baseUrlOrRequest: URL | Request, contextData: TContextData, options?: {
|
|
117
|
+
portableRequest?: PortableRequest;
|
|
118
|
+
}): TestContext<TContextData>;
|
|
108
119
|
}
|
|
109
120
|
/**
|
|
110
121
|
* Creates a mock Federation instance for testing purposes.
|
|
@@ -150,9 +161,64 @@ declare function createFederation<TContextData>(options?: {
|
|
|
150
161
|
* @since 2.3.0
|
|
151
162
|
*/
|
|
152
163
|
meterProvider?: any;
|
|
153
|
-
tracerProvider?: any;
|
|
164
|
+
tracerProvider?: any; /** The document loader used by mock context lookups. @since 2.4.0 */
|
|
165
|
+
documentLoader?: DocumentLoader; /** The JSON-LD context loader used by mock context lookups. @since 2.4.0 */
|
|
166
|
+
contextLoader?: DocumentLoader;
|
|
167
|
+
/**
|
|
168
|
+
* The portable object verifier used by mock context lookups when a
|
|
169
|
+
* document loader is provided. Mock collection traversal remains empty.
|
|
170
|
+
* @since 2.4.0
|
|
171
|
+
*/
|
|
172
|
+
verifyPortableObject?: PortableObjectVerifier;
|
|
154
173
|
}): TestFederation<TContextData>;
|
|
155
174
|
//#endregion
|
|
175
|
+
//#region src/kv-tester.d.ts
|
|
176
|
+
/**
|
|
177
|
+
* Options for {@link testKvStore}.
|
|
178
|
+
*/
|
|
179
|
+
interface TestKvStoreOptions {
|
|
180
|
+
/**
|
|
181
|
+
* Whether to test compare-and-swap support. By default, these tests run
|
|
182
|
+
* when the store implements {@link KvStore.cas}.
|
|
183
|
+
*/
|
|
184
|
+
readonly testCas?: boolean;
|
|
185
|
+
/**
|
|
186
|
+
* Whether to test time-to-live support. `true` by default.
|
|
187
|
+
* @default true
|
|
188
|
+
*/
|
|
189
|
+
readonly testTtl?: boolean;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Tests a {@link KvStore} implementation with a standard set of tests.
|
|
193
|
+
*
|
|
194
|
+
* The suite covers reads and writes, deletion, structured keys and values,
|
|
195
|
+
* prefix listing, TTL expiration, and optional compare-and-swap behavior.
|
|
196
|
+
* Every key is isolated below a random prefix and is deleted after the suite.
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* ```typescript ignore
|
|
200
|
+
* import { test } from "@fedify/fixture";
|
|
201
|
+
* import { testKvStore } from "@fedify/testing";
|
|
202
|
+
* import { MyKvStore } from "./my-kv.ts";
|
|
203
|
+
*
|
|
204
|
+
* test("MyKvStore", () =>
|
|
205
|
+
* testKvStore(
|
|
206
|
+
* () => new MyKvStore(),
|
|
207
|
+
* async ({ store }) => await store.close(),
|
|
208
|
+
* )
|
|
209
|
+
* );
|
|
210
|
+
* ```
|
|
211
|
+
*
|
|
212
|
+
* @param getKvStore A factory that creates the store to test.
|
|
213
|
+
* @param onFinally A cleanup function called after the suite completes.
|
|
214
|
+
* @param options Optional configuration for the suite.
|
|
215
|
+
*/
|
|
216
|
+
declare function testKvStore<KV extends KvStore>(getKvStore: () => KV | Promise<KV>, onFinally: ({
|
|
217
|
+
store
|
|
218
|
+
}: {
|
|
219
|
+
store: KV;
|
|
220
|
+
}) => Promise<void> | void, options?: TestKvStoreOptions): Promise<void>;
|
|
221
|
+
//#endregion
|
|
156
222
|
//#region src/mq-tester.d.ts
|
|
157
223
|
/**
|
|
158
224
|
* Options for {@link testMessageQueue}.
|
|
@@ -223,4 +289,4 @@ declare function testMessageQueue<MQ extends MessageQueue>(getMessageQueue: () =
|
|
|
223
289
|
declare function waitFor(predicate: () => boolean, timeoutMs: number): Promise<void>;
|
|
224
290
|
declare const getRandomKey: (prefix: string) => string;
|
|
225
291
|
//#endregion
|
|
226
|
-
export { type TestMessageQueueOptions, createContext, createFederation, createInboxContext, createOutboxContext, createRequestContext, getRandomKey, testMessageQueue, waitFor };
|
|
292
|
+
export { type TestKvStoreOptions, type TestMessageQueueOptions, createContext, createFederation, createInboxContext, createOutboxContext, createRequestContext, getRandomKey, testKvStore, testMessageQueue, waitFor };
|
package/dist/mod.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/// <reference lib="esnext.temporal" />
|
|
2
2
|
import { Activity } from "@fedify/vocab";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { DocumentLoader, PortableObjectVerifier } from "@fedify/vocab-runtime";
|
|
4
|
+
import { Context, Federation, InboxContext, OutboxContext, PortableRequest, RequestContext } from "@fedify/fedify/federation";
|
|
5
|
+
import { KvStore, MessageQueue } from "@fedify/fedify";
|
|
5
6
|
|
|
6
7
|
//#region src/context.d.ts
|
|
7
8
|
declare function createContext<TContextData>(values: Partial<Context<TContextData>> & {
|
|
@@ -22,6 +23,10 @@ declare function createRequestContext<TContextData>(args: Partial<RequestContext
|
|
|
22
23
|
federation: Federation<TContextData>;
|
|
23
24
|
}): RequestContext<TContextData>;
|
|
24
25
|
/**
|
|
26
|
+
* The default implementation of `RequestContext.isSignedByAudience()` for
|
|
27
|
+
* testing, which checks the audience against `getSignedKeyOwner()`.
|
|
28
|
+
*/
|
|
29
|
+
/**
|
|
25
30
|
* Test-specific InboxContext type alias.
|
|
26
31
|
* This indirection helps avoid JSR type analyzer issues.
|
|
27
32
|
* @since 1.9.1
|
|
@@ -82,7 +87,7 @@ interface SentActivity {
|
|
|
82
87
|
* Extends the standard Context interface with additional testing utilities.
|
|
83
88
|
* @since 1.9.1
|
|
84
89
|
*/
|
|
85
|
-
interface TestContext<TContextData> extends Omit<Context<TContextData>, "clone">, Pick<RequestContext<TContextData>, "request" | "url" | "getActor" | "getObject" | "getSignedKey" | "getSignedKeyOwner" | "sendActivity" | "routeActivity"> {
|
|
90
|
+
interface TestContext<TContextData> extends Omit<Context<TContextData>, "clone">, Pick<RequestContext<TContextData>, "request" | "url" | "portableRequest" | "getActor" | "getObject" | "getSignedKey" | "getSignedKeyOwner" | "isSignedByAudience" | "sendActivity" | "routeActivity"> {
|
|
86
91
|
clone(data: TContextData): TestContext<TContextData>;
|
|
87
92
|
getSentActivities(): Array<{
|
|
88
93
|
sender: any;
|
|
@@ -104,7 +109,13 @@ interface TestFederation<TContextData> extends Omit<Federation<TContextData>, "c
|
|
|
104
109
|
receiveActivity(activity: Activity): Promise<void>;
|
|
105
110
|
postOutboxActivity(identifier: string, activity: Activity): Promise<void>;
|
|
106
111
|
reset(): void;
|
|
107
|
-
createContext(
|
|
112
|
+
createContext(baseUrl: URL, contextData: TContextData): TestContext<TContextData>;
|
|
113
|
+
createContext(request: Request, contextData: TContextData, options?: {
|
|
114
|
+
portableRequest?: PortableRequest;
|
|
115
|
+
}): TestContext<TContextData>;
|
|
116
|
+
createContext(baseUrlOrRequest: URL | Request, contextData: TContextData, options?: {
|
|
117
|
+
portableRequest?: PortableRequest;
|
|
118
|
+
}): TestContext<TContextData>;
|
|
108
119
|
}
|
|
109
120
|
/**
|
|
110
121
|
* Creates a mock Federation instance for testing purposes.
|
|
@@ -150,9 +161,64 @@ declare function createFederation<TContextData>(options?: {
|
|
|
150
161
|
* @since 2.3.0
|
|
151
162
|
*/
|
|
152
163
|
meterProvider?: any;
|
|
153
|
-
tracerProvider?: any;
|
|
164
|
+
tracerProvider?: any; /** The document loader used by mock context lookups. @since 2.4.0 */
|
|
165
|
+
documentLoader?: DocumentLoader; /** The JSON-LD context loader used by mock context lookups. @since 2.4.0 */
|
|
166
|
+
contextLoader?: DocumentLoader;
|
|
167
|
+
/**
|
|
168
|
+
* The portable object verifier used by mock context lookups when a
|
|
169
|
+
* document loader is provided. Mock collection traversal remains empty.
|
|
170
|
+
* @since 2.4.0
|
|
171
|
+
*/
|
|
172
|
+
verifyPortableObject?: PortableObjectVerifier;
|
|
154
173
|
}): TestFederation<TContextData>;
|
|
155
174
|
//#endregion
|
|
175
|
+
//#region src/kv-tester.d.ts
|
|
176
|
+
/**
|
|
177
|
+
* Options for {@link testKvStore}.
|
|
178
|
+
*/
|
|
179
|
+
interface TestKvStoreOptions {
|
|
180
|
+
/**
|
|
181
|
+
* Whether to test compare-and-swap support. By default, these tests run
|
|
182
|
+
* when the store implements {@link KvStore.cas}.
|
|
183
|
+
*/
|
|
184
|
+
readonly testCas?: boolean;
|
|
185
|
+
/**
|
|
186
|
+
* Whether to test time-to-live support. `true` by default.
|
|
187
|
+
* @default true
|
|
188
|
+
*/
|
|
189
|
+
readonly testTtl?: boolean;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Tests a {@link KvStore} implementation with a standard set of tests.
|
|
193
|
+
*
|
|
194
|
+
* The suite covers reads and writes, deletion, structured keys and values,
|
|
195
|
+
* prefix listing, TTL expiration, and optional compare-and-swap behavior.
|
|
196
|
+
* Every key is isolated below a random prefix and is deleted after the suite.
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* ```typescript ignore
|
|
200
|
+
* import { test } from "@fedify/fixture";
|
|
201
|
+
* import { testKvStore } from "@fedify/testing";
|
|
202
|
+
* import { MyKvStore } from "./my-kv.ts";
|
|
203
|
+
*
|
|
204
|
+
* test("MyKvStore", () =>
|
|
205
|
+
* testKvStore(
|
|
206
|
+
* () => new MyKvStore(),
|
|
207
|
+
* async ({ store }) => await store.close(),
|
|
208
|
+
* )
|
|
209
|
+
* );
|
|
210
|
+
* ```
|
|
211
|
+
*
|
|
212
|
+
* @param getKvStore A factory that creates the store to test.
|
|
213
|
+
* @param onFinally A cleanup function called after the suite completes.
|
|
214
|
+
* @param options Optional configuration for the suite.
|
|
215
|
+
*/
|
|
216
|
+
declare function testKvStore<KV extends KvStore>(getKvStore: () => KV | Promise<KV>, onFinally: ({
|
|
217
|
+
store
|
|
218
|
+
}: {
|
|
219
|
+
store: KV;
|
|
220
|
+
}) => Promise<void> | void, options?: TestKvStoreOptions): Promise<void>;
|
|
221
|
+
//#endregion
|
|
156
222
|
//#region src/mq-tester.d.ts
|
|
157
223
|
/**
|
|
158
224
|
* Options for {@link testMessageQueue}.
|
|
@@ -223,4 +289,4 @@ declare function testMessageQueue<MQ extends MessageQueue>(getMessageQueue: () =
|
|
|
223
289
|
declare function waitFor(predicate: () => boolean, timeoutMs: number): Promise<void>;
|
|
224
290
|
declare const getRandomKey: (prefix: string) => string;
|
|
225
291
|
//#endregion
|
|
226
|
-
export { type TestMessageQueueOptions, createContext, createFederation, createInboxContext, createOutboxContext, createRequestContext, getRandomKey, testMessageQueue, waitFor };
|
|
292
|
+
export { type TestKvStoreOptions, type TestMessageQueueOptions, createContext, createFederation, createInboxContext, createOutboxContext, createRequestContext, getRandomKey, testKvStore, testMessageQueue, waitFor };
|