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