@backstage/test-utils 1.2.3-next.0 → 1.2.3-next.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.
- package/CHANGELOG.md +30 -0
- package/alpha/package.json +6 -0
- package/dist/index.alpha.d.ts +526 -0
- package/dist/index.beta.d.ts +522 -0
- package/dist/index.d.ts +261 -202
- package/dist/index.esm.js +31 -21
- package/dist/index.esm.js.map +1 -1
- package/package.json +14 -12
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,86 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Utilities to test Backstage plugins and apps.
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { AnalyticsApi } from '@backstage/core-plugin-api';
|
|
8
|
+
import { AnalyticsEvent } from '@backstage/core-plugin-api';
|
|
9
|
+
import { ApiHolder } from '@backstage/core-plugin-api';
|
|
10
|
+
import { ApiRef } from '@backstage/core-plugin-api';
|
|
11
|
+
import { AuthorizeResult } from '@backstage/plugin-permission-common';
|
|
12
|
+
import { ComponentType } from 'react';
|
|
2
13
|
import { Config } from '@backstage/config';
|
|
3
|
-
import {
|
|
14
|
+
import { ConfigApi } from '@backstage/core-plugin-api';
|
|
4
15
|
import crossFetch from 'cross-fetch';
|
|
16
|
+
import { DiscoveryApi } from '@backstage/core-plugin-api';
|
|
17
|
+
import { ErrorApi } from '@backstage/core-plugin-api';
|
|
18
|
+
import { ErrorApiError } from '@backstage/core-plugin-api';
|
|
19
|
+
import { ErrorApiErrorContext } from '@backstage/core-plugin-api';
|
|
20
|
+
import { EvaluatePermissionRequest } from '@backstage/plugin-permission-common';
|
|
21
|
+
import { EvaluatePermissionResponse } from '@backstage/plugin-permission-common';
|
|
22
|
+
import { ExternalRouteRef } from '@backstage/core-plugin-api';
|
|
23
|
+
import { FetchApi } from '@backstage/core-plugin-api';
|
|
24
|
+
import { IdentityApi } from '@backstage/core-plugin-api';
|
|
25
|
+
import { JsonObject } from '@backstage/types';
|
|
26
|
+
import { JsonValue } from '@backstage/types';
|
|
27
|
+
import { MatcherFunction } from '@testing-library/react';
|
|
28
|
+
import { Observable } from '@backstage/types';
|
|
5
29
|
import { PermissionApi } from '@backstage/plugin-permission-react';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
30
|
+
import { PropsWithChildren } from 'react';
|
|
31
|
+
import { ReactElement } from 'react';
|
|
32
|
+
import { ReactNode } from 'react';
|
|
33
|
+
import { RenderOptions } from '@testing-library/react';
|
|
34
|
+
import { RenderResult } from '@testing-library/react';
|
|
35
|
+
import { RouteRef } from '@backstage/core-plugin-api';
|
|
36
|
+
import { StorageApi } from '@backstage/core-plugin-api';
|
|
37
|
+
import { StorageValueSnapshot } from '@backstage/core-plugin-api';
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* AsyncLogCollector type used in {@link (withLogCollector:1)} callback function.
|
|
41
|
+
* @public
|
|
42
|
+
*/
|
|
43
|
+
export declare type AsyncLogCollector = () => Promise<void>;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Map of severity level and corresponding log lines.
|
|
47
|
+
* @public
|
|
48
|
+
*/
|
|
49
|
+
export declare type CollectedLogs<T extends LogFuncs> = {
|
|
50
|
+
[key in T]: string[];
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Creates a Wrapper component that wraps a component inside a Backstage test app,
|
|
55
|
+
* providing a mocked theme and app context, along with mocked APIs.
|
|
56
|
+
*
|
|
57
|
+
* @param options - Additional options for the rendering.
|
|
58
|
+
* @public
|
|
59
|
+
*/
|
|
60
|
+
export declare function createTestAppWrapper(options?: TestAppOptions): (props: {
|
|
61
|
+
children: ReactNode;
|
|
62
|
+
}) => JSX.Element;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* ErrorWithContext contains error and ErrorApiErrorContext
|
|
66
|
+
* @public
|
|
67
|
+
*/
|
|
68
|
+
export declare type ErrorWithContext = {
|
|
69
|
+
error: ErrorApiError;
|
|
70
|
+
context?: ErrorApiErrorContext;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Union type used in {@link (withLogCollector:3)} callback function.
|
|
75
|
+
* @public
|
|
76
|
+
*/
|
|
77
|
+
export declare type LogCollector = AsyncLogCollector | SyncLogCollector;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Severity levels of {@link CollectedLogs}
|
|
81
|
+
* @public
|
|
82
|
+
*/
|
|
83
|
+
export declare type LogFuncs = 'log' | 'warn' | 'error';
|
|
9
84
|
|
|
10
85
|
/**
|
|
11
86
|
* Mock implementation of {@link core-plugin-api#AnalyticsApi} with helpers to ensure that events are sent correctly.
|
|
@@ -13,12 +88,28 @@ import { RenderResult, RenderOptions } from '@testing-library/react';
|
|
|
13
88
|
*
|
|
14
89
|
* @public
|
|
15
90
|
*/
|
|
16
|
-
declare class MockAnalyticsApi implements AnalyticsApi {
|
|
91
|
+
export declare class MockAnalyticsApi implements AnalyticsApi {
|
|
17
92
|
private events;
|
|
18
93
|
captureEvent(event: AnalyticsEvent): void;
|
|
19
94
|
getEvents(): AnalyticsEvent[];
|
|
20
95
|
}
|
|
21
96
|
|
|
97
|
+
/**
|
|
98
|
+
* This is a mocking method suggested in the Jest docs, as it is not implemented in JSDOM yet.
|
|
99
|
+
* It can be used to mock values for the MUI `useMediaQuery` hook if it is used in a tested component.
|
|
100
|
+
*
|
|
101
|
+
* For issues checkout the documentation:
|
|
102
|
+
* https://jestjs.io/docs/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom
|
|
103
|
+
*
|
|
104
|
+
* If there are any updates from MUI React on testing `useMediaQuery` this mock should be replaced
|
|
105
|
+
* https://material-ui.com/components/use-media-query/#testing
|
|
106
|
+
*
|
|
107
|
+
* @public
|
|
108
|
+
*/
|
|
109
|
+
export declare function mockBreakpoint(options: {
|
|
110
|
+
matches: boolean;
|
|
111
|
+
}): void;
|
|
112
|
+
|
|
22
113
|
/**
|
|
23
114
|
* MockConfigApi is a thin wrapper around {@link @backstage/config#ConfigReader}
|
|
24
115
|
* that can be used to mock configuration using a plain object.
|
|
@@ -37,7 +128,7 @@ declare class MockAnalyticsApi implements AnalyticsApi {
|
|
|
37
128
|
* );
|
|
38
129
|
* ```
|
|
39
130
|
*/
|
|
40
|
-
declare class MockConfigApi implements ConfigApi {
|
|
131
|
+
export declare class MockConfigApi implements ConfigApi {
|
|
41
132
|
private readonly config;
|
|
42
133
|
constructor(data: JsonObject);
|
|
43
134
|
/** {@inheritdoc @backstage/config#Config.has} */
|
|
@@ -74,27 +165,12 @@ declare class MockConfigApi implements ConfigApi {
|
|
|
74
165
|
getOptionalStringArray(key: string): string[] | undefined;
|
|
75
166
|
}
|
|
76
167
|
|
|
77
|
-
/**
|
|
78
|
-
* Constructor arguments for {@link MockErrorApi}
|
|
79
|
-
* @public
|
|
80
|
-
*/
|
|
81
|
-
declare type MockErrorApiOptions = {
|
|
82
|
-
collect?: boolean;
|
|
83
|
-
};
|
|
84
|
-
/**
|
|
85
|
-
* ErrorWithContext contains error and ErrorApiErrorContext
|
|
86
|
-
* @public
|
|
87
|
-
*/
|
|
88
|
-
declare type ErrorWithContext = {
|
|
89
|
-
error: ErrorApiError;
|
|
90
|
-
context?: ErrorApiErrorContext;
|
|
91
|
-
};
|
|
92
168
|
/**
|
|
93
169
|
* Mock implementation of the {@link core-plugin-api#ErrorApi} to be used in tests.
|
|
94
170
|
* Includes withForError and getErrors methods for error testing.
|
|
95
171
|
* @public
|
|
96
172
|
*/
|
|
97
|
-
declare class MockErrorApi implements ErrorApi {
|
|
173
|
+
export declare class MockErrorApi implements ErrorApi {
|
|
98
174
|
private readonly options;
|
|
99
175
|
private readonly errors;
|
|
100
176
|
private readonly waiters;
|
|
@@ -108,12 +184,35 @@ declare class MockErrorApi implements ErrorApi {
|
|
|
108
184
|
waitForError(pattern: RegExp, timeoutMs?: number): Promise<ErrorWithContext>;
|
|
109
185
|
}
|
|
110
186
|
|
|
187
|
+
/**
|
|
188
|
+
* Constructor arguments for {@link MockErrorApi}
|
|
189
|
+
* @public
|
|
190
|
+
*/
|
|
191
|
+
export declare type MockErrorApiOptions = {
|
|
192
|
+
collect?: boolean;
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* A test helper implementation of {@link @backstage/core-plugin-api#FetchApi}.
|
|
197
|
+
*
|
|
198
|
+
* @public
|
|
199
|
+
*/
|
|
200
|
+
export declare class MockFetchApi implements FetchApi {
|
|
201
|
+
private readonly implementation;
|
|
202
|
+
/**
|
|
203
|
+
* Creates a mock {@link @backstage/core-plugin-api#FetchApi}.
|
|
204
|
+
*/
|
|
205
|
+
constructor(options?: MockFetchApiOptions);
|
|
206
|
+
/** {@inheritdoc @backstage/core-plugin-api#FetchApi.fetch} */
|
|
207
|
+
get fetch(): typeof crossFetch;
|
|
208
|
+
}
|
|
209
|
+
|
|
111
210
|
/**
|
|
112
211
|
* The options given when constructing a {@link MockFetchApi}.
|
|
113
212
|
*
|
|
114
213
|
* @public
|
|
115
214
|
*/
|
|
116
|
-
interface MockFetchApiOptions {
|
|
215
|
+
export declare interface MockFetchApiOptions {
|
|
117
216
|
/**
|
|
118
217
|
* Define the underlying base `fetch` implementation.
|
|
119
218
|
*
|
|
@@ -167,20 +266,6 @@ interface MockFetchApiOptions {
|
|
|
167
266
|
identityApi: Pick<IdentityApi, 'getCredentials'>;
|
|
168
267
|
};
|
|
169
268
|
}
|
|
170
|
-
/**
|
|
171
|
-
* A test helper implementation of {@link @backstage/core-plugin-api#FetchApi}.
|
|
172
|
-
*
|
|
173
|
-
* @public
|
|
174
|
-
*/
|
|
175
|
-
declare class MockFetchApi implements FetchApi {
|
|
176
|
-
private readonly implementation;
|
|
177
|
-
/**
|
|
178
|
-
* Creates a mock {@link @backstage/core-plugin-api#FetchApi}.
|
|
179
|
-
*/
|
|
180
|
-
constructor(options?: MockFetchApiOptions);
|
|
181
|
-
/** {@inheritdoc @backstage/core-plugin-api#FetchApi.fetch} */
|
|
182
|
-
get fetch(): typeof crossFetch;
|
|
183
|
-
}
|
|
184
269
|
|
|
185
270
|
/**
|
|
186
271
|
* Mock implementation of
|
|
@@ -189,24 +274,19 @@ declare class MockFetchApi implements FetchApi {
|
|
|
189
274
|
* request.
|
|
190
275
|
* @public
|
|
191
276
|
*/
|
|
192
|
-
declare class MockPermissionApi implements PermissionApi {
|
|
277
|
+
export declare class MockPermissionApi implements PermissionApi {
|
|
193
278
|
private readonly requestHandler;
|
|
194
279
|
constructor(requestHandler?: (request: EvaluatePermissionRequest) => AuthorizeResult.ALLOW | AuthorizeResult.DENY);
|
|
195
280
|
authorize(request: EvaluatePermissionRequest): Promise<EvaluatePermissionResponse>;
|
|
196
281
|
}
|
|
197
282
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
* @public
|
|
201
|
-
*/
|
|
202
|
-
declare type MockStorageBucket = {
|
|
203
|
-
[key: string]: any;
|
|
204
|
-
};
|
|
283
|
+
/* Excluded from this release type: MockPluginProvider */
|
|
284
|
+
|
|
205
285
|
/**
|
|
206
286
|
* Mock implementation of the {@link core-plugin-api#StorageApi} to be used in tests
|
|
207
287
|
* @public
|
|
208
288
|
*/
|
|
209
|
-
declare class MockStorageApi implements StorageApi {
|
|
289
|
+
export declare class MockStorageApi implements StorageApi {
|
|
210
290
|
private readonly namespace;
|
|
211
291
|
private readonly data;
|
|
212
292
|
private readonly bucketStorageApis;
|
|
@@ -224,67 +304,13 @@ declare class MockStorageApi implements StorageApi {
|
|
|
224
304
|
}
|
|
225
305
|
|
|
226
306
|
/**
|
|
227
|
-
*
|
|
228
|
-
* It can be used to mock values for the MUI `useMediaQuery` hook if it is used in a tested component.
|
|
229
|
-
*
|
|
230
|
-
* For issues checkout the documentation:
|
|
231
|
-
* https://jestjs.io/docs/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom
|
|
232
|
-
*
|
|
233
|
-
* If there are any updates from MUI React on testing `useMediaQuery` this mock should be replaced
|
|
234
|
-
* https://material-ui.com/components/use-media-query/#testing
|
|
235
|
-
*
|
|
236
|
-
* @public
|
|
237
|
-
*/
|
|
238
|
-
declare function mockBreakpoint(options: {
|
|
239
|
-
matches: boolean;
|
|
240
|
-
}): void;
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* Options to customize the behavior of the test app wrapper.
|
|
307
|
+
* Type for map holding data in {@link MockStorageApi}
|
|
244
308
|
* @public
|
|
245
309
|
*/
|
|
246
|
-
declare type
|
|
247
|
-
|
|
248
|
-
* Initial route entries to pass along as `initialEntries` to the router.
|
|
249
|
-
*/
|
|
250
|
-
routeEntries?: string[];
|
|
251
|
-
/**
|
|
252
|
-
* An object of paths to mount route ref on, with the key being the path and the value
|
|
253
|
-
* being the RouteRef that the path will be bound to. This allows the route refs to be
|
|
254
|
-
* used by `useRouteRef` in the rendered elements.
|
|
255
|
-
*
|
|
256
|
-
* @example
|
|
257
|
-
* wrapInTestApp(<MyComponent />, \{
|
|
258
|
-
* mountedRoutes: \{
|
|
259
|
-
* '/my-path': myRouteRef,
|
|
260
|
-
* \}
|
|
261
|
-
* \})
|
|
262
|
-
* // ...
|
|
263
|
-
* const link = useRouteRef(myRouteRef)
|
|
264
|
-
*/
|
|
265
|
-
mountedRoutes?: {
|
|
266
|
-
[path: string]: RouteRef | ExternalRouteRef;
|
|
267
|
-
};
|
|
310
|
+
export declare type MockStorageBucket = {
|
|
311
|
+
[key: string]: any;
|
|
268
312
|
};
|
|
269
|
-
|
|
270
|
-
* Creates a Wrapper component that wraps a component inside a Backstage test app,
|
|
271
|
-
* providing a mocked theme and app context, along with mocked APIs.
|
|
272
|
-
*
|
|
273
|
-
* @param options - Additional options for the rendering.
|
|
274
|
-
* @public
|
|
275
|
-
*/
|
|
276
|
-
declare function createTestAppWrapper(options?: TestAppOptions): (props: {
|
|
277
|
-
children: ReactNode;
|
|
278
|
-
}) => JSX.Element;
|
|
279
|
-
/**
|
|
280
|
-
* Wraps a component inside a Backstage test app, providing a mocked theme
|
|
281
|
-
* and app context, along with mocked APIs.
|
|
282
|
-
*
|
|
283
|
-
* @param Component - A component or react node to render inside the test app.
|
|
284
|
-
* @param options - Additional options for the rendering.
|
|
285
|
-
* @public
|
|
286
|
-
*/
|
|
287
|
-
declare function wrapInTestApp(Component: ComponentType | ReactNode, options?: TestAppOptions): ReactElement;
|
|
313
|
+
|
|
288
314
|
/**
|
|
289
315
|
* Renders a component inside a Backstage test app, providing a mocked theme
|
|
290
316
|
* and app context, along with mocked APIs.
|
|
@@ -296,96 +322,96 @@ declare function wrapInTestApp(Component: ComponentType | ReactNode, options?: T
|
|
|
296
322
|
* @param options - Additional options for the rendering.
|
|
297
323
|
* @public
|
|
298
324
|
*/
|
|
299
|
-
declare function renderInTestApp(Component: ComponentType | ReactNode, options?: TestAppOptions): Promise<RenderResult>;
|
|
325
|
+
export declare function renderInTestApp(Component: ComponentType | ReactNode, options?: TestAppOptions): Promise<RenderResult>;
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* @public
|
|
329
|
+
* Simplifies rendering of async components in by taking care of the wrapping inside act
|
|
330
|
+
*
|
|
331
|
+
* @remarks
|
|
332
|
+
*
|
|
333
|
+
* Components using useEffect to perform an asynchronous action (such as fetch) must be rendered within an async
|
|
334
|
+
* act call to properly get the final state, even with mocked responses. This utility method makes the signature a bit
|
|
335
|
+
* cleaner, since act doesn't return the result of the evaluated function.
|
|
336
|
+
* https://github.com/testing-library/react-testing-library/issues/281
|
|
337
|
+
* https://github.com/facebook/react/pull/14853
|
|
338
|
+
*/
|
|
339
|
+
export declare function renderWithEffects(nodes: ReactElement, options?: Pick<RenderOptions, 'wrapper'>): Promise<RenderResult>;
|
|
300
340
|
|
|
301
341
|
/**
|
|
302
342
|
* Sets up handlers for request mocking
|
|
303
343
|
* @public
|
|
304
344
|
* @param worker - service worker
|
|
305
345
|
*/
|
|
306
|
-
declare function setupRequestMockHandlers(worker: {
|
|
346
|
+
export declare function setupRequestMockHandlers(worker: {
|
|
307
347
|
listen: (t: any) => void;
|
|
308
348
|
close: () => void;
|
|
309
349
|
resetHandlers: () => void;
|
|
310
350
|
}): void;
|
|
311
351
|
|
|
312
|
-
/**
|
|
313
|
-
* Severity levels of {@link CollectedLogs}
|
|
314
|
-
* @public
|
|
315
|
-
*/
|
|
316
|
-
declare type LogFuncs = 'log' | 'warn' | 'error';
|
|
317
|
-
/**
|
|
318
|
-
* AsyncLogCollector type used in {@link (withLogCollector:1)} callback function.
|
|
319
|
-
* @public
|
|
320
|
-
*/
|
|
321
|
-
declare type AsyncLogCollector = () => Promise<void>;
|
|
322
352
|
/**
|
|
323
353
|
* SyncLogCollector type used in {@link (withLogCollector:2)} callback function.
|
|
324
354
|
* @public
|
|
325
355
|
*/
|
|
326
|
-
declare type SyncLogCollector = () => void;
|
|
327
|
-
/**
|
|
328
|
-
* Union type used in {@link (withLogCollector:3)} callback function.
|
|
329
|
-
* @public
|
|
330
|
-
*/
|
|
331
|
-
declare type LogCollector = AsyncLogCollector | SyncLogCollector;
|
|
332
|
-
/**
|
|
333
|
-
* Map of severity level and corresponding log lines.
|
|
334
|
-
* @public
|
|
335
|
-
*/
|
|
336
|
-
declare type CollectedLogs<T extends LogFuncs> = {
|
|
337
|
-
[key in T]: string[];
|
|
338
|
-
};
|
|
339
|
-
/**
|
|
340
|
-
* Asynchronous log collector with that collects all categories
|
|
341
|
-
* @public
|
|
342
|
-
*/
|
|
343
|
-
declare function withLogCollector(callback: AsyncLogCollector): Promise<CollectedLogs<LogFuncs>>;
|
|
344
|
-
/**
|
|
345
|
-
* Synchronous log collector with that collects all categories
|
|
346
|
-
* @public
|
|
347
|
-
*/
|
|
348
|
-
declare function withLogCollector(callback: SyncLogCollector): CollectedLogs<LogFuncs>;
|
|
349
|
-
/**
|
|
350
|
-
* Asynchronous log collector with that only collects selected categories
|
|
351
|
-
* @public
|
|
352
|
-
*/
|
|
353
|
-
declare function withLogCollector<T extends LogFuncs>(logsToCollect: T[], callback: AsyncLogCollector): Promise<CollectedLogs<T>>;
|
|
354
|
-
/**
|
|
355
|
-
* Synchronous log collector with that only collects selected categories
|
|
356
|
-
* @public
|
|
357
|
-
*/
|
|
358
|
-
declare function withLogCollector<T extends LogFuncs>(logsToCollect: T[], callback: SyncLogCollector): CollectedLogs<T>;
|
|
356
|
+
export declare type SyncLogCollector = () => void;
|
|
359
357
|
|
|
360
358
|
/**
|
|
361
|
-
*
|
|
362
|
-
*
|
|
359
|
+
* The `TestApiProvider` is a Utility API context provider that is particularly
|
|
360
|
+
* well suited for development and test environments such as unit tests, storybooks,
|
|
361
|
+
* and isolated plugin development setups.
|
|
363
362
|
*
|
|
364
|
-
*
|
|
363
|
+
* It lets you provide any number of API implementations, without necessarily
|
|
364
|
+
* having to fully implement each of the APIs.
|
|
365
365
|
*
|
|
366
|
-
*
|
|
367
|
-
*
|
|
368
|
-
*
|
|
369
|
-
*
|
|
370
|
-
*
|
|
371
|
-
|
|
372
|
-
|
|
366
|
+
* A migration from `ApiRegistry` and `ApiProvider` might look like this, from:
|
|
367
|
+
*
|
|
368
|
+
* ```tsx
|
|
369
|
+
* renderInTestApp(
|
|
370
|
+
* <ApiProvider
|
|
371
|
+
* apis={ApiRegistry.from([
|
|
372
|
+
* [identityApiRef, mockIdentityApi as unknown as IdentityApi]
|
|
373
|
+
* ])}
|
|
374
|
+
* >
|
|
375
|
+
* {...}
|
|
376
|
+
* </ApiProvider>
|
|
377
|
+
* )
|
|
378
|
+
* ```
|
|
379
|
+
*
|
|
380
|
+
* To the following:
|
|
381
|
+
*
|
|
382
|
+
* ```tsx
|
|
383
|
+
* renderInTestApp(
|
|
384
|
+
* <TestApiProvider apis={[[identityApiRef, mockIdentityApi]]}>
|
|
385
|
+
* {...}
|
|
386
|
+
* </TestApiProvider>
|
|
387
|
+
* )
|
|
388
|
+
* ```
|
|
389
|
+
*
|
|
390
|
+
* Note that the cast to `IdentityApi` is no longer needed as long as the mock API
|
|
391
|
+
* implements a subset of the `IdentityApi`.
|
|
392
|
+
*
|
|
393
|
+
* @public
|
|
394
|
+
**/
|
|
395
|
+
export declare const TestApiProvider: <T extends any[]>(props: TestApiProviderProps<T>) => JSX.Element;
|
|
373
396
|
|
|
374
|
-
/** @ignore */
|
|
375
|
-
declare type TestApiProviderPropsApiPair<TApi> = TApi extends infer TImpl ? readonly [ApiRef<TApi>, Partial<TImpl>] : never;
|
|
376
|
-
/** @ignore */
|
|
377
|
-
declare type TestApiProviderPropsApiPairs<TApiPairs> = {
|
|
378
|
-
[TIndex in keyof TApiPairs]: TestApiProviderPropsApiPair<TApiPairs[TIndex]>;
|
|
379
|
-
};
|
|
380
397
|
/**
|
|
381
398
|
* Properties for the {@link TestApiProvider} component.
|
|
382
399
|
*
|
|
383
400
|
* @public
|
|
384
401
|
*/
|
|
385
|
-
declare type TestApiProviderProps<TApiPairs extends any[]> = {
|
|
402
|
+
export declare type TestApiProviderProps<TApiPairs extends any[]> = {
|
|
386
403
|
apis: readonly [...TestApiProviderPropsApiPairs<TApiPairs>];
|
|
387
404
|
children: ReactNode;
|
|
388
405
|
};
|
|
406
|
+
|
|
407
|
+
/** @ignore */
|
|
408
|
+
declare type TestApiProviderPropsApiPair<TApi> = TApi extends infer TImpl ? readonly [ApiRef<TApi>, Partial<TImpl>] : never;
|
|
409
|
+
|
|
410
|
+
/** @ignore */
|
|
411
|
+
declare type TestApiProviderPropsApiPairs<TApiPairs> = {
|
|
412
|
+
[TIndex in keyof TApiPairs]: TestApiProviderPropsApiPair<TApiPairs[TIndex]>;
|
|
413
|
+
};
|
|
414
|
+
|
|
389
415
|
/**
|
|
390
416
|
* The `TestApiRegistry` is an {@link @backstage/core-plugin-api#ApiHolder} implementation
|
|
391
417
|
* that is particularly well suited for development and test environments such as
|
|
@@ -393,7 +419,7 @@ declare type TestApiProviderProps<TApiPairs extends any[]> = {
|
|
|
393
419
|
*
|
|
394
420
|
* @public
|
|
395
421
|
*/
|
|
396
|
-
declare class TestApiRegistry implements ApiHolder {
|
|
422
|
+
export declare class TestApiRegistry implements ApiHolder {
|
|
397
423
|
private readonly apis;
|
|
398
424
|
/**
|
|
399
425
|
* Creates a new {@link TestApiRegistry} with a list of API implementation pairs.
|
|
@@ -421,43 +447,76 @@ declare class TestApiRegistry implements ApiHolder {
|
|
|
421
447
|
*/
|
|
422
448
|
get<T>(api: ApiRef<T>): T | undefined;
|
|
423
449
|
}
|
|
450
|
+
|
|
424
451
|
/**
|
|
425
|
-
*
|
|
426
|
-
*
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
452
|
+
* Options to customize the behavior of the test app wrapper.
|
|
453
|
+
* @public
|
|
454
|
+
*/
|
|
455
|
+
export declare type TestAppOptions = {
|
|
456
|
+
/**
|
|
457
|
+
* Initial route entries to pass along as `initialEntries` to the router.
|
|
458
|
+
*/
|
|
459
|
+
routeEntries?: string[];
|
|
460
|
+
/**
|
|
461
|
+
* An object of paths to mount route ref on, with the key being the path and the value
|
|
462
|
+
* being the RouteRef that the path will be bound to. This allows the route refs to be
|
|
463
|
+
* used by `useRouteRef` in the rendered elements.
|
|
464
|
+
*
|
|
465
|
+
* @example
|
|
466
|
+
* wrapInTestApp(<MyComponent />, \{
|
|
467
|
+
* mountedRoutes: \{
|
|
468
|
+
* '/my-path': myRouteRef,
|
|
469
|
+
* \}
|
|
470
|
+
* \})
|
|
471
|
+
* // ...
|
|
472
|
+
* const link = useRouteRef(myRouteRef)
|
|
473
|
+
*/
|
|
474
|
+
mountedRoutes?: {
|
|
475
|
+
[path: string]: RouteRef | ExternalRouteRef;
|
|
476
|
+
};
|
|
477
|
+
};
|
|
478
|
+
|
|
479
|
+
/**
|
|
480
|
+
* Returns a `@testing-library/react` valid MatcherFunction for supplied text
|
|
447
481
|
*
|
|
448
|
-
*
|
|
449
|
-
* renderInTestApp(
|
|
450
|
-
* <TestApiProvider apis={[[identityApiRef, mockIdentityApi]]}>
|
|
451
|
-
* {...}
|
|
452
|
-
* </TestApiProvider>
|
|
453
|
-
* )
|
|
454
|
-
* ```
|
|
482
|
+
* @param string - text Text to match by element's textContent
|
|
455
483
|
*
|
|
456
|
-
*
|
|
457
|
-
|
|
484
|
+
* @public
|
|
485
|
+
*/
|
|
486
|
+
export declare const textContentMatcher: (text: string) => MatcherFunction;
|
|
487
|
+
|
|
488
|
+
/**
|
|
489
|
+
* Asynchronous log collector with that collects all categories
|
|
490
|
+
* @public
|
|
491
|
+
*/
|
|
492
|
+
export declare function withLogCollector(callback: AsyncLogCollector): Promise<CollectedLogs<LogFuncs>>;
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* Synchronous log collector with that collects all categories
|
|
496
|
+
* @public
|
|
497
|
+
*/
|
|
498
|
+
export declare function withLogCollector(callback: SyncLogCollector): CollectedLogs<LogFuncs>;
|
|
499
|
+
|
|
500
|
+
/**
|
|
501
|
+
* Asynchronous log collector with that only collects selected categories
|
|
502
|
+
* @public
|
|
503
|
+
*/
|
|
504
|
+
export declare function withLogCollector<T extends LogFuncs>(logsToCollect: T[], callback: AsyncLogCollector): Promise<CollectedLogs<T>>;
|
|
505
|
+
|
|
506
|
+
/**
|
|
507
|
+
* Synchronous log collector with that only collects selected categories
|
|
508
|
+
* @public
|
|
509
|
+
*/
|
|
510
|
+
export declare function withLogCollector<T extends LogFuncs>(logsToCollect: T[], callback: SyncLogCollector): CollectedLogs<T>;
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* Wraps a component inside a Backstage test app, providing a mocked theme
|
|
514
|
+
* and app context, along with mocked APIs.
|
|
458
515
|
*
|
|
516
|
+
* @param Component - A component or react node to render inside the test app.
|
|
517
|
+
* @param options - Additional options for the rendering.
|
|
459
518
|
* @public
|
|
460
|
-
|
|
461
|
-
declare
|
|
519
|
+
*/
|
|
520
|
+
export declare function wrapInTestApp(Component: ComponentType | ReactNode, options?: TestAppOptions): ReactElement;
|
|
462
521
|
|
|
463
|
-
export {
|
|
522
|
+
export { }
|