@backstage/test-utils 1.5.4 → 1.5.5

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.
Files changed (40) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/alpha/package.json +1 -1
  3. package/dist/alpha.esm.js +1 -3
  4. package/dist/alpha.esm.js.map +1 -1
  5. package/dist/core-plugin-api/src/translation/TranslationRef.esm.js +13 -0
  6. package/dist/core-plugin-api/src/translation/TranslationRef.esm.js.map +1 -0
  7. package/dist/index.esm.js +12 -738
  8. package/dist/index.esm.js.map +1 -1
  9. package/dist/testUtils/TestApiProvider.esm.js +50 -0
  10. package/dist/testUtils/TestApiProvider.esm.js.map +1 -0
  11. package/dist/testUtils/apis/AnalyticsApi/MockAnalyticsApi.esm.js +27 -0
  12. package/dist/testUtils/apis/AnalyticsApi/MockAnalyticsApi.esm.js.map +1 -0
  13. package/dist/testUtils/apis/ConfigApi/MockConfigApi.esm.js +82 -0
  14. package/dist/testUtils/apis/ConfigApi/MockConfigApi.esm.js.map +1 -0
  15. package/dist/testUtils/apis/ErrorApi/MockErrorApi.esm.js +50 -0
  16. package/dist/testUtils/apis/ErrorApi/MockErrorApi.esm.js.map +1 -0
  17. package/dist/testUtils/apis/FetchApi/MockFetchApi.esm.js +63 -0
  18. package/dist/testUtils/apis/FetchApi/MockFetchApi.esm.js.map +1 -0
  19. package/dist/testUtils/apis/PermissionApi/MockPermissionApi.esm.js +13 -0
  20. package/dist/testUtils/apis/PermissionApi/MockPermissionApi.esm.js.map +1 -0
  21. package/dist/testUtils/apis/StorageApi/MockStorageApi.esm.js +92 -0
  22. package/dist/testUtils/apis/StorageApi/MockStorageApi.esm.js.map +1 -0
  23. package/dist/{esm/MockTranslationApi-Dl_xfoCj.esm.js → testUtils/apis/TranslationApi/MockTranslationApi.esm.js} +5 -15
  24. package/dist/testUtils/apis/TranslationApi/MockTranslationApi.esm.js.map +1 -0
  25. package/dist/testUtils/appWrappers.esm.js +143 -0
  26. package/dist/testUtils/appWrappers.esm.js.map +1 -0
  27. package/dist/testUtils/defaultApis.esm.js +148 -0
  28. package/dist/testUtils/defaultApis.esm.js.map +1 -0
  29. package/dist/testUtils/logCollector.esm.js +57 -0
  30. package/dist/testUtils/logCollector.esm.js.map +1 -0
  31. package/dist/testUtils/mockApis.esm.js +18 -0
  32. package/dist/testUtils/mockApis.esm.js.map +1 -0
  33. package/dist/testUtils/mockBreakpoint.esm.js +23 -0
  34. package/dist/testUtils/mockBreakpoint.esm.js.map +1 -0
  35. package/dist/testUtils/msw/setupRequestMockHandlers.esm.js +8 -0
  36. package/dist/testUtils/msw/setupRequestMockHandlers.esm.js.map +1 -0
  37. package/dist/testUtils/testingLibrary.esm.js +12 -0
  38. package/dist/testUtils/testingLibrary.esm.js.map +1 -0
  39. package/package.json +4 -4
  40. package/dist/esm/MockTranslationApi-Dl_xfoCj.esm.js.map +0 -1
