@backstage/test-utils 1.2.5-next.0 → 1.2.6-next.0

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 CHANGED
@@ -1,5 +1,32 @@
1
1
  # @backstage/test-utils
2
2
 
3
+ ## 1.2.6-next.0
4
+
5
+ ### Patch Changes
6
+
7
+ - 928a12a9b3: Internal refactor of `/alpha` exports.
8
+ - Updated dependencies
9
+ - @backstage/core-plugin-api@1.4.1-next.0
10
+ - @backstage/config@1.0.6
11
+ - @backstage/core-app-api@1.5.1-next.0
12
+ - @backstage/theme@0.2.17
13
+ - @backstage/types@1.0.2
14
+ - @backstage/plugin-permission-common@0.7.3
15
+ - @backstage/plugin-permission-react@0.4.11-next.0
16
+
17
+ ## 1.2.5
18
+
19
+ ### Patch Changes
20
+
21
+ - Updated dependencies
22
+ - @backstage/theme@0.2.17
23
+ - @backstage/core-app-api@1.5.0
24
+ - @backstage/core-plugin-api@1.4.0
25
+ - @backstage/config@1.0.6
26
+ - @backstage/types@1.0.2
27
+ - @backstage/plugin-permission-common@0.7.3
28
+ - @backstage/plugin-permission-react@0.4.10
29
+
3
30
  ## 1.2.5-next.0
4
31
 
5
32
  ### Patch Changes
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@backstage/test-utils",
3
- "version": "1.2.5-next.0",
4
- "main": "../dist/index.esm.js",
5
- "types": "../dist/index.alpha.d.ts"
3
+ "version": "1.2.6-next.0",
4
+ "main": "../dist/alpha.esm.js",
5
+ "module": "../dist/alpha.esm.js",
6
+ "types": "../dist/alpha.d.ts"
6
7
  }
@@ -0,0 +1,9 @@
1
+ import { PropsWithChildren } from 'react';
2
+
3
+ /**
4
+ * Mock for PluginProvider to use in unit tests
5
+ * @alpha
6
+ */
7
+ declare const MockPluginProvider: ({ children }: PropsWithChildren<{}>) => JSX.Element;
8
+
9
+ export { MockPluginProvider };
@@ -0,0 +1,16 @@
1
+ import React from 'react';
2
+ import { PluginProvider } from '@backstage/core-plugin-api/alpha';
3
+ import { createPlugin } from '@backstage/core-plugin-api';
4
+
5
+ const MockPluginProvider = ({ children }) => {
6
+ const plugin = createPlugin({
7
+ id: "my-plugin",
8
+ __experimentalConfigure(_) {
9
+ return {};
10
+ }
11
+ });
12
+ return /* @__PURE__ */ React.createElement(PluginProvider, { plugin }, children);
13
+ };
14
+
15
+ export { MockPluginProvider };
16
+ //# sourceMappingURL=alpha.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"alpha.esm.js","sources":["../src/testUtils/MockPluginProvider.tsx"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React, { PropsWithChildren } from 'react';\nimport { PluginProvider } from '@backstage/core-plugin-api/alpha';\nimport { createPlugin } from '@backstage/core-plugin-api';\n\n/**\n * Mock for PluginProvider to use in unit tests\n * @alpha\n */\nexport const MockPluginProvider = ({ children }: PropsWithChildren<{}>) => {\n type TestInputPluginOptions = {};\n type TestPluginOptions = {};\n const plugin = createPlugin({\n id: 'my-plugin',\n __experimentalConfigure(_: TestInputPluginOptions): TestPluginOptions {\n return {};\n },\n });\n\n return <PluginProvider plugin={plugin}>{children}</PluginProvider>;\n};\n"],"names":[],"mappings":";;;;AAwBO,MAAM,kBAAqB,GAAA,CAAC,EAAE,QAAA,EAAsC,KAAA;AAGzE,EAAA,MAAM,SAAS,YAAa,CAAA;AAAA,IAC1B,EAAI,EAAA,WAAA;AAAA,IACJ,wBAAwB,CAA8C,EAAA;AACpE,MAAA,OAAO,EAAC,CAAA;AAAA,KACV;AAAA,GACD,CAAA,CAAA;AAED,EAAO,uBAAA,KAAA,CAAA,aAAA,CAAC,cAAe,EAAA,EAAA,MAAA,EAAA,EAAiB,QAAS,CAAA,CAAA;AACnD;;;;"}
package/dist/index.d.ts CHANGED
@@ -1,86 +1,11 @@
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';
1
+ import { AnalyticsApi, AnalyticsEvent, ConfigApi, ErrorApiError, ErrorApiErrorContext, ErrorApi, DiscoveryApi, IdentityApi, FetchApi, StorageApi, StorageValueSnapshot, RouteRef, ExternalRouteRef, ApiHolder, ApiRef } from '@backstage/core-plugin-api';
13
2
  import { Config } from '@backstage/config';
14
- import { ConfigApi } from '@backstage/core-plugin-api';
3
+ import { JsonObject, JsonValue, Observable } from '@backstage/types';
15
4
  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';
29
5
  import { PermissionApi } from '@backstage/plugin-permission-react';
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';
6
+ import { EvaluatePermissionRequest, AuthorizeResult, EvaluatePermissionResponse } from '@backstage/plugin-permission-common';
7
+ import { ReactNode, ComponentType, ReactElement } from 'react';
8
+ import { RenderResult, MatcherFunction, RenderOptions } from '@testing-library/react';
84
9
 
85
10
  /**
86
11
  * Mock implementation of {@link core-plugin-api#AnalyticsApi} with helpers to ensure that events are sent correctly.
@@ -88,28 +13,12 @@ export declare type LogFuncs = 'log' | 'warn' | 'error';
88
13
  *
89
14
  * @public
90
15
  */
91
- export declare class MockAnalyticsApi implements AnalyticsApi {
16
+ declare class MockAnalyticsApi implements AnalyticsApi {
92
17
  private events;
93
18
  captureEvent(event: AnalyticsEvent): void;
94
19
  getEvents(): AnalyticsEvent[];
95
20
  }
96
21
 
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
-
113
22
  /**
114
23
  * MockConfigApi is a thin wrapper around {@link @backstage/config#ConfigReader}
115
24
  * that can be used to mock configuration using a plain object.
@@ -128,7 +37,7 @@ export declare function mockBreakpoint(options: {
128
37
  * );
129
38
  * ```
130
39
  */
131
- export declare class MockConfigApi implements ConfigApi {
40
+ declare class MockConfigApi implements ConfigApi {
132
41
  private readonly config;
133
42
  constructor(data: JsonObject);
134
43
  /** {@inheritdoc @backstage/config#Config.has} */
@@ -165,12 +74,27 @@ export declare class MockConfigApi implements ConfigApi {
165
74
  getOptionalStringArray(key: string): string[] | undefined;
166
75
  }
167
76
 
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
+ };
168
92
  /**
169
93
  * Mock implementation of the {@link core-plugin-api#ErrorApi} to be used in tests.
170
94
  * Includes withForError and getErrors methods for error testing.
171
95
  * @public
172
96
  */
173
- export declare class MockErrorApi implements ErrorApi {
97
+ declare class MockErrorApi implements ErrorApi {
174
98
  private readonly options;
175
99
  private readonly errors;
176
100
  private readonly waiters;
@@ -184,35 +108,12 @@ export declare class MockErrorApi implements ErrorApi {
184
108
  waitForError(pattern: RegExp, timeoutMs?: number): Promise<ErrorWithContext>;
185
109
  }
186
110
 
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
-
210
111
  /**
211
112
  * The options given when constructing a {@link MockFetchApi}.
212
113
  *
213
114
  * @public
214
115
  */
215
- export declare interface MockFetchApiOptions {
116
+ interface MockFetchApiOptions {
216
117
  /**
217
118
  * Define the underlying base `fetch` implementation.
218
119
  *
@@ -266,6 +167,20 @@ export declare interface MockFetchApiOptions {
266
167
  identityApi: Pick<IdentityApi, 'getCredentials'>;
267
168
  };
268
169
  }
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
+ }
269
184
 
270
185
  /**
271
186
  * Mock implementation of
@@ -274,19 +189,24 @@ export declare interface MockFetchApiOptions {
274
189
  * request.
275
190
  * @public
276
191
  */
277
- export declare class MockPermissionApi implements PermissionApi {
192
+ declare class MockPermissionApi implements PermissionApi {
278
193
  private readonly requestHandler;
279
194
  constructor(requestHandler?: (request: EvaluatePermissionRequest) => AuthorizeResult.ALLOW | AuthorizeResult.DENY);
280
195
  authorize(request: EvaluatePermissionRequest): Promise<EvaluatePermissionResponse>;
281
196
  }
282
197
 
283
- /* Excluded from this release type: MockPluginProvider */
284
-
198
+ /**
199
+ * Type for map holding data in {@link MockStorageApi}
200
+ * @public
201
+ */
202
+ declare type MockStorageBucket = {
203
+ [key: string]: any;
204
+ };
285
205
  /**
286
206
  * Mock implementation of the {@link core-plugin-api#StorageApi} to be used in tests
287
207
  * @public
288
208
  */
289
- export declare class MockStorageApi implements StorageApi {
209
+ declare class MockStorageApi implements StorageApi {
290
210
  private readonly namespace;
291
211
  private readonly data;
292
212
  private readonly bucketStorageApis;
@@ -304,13 +224,67 @@ export declare class MockStorageApi implements StorageApi {
304
224
  }
305
225
 
306
226
  /**
307
- * Type for map holding data in {@link MockStorageApi}
227
+ * This is a mocking method suggested in the Jest docs, as it is not implemented in JSDOM yet.
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
+ *
308
236
  * @public
309
237
  */
310
- export declare type MockStorageBucket = {
311
- [key: string]: any;
312
- };
238
+ declare function mockBreakpoint(options: {
239
+ matches: boolean;
240
+ }): void;
313
241
 
242
+ /**
243
+ * Options to customize the behavior of the test app wrapper.
244
+ * @public
245
+ */
246
+ declare type TestAppOptions = {
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
+ };
268
+ };
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;
314
288
  /**
315
289
  * Renders a component inside a Backstage test app, providing a mocked theme
316
290
  * and app context, along with mocked APIs.
@@ -322,96 +296,104 @@ export declare type MockStorageBucket = {
322
296
  * @param options - Additional options for the rendering.
323
297
  * @public
324
298
  */
325
- export declare function renderInTestApp(Component: ComponentType | ReactNode, options?: TestAppOptions): Promise<RenderResult>;
326
-
299
+ declare function renderInTestApp(Component: ComponentType | ReactNode, options?: TestAppOptions): Promise<RenderResult>;
327
300
  /**
328
- * @public
329
- * Simplifies rendering of async components in by taking care of the wrapping inside act
301
+ * Returns a `@testing-library/react` valid MatcherFunction for supplied text
330
302
  *
331
- * @remarks
303
+ * @param string - text Text to match by element's textContent
332
304
  *
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
305
+ * @public
338
306
  */
339
- export declare function renderWithEffects(nodes: ReactElement, options?: Pick<RenderOptions, 'wrapper'>): Promise<RenderResult>;
307
+ declare const textContentMatcher: (text: string) => MatcherFunction;
340
308
 
341
309
  /**
342
310
  * Sets up handlers for request mocking
343
311
  * @public
344
312
  * @param worker - service worker
345
313
  */
346
- export declare function setupRequestMockHandlers(worker: {
314
+ declare function setupRequestMockHandlers(worker: {
347
315
  listen: (t: any) => void;
348
316
  close: () => void;
349
317
  resetHandlers: () => void;
350
318
  }): void;
351
319
 
320
+ /**
321
+ * Severity levels of {@link CollectedLogs}
322
+ * @public
323
+ */
324
+ declare type LogFuncs = 'log' | 'warn' | 'error';
325
+ /**
326
+ * AsyncLogCollector type used in {@link (withLogCollector:1)} callback function.
327
+ * @public
328
+ */
329
+ declare type AsyncLogCollector = () => Promise<void>;
352
330
  /**
353
331
  * SyncLogCollector type used in {@link (withLogCollector:2)} callback function.
354
332
  * @public
355
333
  */
356
- export declare type SyncLogCollector = () => void;
357
-
334
+ declare type SyncLogCollector = () => void;
358
335
  /**
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.
362
- *
363
- * It lets you provide any number of API implementations, without necessarily
364
- * having to fully implement each of the APIs.
365
- *
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
- *
336
+ * Union type used in {@link (withLogCollector:3)} callback function.
393
337
  * @public
394
- **/
395
- export declare const TestApiProvider: <T extends any[]>(props: TestApiProviderProps<T>) => JSX.Element;
396
-
338
+ */
339
+ declare type LogCollector = AsyncLogCollector | SyncLogCollector;
397
340
  /**
398
- * Properties for the {@link TestApiProvider} component.
399
- *
341
+ * Map of severity level and corresponding log lines.
400
342
  * @public
401
343
  */
402
- export declare type TestApiProviderProps<TApiPairs extends any[]> = {
403
- apis: readonly [...TestApiProviderPropsApiPairs<TApiPairs>];
404
- children: ReactNode;
344
+ declare type CollectedLogs<T extends LogFuncs> = {
345
+ [key in T]: string[];
405
346
  };
347
+ /**
348
+ * Asynchronous log collector with that collects all categories
349
+ * @public
350
+ */
351
+ declare function withLogCollector(callback: AsyncLogCollector): Promise<CollectedLogs<LogFuncs>>;
352
+ /**
353
+ * Synchronous log collector with that collects all categories
354
+ * @public
355
+ */
356
+ declare function withLogCollector(callback: SyncLogCollector): CollectedLogs<LogFuncs>;
357
+ /**
358
+ * Asynchronous log collector with that only collects selected categories
359
+ * @public
360
+ */
361
+ declare function withLogCollector<T extends LogFuncs>(logsToCollect: T[], callback: AsyncLogCollector): Promise<CollectedLogs<T>>;
362
+ /**
363
+ * Synchronous log collector with that only collects selected categories
364
+ * @public
365
+ */
366
+ declare function withLogCollector<T extends LogFuncs>(logsToCollect: T[], callback: SyncLogCollector): CollectedLogs<T>;
367
+
368
+ /**
369
+ * @public
370
+ * Simplifies rendering of async components in by taking care of the wrapping inside act
371
+ *
372
+ * @remarks
373
+ *
374
+ * Components using useEffect to perform an asynchronous action (such as fetch) must be rendered within an async
375
+ * act call to properly get the final state, even with mocked responses. This utility method makes the signature a bit
376
+ * cleaner, since act doesn't return the result of the evaluated function.
377
+ * https://github.com/testing-library/react-testing-library/issues/281
378
+ * https://github.com/facebook/react/pull/14853
379
+ */
380
+ declare function renderWithEffects(nodes: ReactElement, options?: Pick<RenderOptions, 'wrapper'>): Promise<RenderResult>;
406
381
 
407
382
  /** @ignore */
408
383
  declare type TestApiProviderPropsApiPair<TApi> = TApi extends infer TImpl ? readonly [ApiRef<TApi>, Partial<TImpl>] : never;
409
-
410
384
  /** @ignore */
411
385
  declare type TestApiProviderPropsApiPairs<TApiPairs> = {
412
386
  [TIndex in keyof TApiPairs]: TestApiProviderPropsApiPair<TApiPairs[TIndex]>;
413
387
  };
414
-
388
+ /**
389
+ * Properties for the {@link TestApiProvider} component.
390
+ *
391
+ * @public
392
+ */
393
+ declare type TestApiProviderProps<TApiPairs extends any[]> = {
394
+ apis: readonly [...TestApiProviderPropsApiPairs<TApiPairs>];
395
+ children: ReactNode;
396
+ };
415
397
  /**
416
398
  * The `TestApiRegistry` is an {@link @backstage/core-plugin-api#ApiHolder} implementation
417
399
  * that is particularly well suited for development and test environments such as
@@ -419,7 +401,7 @@ declare type TestApiProviderPropsApiPairs<TApiPairs> = {
419
401
  *
420
402
  * @public
421
403
  */
422
- export declare class TestApiRegistry implements ApiHolder {
404
+ declare class TestApiRegistry implements ApiHolder {
423
405
  private readonly apis;
424
406
  /**
425
407
  * Creates a new {@link TestApiRegistry} with a list of API implementation pairs.
@@ -447,76 +429,43 @@ export declare class TestApiRegistry implements ApiHolder {
447
429
  */
448
430
  get<T>(api: ApiRef<T>): T | undefined;
449
431
  }
450
-
451
432
  /**
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
433
+ * The `TestApiProvider` is a Utility API context provider that is particularly
434
+ * well suited for development and test environments such as unit tests, storybooks,
435
+ * and isolated plugin development setups.
481
436
  *
482
- * @param string - text Text to match by element's textContent
437
+ * It lets you provide any number of API implementations, without necessarily
438
+ * having to fully implement each of the APIs.
483
439
  *
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.
440
+ * A migration from `ApiRegistry` and `ApiProvider` might look like this, from:
441
+ *
442
+ * ```tsx
443
+ * renderInTestApp(
444
+ * <ApiProvider
445
+ * apis={ApiRegistry.from([
446
+ * [identityApiRef, mockIdentityApi as unknown as IdentityApi]
447
+ * ])}
448
+ * >
449
+ * // ...
450
+ * </ApiProvider>
451
+ * )
452
+ * ```
453
+ *
454
+ * To the following:
455
+ *
456
+ * ```tsx
457
+ * renderInTestApp(
458
+ * <TestApiProvider apis={[[identityApiRef, mockIdentityApi]]}>
459
+ * // ...
460
+ * </TestApiProvider>
461
+ * )
462
+ * ```
463
+ *
464
+ * Note that the cast to `IdentityApi` is no longer needed as long as the mock API
465
+ * implements a subset of the `IdentityApi`.
515
466
  *
516
- * @param Component - A component or react node to render inside the test app.
517
- * @param options - Additional options for the rendering.
518
467
  * @public
519
468
  */
520
- export declare function wrapInTestApp(Component: ComponentType | ReactNode, options?: TestAppOptions): ReactElement;
469
+ declare const TestApiProvider: <T extends any[]>(props: TestApiProviderProps<T>) => JSX.Element;
521
470
 
522
- export { }
471
+ export { AsyncLogCollector, CollectedLogs, ErrorWithContext, LogCollector, LogFuncs, MockAnalyticsApi, MockConfigApi, MockErrorApi, MockErrorApiOptions, MockFetchApi, MockFetchApiOptions, MockPermissionApi, MockStorageApi, MockStorageBucket, SyncLogCollector, TestApiProvider, TestApiProviderProps, TestApiRegistry, TestAppOptions, createTestAppWrapper, mockBreakpoint, renderInTestApp, renderWithEffects, setupRequestMockHandlers, textContentMatcher, withLogCollector, wrapInTestApp };