package/dist/index.esm.js CHANGED
@@ -1,739 +1,13 @@
1
- import { ConfigReader } from '@backstage/config';
2
- import { createFetchApi, FetchMiddlewares, UrlPatternDiscovery, AlertApiForwarder, NoOpAnalyticsApi, ErrorAlerter, ErrorApiForwarder, UnhandledErrorForwarder, WebStorage, OAuthRequestManager, GoogleAuth, MicrosoftAuth, GithubAuth, OktaAuth, GitlabAuth, OneLoginAuth, BitbucketAuth, AtlassianAuth, createSpecializedApp, ApiProvider } from '@backstage/core-app-api';
3
- import crossFetch, { Response } from 'cross-fetch';
4
- import { AuthorizeResult } from '@backstage/plugin-permission-common';
5
- import ObservableImpl from 'zen-observable';
6
- import React from 'react';
7
- import { MemoryRouter, Route } from 'react-router-dom';
8
- import { UnifiedThemeProvider, themes } from '@backstage/theme';
9
- import MockIcon from '@material-ui/icons/AcUnit';
10
- import { createApiFactory, discoveryApiRef, configApiRef, alertApiRef, analyticsApiRef, errorApiRef, storageApiRef, oauthRequestApiRef, googleAuthApiRef, microsoftAuthApiRef, githubAuthApiRef, oktaAuthApiRef, gitlabAuthApiRef, oneloginAuthApiRef, bitbucketAuthApiRef, atlassianAuthApiRef, fetchApiRef, createRouteRef, attachComponentData } from '@backstage/core-plugin-api';
11
- import { act, render } from '@testing-library/react';
12
- import { translationApiRef } from '@backstage/core-plugin-api/alpha';
13
- import { M as MockTranslationApi } from './esm/MockTranslationApi-Dl_xfoCj.esm.js';
14
- import 'i18next';
15
-
16
- var __defProp$4 = Object.defineProperty;
17
- var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
18
- var __publicField$4 = (obj, key, value) => {
19
- __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
20
- return value;
21
- };
22
- class MockAnalyticsApi {
23
- constructor() {
24
- __publicField$4(this, "events", []);
25
- }
26
- captureEvent(event) {
27
- const { action, subject, value, attributes, context } = event;
28
- this.events.push({
29
- action,
30
- subject,
31
- context,
32
- ...value !== void 0 ? { value } : {},
33
- ...attributes !== void 0 ? { attributes } : {}
34
- });
35
- }
36
- getEvents() {
37
- return this.events;
38
- }
39
- }
40
-
41
- var __defProp$3 = Object.defineProperty;
42
- var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
43
- var __publicField$3 = (obj, key, value) => {
44
- __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
45
- return value;
46
- };
47
- class MockConfigApi {
48
- // NOTE: not extending in order to avoid inheriting the static `.fromConfigs`
49
- constructor(data) {
50
- __publicField$3(this, "config");
51
- this.config = new ConfigReader(data);
52
- }
53
- /** {@inheritdoc @backstage/config#Config.has} */
54
- has(key) {
55
- return this.config.has(key);
56
- }
57
- /** {@inheritdoc @backstage/config#Config.keys} */
58
- keys() {
59
- return this.config.keys();
60
- }
61
- /** {@inheritdoc @backstage/config#Config.get} */
62
- get(key) {
63
- return this.config.get(key);
64
- }
65
- /** {@inheritdoc @backstage/config#Config.getOptional} */
66
- getOptional(key) {
67
- return this.config.getOptional(key);
68
- }
69
- /** {@inheritdoc @backstage/config#Config.getConfig} */
70
- getConfig(key) {
71
- return this.config.getConfig(key);
72
- }
73
- /** {@inheritdoc @backstage/config#Config.getOptionalConfig} */
74
- getOptionalConfig(key) {
75
- return this.config.getOptionalConfig(key);
76
- }
77
- /** {@inheritdoc @backstage/config#Config.getConfigArray} */
78
- getConfigArray(key) {
79
- return this.config.getConfigArray(key);
80
- }
81
- /** {@inheritdoc @backstage/config#Config.getOptionalConfigArray} */
82
- getOptionalConfigArray(key) {
83
- return this.config.getOptionalConfigArray(key);
84
- }
85
- /** {@inheritdoc @backstage/config#Config.getNumber} */
86
- getNumber(key) {
87
- return this.config.getNumber(key);
88
- }
89
- /** {@inheritdoc @backstage/config#Config.getOptionalNumber} */
90
- getOptionalNumber(key) {
91
- return this.config.getOptionalNumber(key);
92
- }
93
- /** {@inheritdoc @backstage/config#Config.getBoolean} */
94
- getBoolean(key) {
95
- return this.config.getBoolean(key);
96
- }
97
- /** {@inheritdoc @backstage/config#Config.getOptionalBoolean} */
98
- getOptionalBoolean(key) {
99
- return this.config.getOptionalBoolean(key);
100
- }
101
- /** {@inheritdoc @backstage/config#Config.getString} */
102
- getString(key) {
103
- return this.config.getString(key);
104
- }
105
- /** {@inheritdoc @backstage/config#Config.getOptionalString} */
106
- getOptionalString(key) {
107
- return this.config.getOptionalString(key);
108
- }
109
- /** {@inheritdoc @backstage/config#Config.getStringArray} */
110
- getStringArray(key) {
111
- return this.config.getStringArray(key);
112
- }
113
- /** {@inheritdoc @backstage/config#Config.getOptionalStringArray} */
114
- getOptionalStringArray(key) {
115
- return this.config.getOptionalStringArray(key);
116
- }
117
- }
118
-
119
- var __defProp$2 = Object.defineProperty;
120
- var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
121
- var __publicField$2 = (obj, key, value) => {
122
- __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
123
- return value;
124
- };
125
- const nullObservable = {
126
- subscribe: () => ({ unsubscribe: () => {
127
- }, closed: true }),
128
- [Symbol.observable]() {
129
- return this;
130
- }
131
- };
132
- class MockErrorApi {
133
- constructor(options = {}) {
134
- this.options = options;
135
- __publicField$2(this, "errors", new Array());
136
- __publicField$2(this, "waiters", /* @__PURE__ */ new Set());
137
- }
138
- post(error, context) {
139
- if (this.options.collect) {
140
- this.errors.push({ error, context });
141
- for (const waiter of this.waiters) {
142
- if (waiter.pattern.test(error.message)) {
143
- this.waiters.delete(waiter);
144
- waiter.resolve({ error, context });
145
- }
146
- }
147
- return;
148
- }
149
- throw new Error(`MockErrorApi received unexpected error, ${error}`);
150
- }
151
- error$() {
152
- return nullObservable;
153
- }
154
- getErrors() {
155
- return this.errors;
156
- }
157
- waitForError(pattern, timeoutMs = 2e3) {
158
- return new Promise((resolve, reject) => {
159
- setTimeout(() => {
160
- reject(new Error("Timed out waiting for error"));
161
- }, timeoutMs);
162
- this.waiters.add({ resolve, pattern });
163
- });
164
- }
165
- }
166
-
167
- var __defProp$1 = Object.defineProperty;
168
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
169
- var __publicField$1 = (obj, key, value) => {
170
- __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
171
- return value;
172
- };
173
- class MockFetchApi {
174
- /**
175
- * Creates a mock {@link @backstage/core-plugin-api#FetchApi}.
176
- */
177
- constructor(options) {
178
- __publicField$1(this, "implementation");
179
- this.implementation = build(options);
180
- }
181
- /** {@inheritdoc @backstage/core-plugin-api#FetchApi.fetch} */
182
- get fetch() {
183
- return this.implementation.fetch;
184
- }
185
- }
186
- function build(options) {
187
- return createFetchApi({
188
- baseImplementation: baseImplementation(options),
189
- middleware: [
190
- resolvePluginProtocol(options),
191
- injectIdentityAuth(options)
192
- ].filter((x) => Boolean(x))
193
- });
194
- }
195
- function baseImplementation(options) {
196
- const implementation = options == null ? void 0 : options.baseImplementation;
197
- if (!implementation) {
198
- return crossFetch;
199
- } else if (implementation === "none") {
200
- return () => Promise.resolve(new Response());
201
- }
202
- return implementation;
203
- }
204
- function resolvePluginProtocol(allOptions) {
205
- const options = allOptions == null ? void 0 : allOptions.resolvePluginProtocol;
206
- if (!options) {
207
- return void 0;
208
- }
209
- return FetchMiddlewares.resolvePluginProtocol({
210
- discoveryApi: options.discoveryApi
211
- });
212
- }
213
- function injectIdentityAuth(allOptions) {
214
- const options = allOptions == null ? void 0 : allOptions.injectIdentityAuth;
215
- if (!options) {
216
- return void 0;
217
- }
218
- const identityApi = "token" in options ? { getCredentials: async () => ({ token: options.token }) } : options.identityApi;
219
- return FetchMiddlewares.injectIdentityAuth({
220
- identityApi,
221
- allowUrl: () => true
222
- });
223
- }
224
-
225
- class MockPermissionApi {
226
- constructor(requestHandler = () => AuthorizeResult.ALLOW) {
227
- this.requestHandler = requestHandler;
228
- }
229
- async authorize(request) {
230
- return { result: this.requestHandler(request) };
231
- }
232
- }
233
-
234
- var __defProp = Object.defineProperty;
235
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
236
- var __publicField = (obj, key, value) => {
237
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
238
- return value;
239
- };
240
- class MockStorageApi {
241
- constructor(namespace, bucketStorageApis, data) {
242
- __publicField(this, "namespace");
243
- __publicField(this, "data");
244
- __publicField(this, "bucketStorageApis");
245
- __publicField(this, "subscribers", /* @__PURE__ */ new Set());
246
- __publicField(this, "observable", new ObservableImpl((subscriber) => {
247
- this.subscribers.add(subscriber);
248
- return () => {
249
- this.subscribers.delete(subscriber);
250
- };
251
- }));
252
- this.namespace = namespace;
253
- this.bucketStorageApis = bucketStorageApis;
254
- this.data = { ...data };
255
- }
256
- static create(data) {
257
- return new MockStorageApi("", /* @__PURE__ */ new Map(), data);
258
- }
259
- forBucket(name) {
260
- if (!this.bucketStorageApis.has(name)) {
261
- this.bucketStorageApis.set(
262
- name,
263
- new MockStorageApi(
264
- `${this.namespace}/${name}`,
265
- this.bucketStorageApis,
266
- this.data
267
- )
268
- );
269
- }
270
- return this.bucketStorageApis.get(name);
271
- }
272
- snapshot(key) {
273
- if (this.data.hasOwnProperty(this.getKeyName(key))) {
274
- const data = this.data[this.getKeyName(key)];
275
- return {
276
- key,
277
- presence: "present",
278
- value: data
279
- };
280
- }
281
- return {
282
- key,
283
- presence: "absent",
284
- value: void 0
285
- };
286
- }
287
- async set(key, data) {
288
- const serialized = JSON.parse(JSON.stringify(data), (_key, value) => {
289
- if (typeof value === "object" && value !== null) {
290
- Object.freeze(value);
291
- }
292
- return value;
293
- });
294
- this.data[this.getKeyName(key)] = serialized;
295
- this.notifyChanges({
296
- key,
297
- presence: "present",
298
- value: serialized
299
- });
300
- }
301
- async remove(key) {
302
- delete this.data[this.getKeyName(key)];
303
- this.notifyChanges({
304
- key,
305
- presence: "absent",
306
- value: void 0
307
- });
308
- }
309
- observe$(key) {
310
- return this.observable.filter(({ key: messageKey }) => messageKey === key);
311
- }
312
- getKeyName(key) {
313
- return `${this.namespace}/${encodeURIComponent(key)}`;
314
- }
315
- notifyChanges(message) {
316
- for (const subscription of this.subscribers) {
317
- subscription.next(message);
318
- }
319
- }
320
- }
321
-
322
- function mockBreakpoint(options) {
323
- Object.defineProperty(window, "matchMedia", {
324
- writable: true,
325
- value: jest.fn().mockImplementation((query) => {
326
- var _a;
327
- return {
328
- matches: (_a = options.matches) != null ? _a : false,
329
- media: query,
330
- onchange: null,
331
- addListener: jest.fn(),
332
- // deprecated
333
- removeListener: jest.fn(),
334
- // deprecated
335
- addEventListener: jest.fn(),
336
- removeEventListener: jest.fn(),
337
- dispatchEvent: jest.fn()
338
- };
339
- })
340
- });
341
- }
342
-
343
- async function renderWithEffects(nodes, options) {
344
- let value;
345
- await act(async () => {
346
- value = render(nodes, options);
347
- });
348
- return value;
349
- }
350
-
351
- const defaultApis = [
352
- createApiFactory({
353
- api: discoveryApiRef,
354
- deps: { configApi: configApiRef },
355
- factory: ({ configApi }) => UrlPatternDiscovery.compile(
356
- `${configApi.getString("backend.baseUrl")}/api/{{ pluginId }}`
357
- )
358
- }),
359
- createApiFactory(alertApiRef, new AlertApiForwarder()),
360
- createApiFactory(analyticsApiRef, new NoOpAnalyticsApi()),
361
- createApiFactory({
362
- api: errorApiRef,
363
- deps: { alertApi: alertApiRef },
364
- factory: ({ alertApi }) => {
365
- const errorApi = new ErrorAlerter(alertApi, new ErrorApiForwarder());
366
- UnhandledErrorForwarder.forward(errorApi, { hidden: false });
367
- return errorApi;
368
- }
369
- }),
370
- createApiFactory({
371
- api: storageApiRef,
372
- deps: { errorApi: errorApiRef },
373
- factory: ({ errorApi }) => WebStorage.create({ errorApi })
374
- }),
375
- createApiFactory(oauthRequestApiRef, new OAuthRequestManager()),
376
- createApiFactory({
377
- api: googleAuthApiRef,
378
- deps: {
379
- discoveryApi: discoveryApiRef,
380
- oauthRequestApi: oauthRequestApiRef,
381
- configApi: configApiRef
382
- },
383
- factory: ({ discoveryApi, oauthRequestApi, configApi }) => GoogleAuth.create({
384
- configApi,
385
- discoveryApi,
386
- oauthRequestApi,
387
- environment: configApi.getOptionalString("auth.environment")
388
- })
389
- }),
390
- createApiFactory({
391
- api: microsoftAuthApiRef,
392
- deps: {
393
- discoveryApi: discoveryApiRef,
394
- oauthRequestApi: oauthRequestApiRef,
395
- configApi: configApiRef
396
- },
397
- factory: ({ discoveryApi, oauthRequestApi, configApi }) => MicrosoftAuth.create({
398
- configApi,
399
- discoveryApi,
400
- oauthRequestApi,
401
- environment: configApi.getOptionalString("auth.environment")
402
- })
403
- }),
404
- createApiFactory({
405
- api: githubAuthApiRef,
406
- deps: {
407
- discoveryApi: discoveryApiRef,
408
- oauthRequestApi: oauthRequestApiRef,
409
- configApi: configApiRef
410
- },
411
- factory: ({ discoveryApi, oauthRequestApi, configApi }) => GithubAuth.create({
412
- configApi,
413
- discoveryApi,
414
- oauthRequestApi,
415
- defaultScopes: ["read:user"],
416
- environment: configApi.getOptionalString("auth.environment")
417
- })
418
- }),
419
- createApiFactory({
420
- api: oktaAuthApiRef,
421
- deps: {
422
- discoveryApi: discoveryApiRef,
423
- oauthRequestApi: oauthRequestApiRef,
424
- configApi: configApiRef
425
- },
426
- factory: ({ discoveryApi, oauthRequestApi, configApi }) => OktaAuth.create({
427
- configApi,
428
- discoveryApi,
429
- oauthRequestApi,
430
- environment: configApi.getOptionalString("auth.environment")
431
- })
432
- }),
433
- createApiFactory({
434
- api: gitlabAuthApiRef,
435
- deps: {
436
- discoveryApi: discoveryApiRef,
437
- oauthRequestApi: oauthRequestApiRef,
438
- configApi: configApiRef
439
- },
440
- factory: ({ discoveryApi, oauthRequestApi, configApi }) => GitlabAuth.create({
441
- configApi,
442
- discoveryApi,
443
- oauthRequestApi,
444
- environment: configApi.getOptionalString("auth.environment")
445
- })
446
- }),
447
- createApiFactory({
448
- api: oneloginAuthApiRef,
449
- deps: {
450
- discoveryApi: discoveryApiRef,
451
- oauthRequestApi: oauthRequestApiRef,
452
- configApi: configApiRef
453
- },
454
- factory: ({ discoveryApi, oauthRequestApi, configApi }) => OneLoginAuth.create({
455
- configApi,
456
- discoveryApi,
457
- oauthRequestApi,
458
- environment: configApi.getOptionalString("auth.environment")
459
- })
460
- }),
461
- createApiFactory({
462
- api: bitbucketAuthApiRef,
463
- deps: {
464
- discoveryApi: discoveryApiRef,
465
- oauthRequestApi: oauthRequestApiRef,
466
- configApi: configApiRef
467
- },
468
- factory: ({ discoveryApi, oauthRequestApi, configApi }) => BitbucketAuth.create({
469
- configApi,
470
- discoveryApi,
471
- oauthRequestApi,
472
- defaultScopes: ["account"],
473
- environment: configApi.getOptionalString("auth.environment")
474
- })
475
- }),
476
- createApiFactory({
477
- api: atlassianAuthApiRef,
478
- deps: {
479
- discoveryApi: discoveryApiRef,
480
- oauthRequestApi: oauthRequestApiRef,
481
- configApi: configApiRef
482
- },
483
- factory: ({ discoveryApi, oauthRequestApi, configApi }) => {
484
- return AtlassianAuth.create({
485
- configApi,
486
- discoveryApi,
487
- oauthRequestApi,
488
- environment: configApi.getOptionalString("auth.environment")
489
- });
490
- }
491
- })
492
- ];
493
-
494
- const mockApis = [
495
- createApiFactory(errorApiRef, new MockErrorApi()),
496
- createApiFactory(fetchApiRef, new MockFetchApi()),
497
- createApiFactory(storageApiRef, MockStorageApi.create()),
498
- createApiFactory(translationApiRef, MockTranslationApi.create())
499
- ];
500
-
501
- const mockIcons = {
502
- "kind:api": MockIcon,
503
- "kind:component": MockIcon,
504
- "kind:domain": MockIcon,
505
- "kind:group": MockIcon,
506
- "kind:location": MockIcon,
507
- "kind:system": MockIcon,
508
- "kind:user": MockIcon,
509
- "kind:resource": MockIcon,
510
- "kind:template": MockIcon,
511
- brokenImage: MockIcon,
512
- catalog: MockIcon,
513
- scaffolder: MockIcon,
514
- techdocs: MockIcon,
515
- search: MockIcon,
516
- chat: MockIcon,
517
- dashboard: MockIcon,
518
- docs: MockIcon,
519
- email: MockIcon,
520
- github: MockIcon,
521
- group: MockIcon,
522
- help: MockIcon,
523
- user: MockIcon,
524
- warning: MockIcon
525
- };
526
- const ErrorBoundaryFallback = ({ error }) => {
527
- throw new Error(`Reached ErrorBoundaryFallback Page with error, ${error}`);
528
- };
529
- const NotFoundErrorPage = () => {
530
- throw new Error("Reached NotFound Page");
531
- };
532
- const BootErrorPage = ({ step, error }) => {
533
- throw new Error(`Reached BootError Page at step ${step} with error ${error}`);
534
- };
535
- const Progress = () => /* @__PURE__ */ React.createElement("div", { "data-testid": "progress" });
536
- const NoRender = (_props) => null;
537
- function isExternalRouteRef(routeRef) {
538
- return String(routeRef).includes("{type=external,");
539
- }
540
- function createTestAppWrapper(options = {}) {
541
- var _a;
542
- const { routeEntries = ["/"] } = options;
543
- const boundRoutes = /* @__PURE__ */ new Map();
544
- const app = createSpecializedApp({
545
- apis: mockApis,
546
- defaultApis,
547
- // Bit of a hack to make sure that the default config loader isn't used
548
- // as that would force every single test to wait for config loading.
549
- configLoader: false,
550
- components: {
551
- Progress,
552
- BootErrorPage,
553
- NotFoundErrorPage,
554
- ErrorBoundaryFallback,
555
- Router: ({ children }) => /* @__PURE__ */ React.createElement(MemoryRouter, { initialEntries: routeEntries, children }),
556
- ...options.components
557
- },
558
- icons: mockIcons,
559
- plugins: [],
560
- themes: [
561
- {
562
- id: "light",
563
- title: "Test App Theme",
564
- variant: "light",
565
- Provider: ({ children }) => /* @__PURE__ */ React.createElement(UnifiedThemeProvider, { theme: themes.light }, children)
566
- }
567
- ],
568
- bindRoutes: ({ bind }) => {
569
- for (const [externalRef, absoluteRef] of boundRoutes) {
570
- bind(
571
- { ref: externalRef },
572
- {
573
- ref: absoluteRef
574
- }
575
- );
576
- }
577
- }
578
- });
579
- const routeElements = Object.entries((_a = options.mountedRoutes) != null ? _a : {}).map(
580
- ([path, routeRef]) => {
581
- const Page = () => /* @__PURE__ */ React.createElement("div", null, "Mounted at ", path);
582
- if (isExternalRouteRef(routeRef)) {
583
- const absoluteRef = createRouteRef({ id: "id" });
584
- boundRoutes.set(routeRef, absoluteRef);
585
- attachComponentData(Page, "core.mountPoint", absoluteRef);
586
- } else {
587
- attachComponentData(Page, "core.mountPoint", routeRef);
588
- }
589
- return /* @__PURE__ */ React.createElement(Route, { key: path, path, element: /* @__PURE__ */ React.createElement(Page, null) });
590
- }
591
- );
592
- const AppProvider = app.getProvider();
593
- const AppRouter = app.getRouter();
594
- const TestAppWrapper = ({ children }) => /* @__PURE__ */ React.createElement(AppProvider, null, /* @__PURE__ */ React.createElement(AppRouter, null, /* @__PURE__ */ React.createElement(NoRender, null, routeElements), children));
595
- return TestAppWrapper;
596
- }
597
- function wrapInTestApp(Component, options = {}) {
598
- const TestAppWrapper = createTestAppWrapper(options);
599
- let wrappedElement;
600
- if (Component instanceof Function) {
601
- wrappedElement = React.createElement(Component);
602
- } else {
603
- wrappedElement = Component;
604
- }
605
- return /* @__PURE__ */ React.createElement(TestAppWrapper, null, wrappedElement);
606
- }
607
- async function renderInTestApp(Component, options = {}) {
608
- let wrappedElement;
609
- if (Component instanceof Function) {
610
- wrappedElement = React.createElement(Component);
611
- } else {
612
- wrappedElement = Component;
613
- }
614
- const { legacyRoot } = options;
615
- return renderWithEffects(wrappedElement, {
616
- wrapper: createTestAppWrapper(options),
617
- legacyRoot
618
- });
619
- }
620
- const textContentMatcher = (text) => (_, node) => {
621
- if (!node) {
622
- return false;
623
- }
624
- const hasText = (textNode) => {
625
- var _a, _b;
626
- return (_b = (_a = textNode == null ? void 0 : textNode.textContent) == null ? void 0 : _a.includes(text)) != null ? _b : false;
627
- };
628
- const childrenDontHaveText = (containerNode) => Array.from(containerNode == null ? void 0 : containerNode.children).every((child) => !hasText(child));
629
- return hasText(node) && childrenDontHaveText(node);
630
- };
631
-
632
- function setupRequestMockHandlers(worker) {
633
- beforeAll(() => worker.listen({ onUnhandledRequest: "error" }));
634
- afterAll(() => worker.close());
635
- afterEach(() => worker.resetHandlers());
636
- }
637
-
638
- const allCategories = ["log", "warn", "error"];
639
- function withLogCollector(logsToCollect, callback) {
640
- const oneArg = !callback;
641
- const actualCallback = oneArg ? logsToCollect : callback;
642
- const categories = oneArg ? allCategories : logsToCollect;
643
- const logs = {
644
- log: new Array(),
645
- warn: new Array(),
646
- error: new Array()
647
- };
648
- const origLog = console.log;
649
- const origWarn = console.warn;
650
- const origError = console.error;
651
- if (categories.includes("log")) {
652
- console.log = (message) => {
653
- logs.log.push(message);
654
- };
655
- }
656
- if (categories.includes("warn")) {
657
- console.warn = (message) => {
658
- logs.warn.push(message);
659
- };
660
- }
661
- if (categories.includes("error")) {
662
- console.error = (message) => {
663
- logs.error.push(message);
664
- };
665
- }
666
- const restore = () => {
667
- console.log = origLog;
668
- console.warn = origWarn;
669
- console.error = origError;
670
- };
671
- try {
672
- const ret = actualCallback();
673
- if (!ret || !ret.then) {
674
- restore();
675
- return logs;
676
- }
677
- return ret.then(
678
- () => {
679
- restore();
680
- return logs;
681
- },
682
- (error) => {
683
- restore();
684
- throw error;
685
- }
686
- );
687
- } catch (error) {
688
- restore();
689
- throw error;
690
- }
691
- }
692
-
693
- class TestApiRegistry {
694
- constructor(apis) {
695
- this.apis = apis;
696
- }
697
- /**
698
- * Creates a new {@link TestApiRegistry} with a list of API implementation pairs.
699
- *
700
- * Similar to the {@link TestApiProvider}, there is no need to provide a full
701
- * implementation of each API, it's enough to implement the methods that are tested.
702
- *
703
- * @example
704
- * ```ts
705
- * const apis = TestApiRegistry.from(
706
- * [configApiRef, new ConfigReader({})],
707
- * [identityApiRef, { getUserId: () => 'tester' }],
708
- * );
709
- * ```
710
- *
711
- * @public
712
- * @param apis - A list of pairs mapping an ApiRef to its respective implementation.
713
- */
714
- static from(...apis) {
715
- return new TestApiRegistry(
716
- new Map(apis.map(([api, impl]) => [api.id, impl]))
717
- );
718
- }
719
- /**
720
- * Returns an implementation of the API.
721
- *
722
- * @public
723
- */
724
- get(api) {
725
- return this.apis.get(api.id);
726
- }
727
- }
728
- const TestApiProvider = (props) => {
729
- return /* @__PURE__ */ React.createElement(
730
- ApiProvider,
731
- {
732
- apis: TestApiRegistry.from(...props.apis),
733
- children: props.children
734
- }
735
- );
736
- };
737
-
738
- export { MockAnalyticsApi, MockConfigApi, MockErrorApi, MockFetchApi, MockPermissionApi, MockStorageApi, TestApiProvider, TestApiRegistry, createTestAppWrapper, mockBreakpoint, renderInTestApp, renderWithEffects, setupRequestMockHandlers, textContentMatcher, withLogCollector, wrapInTestApp };
1
+ export { MockAnalyticsApi } from './testUtils/apis/AnalyticsApi/MockAnalyticsApi.esm.js';
2
+ export { MockConfigApi } from './testUtils/apis/ConfigApi/MockConfigApi.esm.js';
3
+ export { MockErrorApi } from './testUtils/apis/ErrorApi/MockErrorApi.esm.js';
4
+ export { MockFetchApi } from './testUtils/apis/FetchApi/MockFetchApi.esm.js';
5
+ export { MockPermissionApi } from './testUtils/apis/PermissionApi/MockPermissionApi.esm.js';
6
+ export { MockStorageApi } from './testUtils/apis/StorageApi/MockStorageApi.esm.js';
7
+ export { default as mockBreakpoint } from './testUtils/mockBreakpoint.esm.js';
8
+ export { createTestAppWrapper, renderInTestApp, textContentMatcher, wrapInTestApp } from './testUtils/appWrappers.esm.js';
9
+ export { setupRequestMockHandlers } from './testUtils/msw/setupRequestMockHandlers.esm.js';
10
+ export { withLogCollector } from './testUtils/logCollector.esm.js';
11
+ export { renderWithEffects } from './testUtils/testingLibrary.esm.js';
12
+ export { TestApiProvider, TestApiRegistry } from './testUtils/TestApiProvider.esm.js';
739
13
  //# sourceMappingURL=index.esm.js.map