@backstage/test-utils 1.5.4-next.0 → 1.5.5-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 +27 -0
- package/alpha/package.json +1 -1
- package/dist/alpha.esm.js +1 -3
- package/dist/alpha.esm.js.map +1 -1
- package/dist/core-plugin-api/src/translation/TranslationRef.esm.js +13 -0
- package/dist/core-plugin-api/src/translation/TranslationRef.esm.js.map +1 -0
- package/dist/index.esm.js +12 -738
- package/dist/index.esm.js.map +1 -1
- package/dist/testUtils/TestApiProvider.esm.js +50 -0
- package/dist/testUtils/TestApiProvider.esm.js.map +1 -0
- package/dist/testUtils/apis/AnalyticsApi/MockAnalyticsApi.esm.js +27 -0
- package/dist/testUtils/apis/AnalyticsApi/MockAnalyticsApi.esm.js.map +1 -0
- package/dist/testUtils/apis/ConfigApi/MockConfigApi.esm.js +82 -0
- package/dist/testUtils/apis/ConfigApi/MockConfigApi.esm.js.map +1 -0
- package/dist/testUtils/apis/ErrorApi/MockErrorApi.esm.js +50 -0
- package/dist/testUtils/apis/ErrorApi/MockErrorApi.esm.js.map +1 -0
- package/dist/testUtils/apis/FetchApi/MockFetchApi.esm.js +63 -0
- package/dist/testUtils/apis/FetchApi/MockFetchApi.esm.js.map +1 -0
- package/dist/testUtils/apis/PermissionApi/MockPermissionApi.esm.js +13 -0
- package/dist/testUtils/apis/PermissionApi/MockPermissionApi.esm.js.map +1 -0
- package/dist/testUtils/apis/StorageApi/MockStorageApi.esm.js +92 -0
- package/dist/testUtils/apis/StorageApi/MockStorageApi.esm.js.map +1 -0
- package/dist/{esm/MockTranslationApi-Dl_xfoCj.esm.js → testUtils/apis/TranslationApi/MockTranslationApi.esm.js} +5 -15
- package/dist/testUtils/apis/TranslationApi/MockTranslationApi.esm.js.map +1 -0
- package/dist/testUtils/appWrappers.esm.js +143 -0
- package/dist/testUtils/appWrappers.esm.js.map +1 -0
- package/dist/testUtils/defaultApis.esm.js +148 -0
- package/dist/testUtils/defaultApis.esm.js.map +1 -0
- package/dist/testUtils/logCollector.esm.js +57 -0
- package/dist/testUtils/logCollector.esm.js.map +1 -0
- package/dist/testUtils/mockApis.esm.js +18 -0
- package/dist/testUtils/mockApis.esm.js.map +1 -0
- package/dist/testUtils/mockBreakpoint.esm.js +23 -0
- package/dist/testUtils/mockBreakpoint.esm.js.map +1 -0
- package/dist/testUtils/msw/setupRequestMockHandlers.esm.js +8 -0
- package/dist/testUtils/msw/setupRequestMockHandlers.esm.js.map +1 -0
- package/dist/testUtils/testingLibrary.esm.js +12 -0
- package/dist/testUtils/testingLibrary.esm.js.map +1 -0
- package/package.json +7 -7
- package/dist/esm/MockTranslationApi-Dl_xfoCj.esm.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MockStorageApi.esm.js","sources":["../../../../src/testUtils/apis/StorageApi/MockStorageApi.ts"],"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 { StorageApi, StorageValueSnapshot } from '@backstage/core-plugin-api';\nimport { JsonValue, Observable } from '@backstage/types';\nimport ObservableImpl from 'zen-observable';\n\n/**\n * Type for map holding data in {@link MockStorageApi}\n * @public\n */\nexport type MockStorageBucket = { [key: string]: any };\n\n/**\n * Mock implementation of the {@link core-plugin-api#StorageApi} to be used in tests\n * @public\n */\nexport class MockStorageApi implements StorageApi {\n private readonly namespace: string;\n private readonly data: MockStorageBucket;\n private readonly bucketStorageApis: Map<string, MockStorageApi>;\n\n private constructor(\n namespace: string,\n bucketStorageApis: Map<string, MockStorageApi>,\n data?: MockStorageBucket,\n ) {\n this.namespace = namespace;\n this.bucketStorageApis = bucketStorageApis;\n this.data = { ...data };\n }\n\n static create(data?: MockStorageBucket) {\n return new MockStorageApi('', new Map(), data);\n }\n\n forBucket(name: string): StorageApi {\n if (!this.bucketStorageApis.has(name)) {\n this.bucketStorageApis.set(\n name,\n new MockStorageApi(\n `${this.namespace}/${name}`,\n this.bucketStorageApis,\n this.data,\n ),\n );\n }\n return this.bucketStorageApis.get(name)!;\n }\n\n snapshot<T extends JsonValue>(key: string): StorageValueSnapshot<T> {\n if (this.data.hasOwnProperty(this.getKeyName(key))) {\n const data = this.data[this.getKeyName(key)];\n return {\n key,\n presence: 'present',\n value: data,\n };\n }\n return {\n key,\n presence: 'absent',\n value: undefined,\n };\n }\n\n async set<T>(key: string, data: T): Promise<void> {\n const serialized = JSON.parse(JSON.stringify(data), (_key, value) => {\n if (typeof value === 'object' && value !== null) {\n Object.freeze(value);\n }\n return value;\n });\n this.data[this.getKeyName(key)] = serialized;\n this.notifyChanges({\n key,\n presence: 'present',\n value: serialized,\n });\n }\n\n async remove(key: string): Promise<void> {\n delete this.data[this.getKeyName(key)];\n this.notifyChanges({\n key,\n presence: 'absent',\n value: undefined,\n });\n }\n\n observe$<T extends JsonValue>(\n key: string,\n ): Observable<StorageValueSnapshot<T>> {\n return this.observable.filter(({ key: messageKey }) => messageKey === key);\n }\n\n private getKeyName(key: string) {\n return `${this.namespace}/${encodeURIComponent(key)}`;\n }\n\n private notifyChanges<T extends JsonValue>(message: StorageValueSnapshot<T>) {\n for (const subscription of this.subscribers) {\n subscription.next(message);\n }\n }\n\n private subscribers = new Set<\n ZenObservable.SubscriptionObserver<StorageValueSnapshot<JsonValue>>\n >();\n\n private readonly observable = new ObservableImpl<\n StorageValueSnapshot<JsonValue>\n >(subscriber => {\n this.subscribers.add(subscriber);\n return () => {\n this.subscribers.delete(subscriber);\n };\n });\n}\n"],"names":[],"mappings":";;;;;;;;AA8BO,MAAM,cA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ACvC,IAAA,OAAO,IAAK,CAAA,IAAA,CAAK,IAAK,CAAA,UAAA,CAAW,GAAG,CAAC,CAAA,CAAA;AACrC,IAAA,IAAA,CAAK,aAAc,CAAA;AAAA,MACjB,GAAA;AAAA,MACA,QAAU,EAAA,QAAA;AAAA,MACV,KAAO,EAAA,KAAA,CAAA;AAAA,KACR,CAAA,CAAA;AAAA,GACH;AAAA,EAEA,SACE,GACqC,EAAA;AACrC,IAAO,OAAA,IAAA,CAAK,WAAW,MAAO,CAAA,CAAC,EAAE,GAAK,EAAA,UAAA,EAAiB,KAAA,UAAA,KAAe,GAAG,CAAA,CAAA;AAAA,GAC3E;AAAA,EAEQ,WAAW,GAAa,EAAA;AAC9B,IAAA,OAAO,GAAG,IAAK,CAAA,SAAS,CAAI,CAAA,EAAA,kBAAA,CAAmB,GAAG,CAAC,CAAA,CAAA,CAAA;AAAA,GACrD;AAAA,EAEQ,cAAmC,OAAkC,EAAA;AAC3E,IAAW,KAAA,MAAA,YAAA,IAAgB,KAAK,WAAa,EAAA;AAC3C,MAAA,YAAA,CAAa,KAAK,OAAO,CAAA,CAAA;AAAA,KAC3B;AAAA,GACF;AAcF;;;;"}
|
|
@@ -1,16 +1,6 @@
|
|
|
1
1
|
import { createInstance } from 'i18next';
|
|
2
2
|
import ObservableImpl from 'zen-observable';
|
|
3
|
-
|
|
4
|
-
function toInternalTranslationRef(ref) {
|
|
5
|
-
const r = ref;
|
|
6
|
-
if (r.$$type !== "@backstage/TranslationRef") {
|
|
7
|
-
throw new Error(`Invalid translation ref, bad type '${r.$$type}'`);
|
|
8
|
-
}
|
|
9
|
-
if (r.version !== "v1") {
|
|
10
|
-
throw new Error(`Invalid translation ref, bad version '${r.version}'`);
|
|
11
|
-
}
|
|
12
|
-
return r;
|
|
13
|
-
}
|
|
3
|
+
import { toInternalTranslationRef } from '../../../core-plugin-api/src/translation/TranslationRef.esm.js';
|
|
14
4
|
|
|
15
5
|
var __accessCheck = (obj, member, msg) => {
|
|
16
6
|
if (!member.has(obj))
|
|
@@ -18,7 +8,7 @@ var __accessCheck = (obj, member, msg) => {
|
|
|
18
8
|
};
|
|
19
9
|
var __privateGet = (obj, member, getter) => {
|
|
20
10
|
__accessCheck(obj, member, "read from private field");
|
|
21
|
-
return
|
|
11
|
+
return member.get(obj);
|
|
22
12
|
};
|
|
23
13
|
var __privateAdd = (obj, member, value) => {
|
|
24
14
|
if (member.has(obj))
|
|
@@ -27,7 +17,7 @@ var __privateAdd = (obj, member, value) => {
|
|
|
27
17
|
};
|
|
28
18
|
var __privateSet = (obj, member, value, setter) => {
|
|
29
19
|
__accessCheck(obj, member, "write to private field");
|
|
30
|
-
|
|
20
|
+
member.set(obj, value);
|
|
31
21
|
return value;
|
|
32
22
|
};
|
|
33
23
|
var _i18n, _registeredRefs;
|
|
@@ -91,5 +81,5 @@ _i18n = new WeakMap();
|
|
|
91
81
|
_registeredRefs = new WeakMap();
|
|
92
82
|
let MockTranslationApi = _MockTranslationApi;
|
|
93
83
|
|
|
94
|
-
export { MockTranslationApi
|
|
95
|
-
//# sourceMappingURL=MockTranslationApi
|
|
84
|
+
export { MockTranslationApi };
|
|
85
|
+
//# sourceMappingURL=MockTranslationApi.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MockTranslationApi.esm.js","sources":["../../../../src/testUtils/apis/TranslationApi/MockTranslationApi.ts"],"sourcesContent":["/*\n * Copyright 2023 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 {\n TranslationApi,\n TranslationFunction,\n TranslationRef,\n TranslationSnapshot,\n} from '@backstage/core-plugin-api/alpha';\nimport { createInstance as createI18n, type i18n as I18n } from 'i18next';\nimport ObservableImpl from 'zen-observable';\n\nimport { Observable } from '@backstage/types';\n// Internal import to avoid code duplication, this will lead to duplication in build output\n// eslint-disable-next-line @backstage/no-relative-monorepo-imports\nimport { toInternalTranslationRef } from '../../../../../core-plugin-api/src/translation/TranslationRef';\n\nconst DEFAULT_LANGUAGE = 'en';\n\n/** @alpha */\nexport class MockTranslationApi implements TranslationApi {\n static create() {\n const i18n = createI18n({\n fallbackLng: DEFAULT_LANGUAGE,\n supportedLngs: [DEFAULT_LANGUAGE],\n interpolation: {\n escapeValue: false,\n },\n ns: [],\n defaultNS: false,\n fallbackNS: false,\n\n // Disable resource loading on init, meaning i18n will be ready to use immediately\n initImmediate: false,\n });\n\n i18n.init();\n if (!i18n.isInitialized) {\n throw new Error('i18next was unexpectedly not initialized');\n }\n\n return new MockTranslationApi(i18n);\n }\n\n #i18n: I18n;\n #registeredRefs = new Set<string>();\n\n private constructor(i18n: I18n) {\n this.#i18n = i18n;\n }\n\n getTranslation<TMessages extends { [key in string]: string }>(\n translationRef: TranslationRef<string, TMessages>,\n ): TranslationSnapshot<TMessages> {\n const internalRef = toInternalTranslationRef(translationRef);\n\n if (!this.#registeredRefs.has(internalRef.id)) {\n this.#registeredRefs.add(internalRef.id);\n this.#i18n.addResourceBundle(\n DEFAULT_LANGUAGE,\n internalRef.id,\n internalRef.getDefaultMessages(),\n false, // do not merge\n true, // overwrite existing\n );\n }\n\n const t = this.#i18n.getFixedT(\n null,\n internalRef.id,\n ) as TranslationFunction<TMessages>;\n\n return {\n ready: true,\n t,\n };\n }\n\n translation$<TMessages extends { [key in string]: string }>(): Observable<\n TranslationSnapshot<TMessages>\n > {\n // No need to implement, getTranslation will always return a ready snapshot\n return new ObservableImpl<TranslationSnapshot<TMessages>>(_subscriber => {\n return () => {};\n });\n }\n}\n"],"names":["createI18n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,IAAA,KAAA,EAAA,e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AA,EAAK,KAAM,CAAA,CAAA,iBAAA;AAAA,QACT,gBAAA;AAAA,QACA,WAAY,CAAA,EAAA;AAAA,QACZ,YAAY,kBAAmB,EAAA;AAAA,QAC/B,KAAA;AAAA;AAAA,QACA,IAAA;AAAA;AAAA,OACF,CAAA;AAAA,KACF;AAEA,IAAM,MAAA,CAAA,GAAI,mBAAK,KAAM,CAAA,CAAA,SAAA;AAAA,MACnB,IAAA;AAAA,MACA,WAAY,CAAA,EAAA;AAAA,KACd,CAAA;AAEA,IAAO,OAAA;AAAA,MACL,KAAO,EAAA,IAAA;AAAA,MACP,CAAA;AAAA,KACF,CAAA;AAAA,GACF;AAAA,EAEA,YAEE,GAAA;AAEA,IAAO,OAAA,IAAI,eAA+C,CAAe,WAAA,KAAA;AACvE,MAAA,OAAO,MAAM;AAAA,OAAC,CAAA;AAAA,KACf,CAAA,CAAA;AAAA,GACH;AACF,CAAA,CAAA;AA1CE,KAAA,GAAA,IAAA,OAAA,EAAA,CAAA;AACA,eAAA,GAAA,IAAA,OAAA,EAAA,CAAA;AAzBK,IAAM,kBAAN,GAAA;;;;"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { MemoryRouter, Route } from 'react-router-dom';
|
|
3
|
+
import { UnifiedThemeProvider, themes } from '@backstage/theme';
|
|
4
|
+
import MockIcon from '@material-ui/icons/AcUnit';
|
|
5
|
+
import { createSpecializedApp } from '@backstage/core-app-api';
|
|
6
|
+
import { createRouteRef, attachComponentData } from '@backstage/core-plugin-api';
|
|
7
|
+
import { renderWithEffects } from './testingLibrary.esm.js';
|
|
8
|
+
import { defaultApis } from './defaultApis.esm.js';
|
|
9
|
+
import { mockApis } from './mockApis.esm.js';
|
|
10
|
+
|
|
11
|
+
const mockIcons = {
|
|
12
|
+
"kind:api": MockIcon,
|
|
13
|
+
"kind:component": MockIcon,
|
|
14
|
+
"kind:domain": MockIcon,
|
|
15
|
+
"kind:group": MockIcon,
|
|
16
|
+
"kind:location": MockIcon,
|
|
17
|
+
"kind:system": MockIcon,
|
|
18
|
+
"kind:user": MockIcon,
|
|
19
|
+
"kind:resource": MockIcon,
|
|
20
|
+
"kind:template": MockIcon,
|
|
21
|
+
brokenImage: MockIcon,
|
|
22
|
+
catalog: MockIcon,
|
|
23
|
+
scaffolder: MockIcon,
|
|
24
|
+
techdocs: MockIcon,
|
|
25
|
+
search: MockIcon,
|
|
26
|
+
chat: MockIcon,
|
|
27
|
+
dashboard: MockIcon,
|
|
28
|
+
docs: MockIcon,
|
|
29
|
+
email: MockIcon,
|
|
30
|
+
github: MockIcon,
|
|
31
|
+
group: MockIcon,
|
|
32
|
+
help: MockIcon,
|
|
33
|
+
user: MockIcon,
|
|
34
|
+
warning: MockIcon
|
|
35
|
+
};
|
|
36
|
+
const ErrorBoundaryFallback = ({ error }) => {
|
|
37
|
+
throw new Error(`Reached ErrorBoundaryFallback Page with error, ${error}`);
|
|
38
|
+
};
|
|
39
|
+
const NotFoundErrorPage = () => {
|
|
40
|
+
throw new Error("Reached NotFound Page");
|
|
41
|
+
};
|
|
42
|
+
const BootErrorPage = ({ step, error }) => {
|
|
43
|
+
throw new Error(`Reached BootError Page at step ${step} with error ${error}`);
|
|
44
|
+
};
|
|
45
|
+
const Progress = () => /* @__PURE__ */ React.createElement("div", { "data-testid": "progress" });
|
|
46
|
+
const NoRender = (_props) => null;
|
|
47
|
+
function isExternalRouteRef(routeRef) {
|
|
48
|
+
return String(routeRef).includes("{type=external,");
|
|
49
|
+
}
|
|
50
|
+
function createTestAppWrapper(options = {}) {
|
|
51
|
+
var _a;
|
|
52
|
+
const { routeEntries = ["/"] } = options;
|
|
53
|
+
const boundRoutes = /* @__PURE__ */ new Map();
|
|
54
|
+
const app = createSpecializedApp({
|
|
55
|
+
apis: mockApis,
|
|
56
|
+
defaultApis,
|
|
57
|
+
// Bit of a hack to make sure that the default config loader isn't used
|
|
58
|
+
// as that would force every single test to wait for config loading.
|
|
59
|
+
configLoader: false,
|
|
60
|
+
components: {
|
|
61
|
+
Progress,
|
|
62
|
+
BootErrorPage,
|
|
63
|
+
NotFoundErrorPage,
|
|
64
|
+
ErrorBoundaryFallback,
|
|
65
|
+
Router: ({ children }) => /* @__PURE__ */ React.createElement(MemoryRouter, { initialEntries: routeEntries, children }),
|
|
66
|
+
...options.components
|
|
67
|
+
},
|
|
68
|
+
icons: mockIcons,
|
|
69
|
+
plugins: [],
|
|
70
|
+
themes: [
|
|
71
|
+
{
|
|
72
|
+
id: "light",
|
|
73
|
+
title: "Test App Theme",
|
|
74
|
+
variant: "light",
|
|
75
|
+
Provider: ({ children }) => /* @__PURE__ */ React.createElement(UnifiedThemeProvider, { theme: themes.light }, children)
|
|
76
|
+
}
|
|
77
|
+
],
|
|
78
|
+
bindRoutes: ({ bind }) => {
|
|
79
|
+
for (const [externalRef, absoluteRef] of boundRoutes) {
|
|
80
|
+
bind(
|
|
81
|
+
{ ref: externalRef },
|
|
82
|
+
{
|
|
83
|
+
ref: absoluteRef
|
|
84
|
+
}
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
const routeElements = Object.entries((_a = options.mountedRoutes) != null ? _a : {}).map(
|
|
90
|
+
([path, routeRef]) => {
|
|
91
|
+
const Page = () => /* @__PURE__ */ React.createElement("div", null, "Mounted at ", path);
|
|
92
|
+
if (isExternalRouteRef(routeRef)) {
|
|
93
|
+
const absoluteRef = createRouteRef({ id: "id" });
|
|
94
|
+
boundRoutes.set(routeRef, absoluteRef);
|
|
95
|
+
attachComponentData(Page, "core.mountPoint", absoluteRef);
|
|
96
|
+
} else {
|
|
97
|
+
attachComponentData(Page, "core.mountPoint", routeRef);
|
|
98
|
+
}
|
|
99
|
+
return /* @__PURE__ */ React.createElement(Route, { key: path, path, element: /* @__PURE__ */ React.createElement(Page, null) });
|
|
100
|
+
}
|
|
101
|
+
);
|
|
102
|
+
const AppProvider = app.getProvider();
|
|
103
|
+
const AppRouter = app.getRouter();
|
|
104
|
+
const TestAppWrapper = ({ children }) => /* @__PURE__ */ React.createElement(AppProvider, null, /* @__PURE__ */ React.createElement(AppRouter, null, /* @__PURE__ */ React.createElement(NoRender, null, routeElements), children));
|
|
105
|
+
return TestAppWrapper;
|
|
106
|
+
}
|
|
107
|
+
function wrapInTestApp(Component, options = {}) {
|
|
108
|
+
const TestAppWrapper = createTestAppWrapper(options);
|
|
109
|
+
let wrappedElement;
|
|
110
|
+
if (Component instanceof Function) {
|
|
111
|
+
wrappedElement = React.createElement(Component);
|
|
112
|
+
} else {
|
|
113
|
+
wrappedElement = Component;
|
|
114
|
+
}
|
|
115
|
+
return /* @__PURE__ */ React.createElement(TestAppWrapper, null, wrappedElement);
|
|
116
|
+
}
|
|
117
|
+
async function renderInTestApp(Component, options = {}) {
|
|
118
|
+
let wrappedElement;
|
|
119
|
+
if (Component instanceof Function) {
|
|
120
|
+
wrappedElement = React.createElement(Component);
|
|
121
|
+
} else {
|
|
122
|
+
wrappedElement = Component;
|
|
123
|
+
}
|
|
124
|
+
const { legacyRoot } = options;
|
|
125
|
+
return renderWithEffects(wrappedElement, {
|
|
126
|
+
wrapper: createTestAppWrapper(options),
|
|
127
|
+
legacyRoot
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
const textContentMatcher = (text) => (_, node) => {
|
|
131
|
+
if (!node) {
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
const hasText = (textNode) => {
|
|
135
|
+
var _a, _b;
|
|
136
|
+
return (_b = (_a = textNode == null ? void 0 : textNode.textContent) == null ? void 0 : _a.includes(text)) != null ? _b : false;
|
|
137
|
+
};
|
|
138
|
+
const childrenDontHaveText = (containerNode) => Array.from(containerNode == null ? void 0 : containerNode.children).every((child) => !hasText(child));
|
|
139
|
+
return hasText(node) && childrenDontHaveText(node);
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
export { createTestAppWrapper, renderInTestApp, textContentMatcher, wrapInTestApp };
|
|
143
|
+
//# sourceMappingURL=appWrappers.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"appWrappers.esm.js","sources":["../../src/testUtils/appWrappers.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, {\n ComponentType,\n PropsWithChildren,\n ReactElement,\n ReactNode,\n} from 'react';\nimport { MemoryRouter, Route } from 'react-router-dom';\nimport { themes, UnifiedThemeProvider } from '@backstage/theme';\nimport MockIcon from '@material-ui/icons/AcUnit';\nimport { createSpecializedApp } from '@backstage/core-app-api';\nimport {\n AppComponents,\n attachComponentData,\n BootErrorPageProps,\n createRouteRef,\n ExternalRouteRef,\n RouteRef,\n} from '@backstage/core-plugin-api';\nimport { MatcherFunction, RenderResult } from '@testing-library/react';\nimport { LegacyRootOption, renderWithEffects } from './testingLibrary';\nimport { defaultApis } from './defaultApis';\nimport { mockApis } from './mockApis';\n\nconst mockIcons = {\n 'kind:api': MockIcon,\n 'kind:component': MockIcon,\n 'kind:domain': MockIcon,\n 'kind:group': MockIcon,\n 'kind:location': MockIcon,\n 'kind:system': MockIcon,\n 'kind:user': MockIcon,\n 'kind:resource': MockIcon,\n 'kind:template': MockIcon,\n\n brokenImage: MockIcon,\n catalog: MockIcon,\n scaffolder: MockIcon,\n techdocs: MockIcon,\n search: MockIcon,\n chat: MockIcon,\n dashboard: MockIcon,\n docs: MockIcon,\n email: MockIcon,\n github: MockIcon,\n group: MockIcon,\n help: MockIcon,\n user: MockIcon,\n warning: MockIcon,\n};\n\nconst ErrorBoundaryFallback = ({ error }: { error: Error }) => {\n throw new Error(`Reached ErrorBoundaryFallback Page with error, ${error}`);\n};\nconst NotFoundErrorPage = () => {\n throw new Error('Reached NotFound Page');\n};\nconst BootErrorPage = ({ step, error }: BootErrorPageProps) => {\n throw new Error(`Reached BootError Page at step ${step} with error ${error}`);\n};\nconst Progress = () => <div data-testid=\"progress\" />;\n\nconst NoRender = (_props: { children: ReactNode }) => null;\n\n/**\n * Options to customize the behavior of the test app wrapper.\n * @public\n */\nexport type TestAppOptions = {\n /**\n * Initial route entries to pass along as `initialEntries` to the router.\n */\n routeEntries?: string[];\n\n /**\n * An object of paths to mount route ref on, with the key being the path and the value\n * being the RouteRef that the path will be bound to. This allows the route refs to be\n * used by `useRouteRef` in the rendered elements.\n *\n * @example\n * wrapInTestApp(<MyComponent />, \\{\n * mountedRoutes: \\{\n * '/my-path': myRouteRef,\n * \\}\n * \\})\n * // ...\n * const link = useRouteRef(myRouteRef)\n */\n mountedRoutes?: { [path: string]: RouteRef | ExternalRouteRef };\n\n /**\n * Components to be forwarded to the `components` option of `createApp`.\n */\n components?: Partial<AppComponents>;\n};\n\nfunction isExternalRouteRef(\n routeRef: RouteRef | ExternalRouteRef,\n): routeRef is ExternalRouteRef {\n // TODO(Rugvip): Least ugly workaround for now, but replace :D\n return String(routeRef).includes('{type=external,');\n}\n\n/**\n * Creates a Wrapper component that wraps a component inside a Backstage test app,\n * providing a mocked theme and app context, along with mocked APIs.\n *\n * @param options - Additional options for the rendering.\n * @public\n */\nexport function createTestAppWrapper(\n options: TestAppOptions = {},\n): (props: { children: ReactNode }) => JSX.Element {\n const { routeEntries = ['/'] } = options;\n const boundRoutes = new Map<ExternalRouteRef, RouteRef>();\n\n const app = createSpecializedApp({\n apis: mockApis,\n defaultApis,\n // Bit of a hack to make sure that the default config loader isn't used\n // as that would force every single test to wait for config loading.\n configLoader: false as unknown as undefined,\n components: {\n Progress,\n BootErrorPage,\n NotFoundErrorPage,\n ErrorBoundaryFallback,\n Router: ({ children }) => (\n <MemoryRouter initialEntries={routeEntries} children={children} />\n ),\n ...options.components,\n },\n icons: mockIcons,\n plugins: [],\n themes: [\n {\n id: 'light',\n title: 'Test App Theme',\n variant: 'light',\n Provider: ({ children }) => (\n <UnifiedThemeProvider theme={themes.light}>\n {children}\n </UnifiedThemeProvider>\n ),\n },\n ],\n bindRoutes: ({ bind }) => {\n for (const [externalRef, absoluteRef] of boundRoutes) {\n bind(\n { ref: externalRef },\n {\n ref: absoluteRef,\n },\n );\n }\n },\n });\n\n const routeElements = Object.entries(options.mountedRoutes ?? {}).map(\n ([path, routeRef]) => {\n const Page = () => <div>Mounted at {path}</div>;\n\n // Allow external route refs to be bound to paths as well, for convenience.\n // We work around it by creating and binding an absolute ref to the external one.\n if (isExternalRouteRef(routeRef)) {\n const absoluteRef = createRouteRef({ id: 'id' });\n boundRoutes.set(routeRef, absoluteRef);\n attachComponentData(Page, 'core.mountPoint', absoluteRef);\n } else {\n attachComponentData(Page, 'core.mountPoint', routeRef);\n }\n return <Route key={path} path={path} element={<Page />} />;\n },\n );\n\n const AppProvider = app.getProvider();\n const AppRouter = app.getRouter();\n\n const TestAppWrapper = ({ children }: { children: ReactNode }) => (\n <AppProvider>\n <AppRouter>\n <NoRender>{routeElements}</NoRender>\n {children}\n </AppRouter>\n </AppProvider>\n );\n\n return TestAppWrapper;\n}\n\n/**\n * Wraps a component inside a Backstage test app, providing a mocked theme\n * and app context, along with mocked APIs.\n *\n * @param Component - A component or react node to render inside the test app.\n * @param options - Additional options for the rendering.\n * @public\n */\nexport function wrapInTestApp(\n Component: ComponentType | ReactNode,\n options: TestAppOptions = {},\n): ReactElement {\n const TestAppWrapper = createTestAppWrapper(options);\n\n let wrappedElement: React.ReactElement;\n if (Component instanceof Function) {\n wrappedElement = React.createElement(Component as ComponentType);\n } else {\n wrappedElement = Component as React.ReactElement;\n }\n\n return <TestAppWrapper>{wrappedElement}</TestAppWrapper>;\n}\n\n/**\n * Renders a component inside a Backstage test app, providing a mocked theme\n * and app context, along with mocked APIs.\n *\n * The render executes async effects similar to `renderWithEffects`. To avoid this\n * behavior, use a regular `render()` + `wrapInTestApp()` instead.\n *\n * @param Component - A component or react node to render inside the test app.\n * @param options - Additional options for the rendering.\n * @public\n */\nexport async function renderInTestApp(\n Component: ComponentType<PropsWithChildren<{}>> | ReactNode,\n options: TestAppOptions & LegacyRootOption = {},\n): Promise<RenderResult> {\n let wrappedElement: React.ReactElement;\n if (Component instanceof Function) {\n wrappedElement = React.createElement(Component as ComponentType);\n } else {\n wrappedElement = Component as React.ReactElement;\n }\n const { legacyRoot } = options;\n\n return renderWithEffects(wrappedElement, {\n wrapper: createTestAppWrapper(options),\n legacyRoot,\n });\n}\n\n/**\n * Returns a `@testing-library/react` valid MatcherFunction for supplied text\n *\n * @param string - text Text to match by element's textContent\n *\n * @public\n */\nexport const textContentMatcher =\n (text: string): MatcherFunction =>\n (_, node) => {\n if (!node) {\n return false;\n }\n\n const hasText = (textNode: Element) =>\n textNode?.textContent?.includes(text) ?? false;\n const childrenDontHaveText = (containerNode: Element) =>\n Array.from(containerNode?.children).every(child => !hasText(child));\n\n return hasText(node) && childrenDontHaveText(node);\n };\n"],"names":[],"mappings":";;;;;;;;;;AAuCA,MAAM,SAAY,GAAA;AAAA,EAChB,UAAY,EAAA,QAAA;AAAA,EACZ,gBAAkB,EAAA,QAAA;AAAA,EAClB,aAAe,EAAA,QAAA;AAAA,EACf,YAAc,EAAA,QAAA;AAAA,EACd,eAAiB,EAAA,QAAA;AAAA,EACjB,aAAe,EAAA,QAAA;AAAA,EACf,WAAa,EAAA,QAAA;AAAA,EACb,eAAiB,EAAA,QAAA;AAAA,EACjB,eAAiB,EAAA,QAAA;AAAA,EAEjB,WAAa,EAAA,QAAA;AAAA,EACb,OAAS,EAAA,QAAA;AAAA,EACT,UAAY,EAAA,QAAA;AAAA,EACZ,QAAU,EAAA,QAAA;AAAA,EACV,MAAQ,EAAA,QAAA;AAAA,EACR,IAAM,EAAA,QAAA;AAAA,EACN,SAAW,EAAA,Q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AAA,CAAQ,KAAK,CAAC,CAAA,CAAA;AAEpE,EAAA,OAAO,OAAQ,CAAA,IAAI,CAAK,IAAA,oBAAA,CAAqB,IAAI,CAAA,CAAA;AACnD;;;;"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { UrlPatternDiscovery, AlertApiForwarder, NoOpAnalyticsApi, ErrorAlerter, ErrorApiForwarder, UnhandledErrorForwarder, WebStorage, OAuthRequestManager, GoogleAuth, MicrosoftAuth, GithubAuth, OktaAuth, GitlabAuth, OneLoginAuth, BitbucketAuth, AtlassianAuth } from '@backstage/core-app-api';
|
|
2
|
+
import { createApiFactory, discoveryApiRef, configApiRef, alertApiRef, analyticsApiRef, errorApiRef, storageApiRef, oauthRequestApiRef, googleAuthApiRef, microsoftAuthApiRef, githubAuthApiRef, oktaAuthApiRef, gitlabAuthApiRef, oneloginAuthApiRef, bitbucketAuthApiRef, atlassianAuthApiRef } from '@backstage/core-plugin-api';
|
|
3
|
+
|
|
4
|
+
const defaultApis = [
|
|
5
|
+
createApiFactory({
|
|
6
|
+
api: discoveryApiRef,
|
|
7
|
+
deps: { configApi: configApiRef },
|
|
8
|
+
factory: ({ configApi }) => UrlPatternDiscovery.compile(
|
|
9
|
+
`${configApi.getString("backend.baseUrl")}/api/{{ pluginId }}`
|
|
10
|
+
)
|
|
11
|
+
}),
|
|
12
|
+
createApiFactory(alertApiRef, new AlertApiForwarder()),
|
|
13
|
+
createApiFactory(analyticsApiRef, new NoOpAnalyticsApi()),
|
|
14
|
+
createApiFactory({
|
|
15
|
+
api: errorApiRef,
|
|
16
|
+
deps: { alertApi: alertApiRef },
|
|
17
|
+
factory: ({ alertApi }) => {
|
|
18
|
+
const errorApi = new ErrorAlerter(alertApi, new ErrorApiForwarder());
|
|
19
|
+
UnhandledErrorForwarder.forward(errorApi, { hidden: false });
|
|
20
|
+
return errorApi;
|
|
21
|
+
}
|
|
22
|
+
}),
|
|
23
|
+
createApiFactory({
|
|
24
|
+
api: storageApiRef,
|
|
25
|
+
deps: { errorApi: errorApiRef },
|
|
26
|
+
factory: ({ errorApi }) => WebStorage.create({ errorApi })
|
|
27
|
+
}),
|
|
28
|
+
createApiFactory(oauthRequestApiRef, new OAuthRequestManager()),
|
|
29
|
+
createApiFactory({
|
|
30
|
+
api: googleAuthApiRef,
|
|
31
|
+
deps: {
|
|
32
|
+
discoveryApi: discoveryApiRef,
|
|
33
|
+
oauthRequestApi: oauthRequestApiRef,
|
|
34
|
+
configApi: configApiRef
|
|
35
|
+
},
|
|
36
|
+
factory: ({ discoveryApi, oauthRequestApi, configApi }) => GoogleAuth.create({
|
|
37
|
+
configApi,
|
|
38
|
+
discoveryApi,
|
|
39
|
+
oauthRequestApi,
|
|
40
|
+
environment: configApi.getOptionalString("auth.environment")
|
|
41
|
+
})
|
|
42
|
+
}),
|
|
43
|
+
createApiFactory({
|
|
44
|
+
api: microsoftAuthApiRef,
|
|
45
|
+
deps: {
|
|
46
|
+
discoveryApi: discoveryApiRef,
|
|
47
|
+
oauthRequestApi: oauthRequestApiRef,
|
|
48
|
+
configApi: configApiRef
|
|
49
|
+
},
|
|
50
|
+
factory: ({ discoveryApi, oauthRequestApi, configApi }) => MicrosoftAuth.create({
|
|
51
|
+
configApi,
|
|
52
|
+
discoveryApi,
|
|
53
|
+
oauthRequestApi,
|
|
54
|
+
environment: configApi.getOptionalString("auth.environment")
|
|
55
|
+
})
|
|
56
|
+
}),
|
|
57
|
+
createApiFactory({
|
|
58
|
+
api: githubAuthApiRef,
|
|
59
|
+
deps: {
|
|
60
|
+
discoveryApi: discoveryApiRef,
|
|
61
|
+
oauthRequestApi: oauthRequestApiRef,
|
|
62
|
+
configApi: configApiRef
|
|
63
|
+
},
|
|
64
|
+
factory: ({ discoveryApi, oauthRequestApi, configApi }) => GithubAuth.create({
|
|
65
|
+
configApi,
|
|
66
|
+
discoveryApi,
|
|
67
|
+
oauthRequestApi,
|
|
68
|
+
defaultScopes: ["read:user"],
|
|
69
|
+
environment: configApi.getOptionalString("auth.environment")
|
|
70
|
+
})
|
|
71
|
+
}),
|
|
72
|
+
createApiFactory({
|
|
73
|
+
api: oktaAuthApiRef,
|
|
74
|
+
deps: {
|
|
75
|
+
discoveryApi: discoveryApiRef,
|
|
76
|
+
oauthRequestApi: oauthRequestApiRef,
|
|
77
|
+
configApi: configApiRef
|
|
78
|
+
},
|
|
79
|
+
factory: ({ discoveryApi, oauthRequestApi, configApi }) => OktaAuth.create({
|
|
80
|
+
configApi,
|
|
81
|
+
discoveryApi,
|
|
82
|
+
oauthRequestApi,
|
|
83
|
+
environment: configApi.getOptionalString("auth.environment")
|
|
84
|
+
})
|
|
85
|
+
}),
|
|
86
|
+
createApiFactory({
|
|
87
|
+
api: gitlabAuthApiRef,
|
|
88
|
+
deps: {
|
|
89
|
+
discoveryApi: discoveryApiRef,
|
|
90
|
+
oauthRequestApi: oauthRequestApiRef,
|
|
91
|
+
configApi: configApiRef
|
|
92
|
+
},
|
|
93
|
+
factory: ({ discoveryApi, oauthRequestApi, configApi }) => GitlabAuth.create({
|
|
94
|
+
configApi,
|
|
95
|
+
discoveryApi,
|
|
96
|
+
oauthRequestApi,
|
|
97
|
+
environment: configApi.getOptionalString("auth.environment")
|
|
98
|
+
})
|
|
99
|
+
}),
|
|
100
|
+
createApiFactory({
|
|
101
|
+
api: oneloginAuthApiRef,
|
|
102
|
+
deps: {
|
|
103
|
+
discoveryApi: discoveryApiRef,
|
|
104
|
+
oauthRequestApi: oauthRequestApiRef,
|
|
105
|
+
configApi: configApiRef
|
|
106
|
+
},
|
|
107
|
+
factory: ({ discoveryApi, oauthRequestApi, configApi }) => OneLoginAuth.create({
|
|
108
|
+
configApi,
|
|
109
|
+
discoveryApi,
|
|
110
|
+
oauthRequestApi,
|
|
111
|
+
environment: configApi.getOptionalString("auth.environment")
|
|
112
|
+
})
|
|
113
|
+
}),
|
|
114
|
+
createApiFactory({
|
|
115
|
+
api: bitbucketAuthApiRef,
|
|
116
|
+
deps: {
|
|
117
|
+
discoveryApi: discoveryApiRef,
|
|
118
|
+
oauthRequestApi: oauthRequestApiRef,
|
|
119
|
+
configApi: configApiRef
|
|
120
|
+
},
|
|
121
|
+
factory: ({ discoveryApi, oauthRequestApi, configApi }) => BitbucketAuth.create({
|
|
122
|
+
configApi,
|
|
123
|
+
discoveryApi,
|
|
124
|
+
oauthRequestApi,
|
|
125
|
+
defaultScopes: ["account"],
|
|
126
|
+
environment: configApi.getOptionalString("auth.environment")
|
|
127
|
+
})
|
|
128
|
+
}),
|
|
129
|
+
createApiFactory({
|
|
130
|
+
api: atlassianAuthApiRef,
|
|
131
|
+
deps: {
|
|
132
|
+
discoveryApi: discoveryApiRef,
|
|
133
|
+
oauthRequestApi: oauthRequestApiRef,
|
|
134
|
+
configApi: configApiRef
|
|
135
|
+
},
|
|
136
|
+
factory: ({ discoveryApi, oauthRequestApi, configApi }) => {
|
|
137
|
+
return AtlassianAuth.create({
|
|
138
|
+
configApi,
|
|
139
|
+
discoveryApi,
|
|
140
|
+
oauthRequestApi,
|
|
141
|
+
environment: configApi.getOptionalString("auth.environment")
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
})
|
|
145
|
+
];
|
|
146
|
+
|
|
147
|
+
export { defaultApis };
|
|
148
|
+
//# sourceMappingURL=defaultApis.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaultApis.esm.js","sources":["../../src/testUtils/defaultApis.ts"],"sourcesContent":["/*\n * Copyright 2021 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 {\n AlertApiForwarder,\n NoOpAnalyticsApi,\n ErrorApiForwarder,\n ErrorAlerter,\n GoogleAuth,\n GithubAuth,\n OktaAuth,\n GitlabAuth,\n MicrosoftAuth,\n BitbucketAuth,\n OAuthRequestManager,\n WebStorage,\n UrlPatternDiscovery,\n OneLoginAuth,\n UnhandledErrorForwarder,\n AtlassianAuth,\n} from '@backstage/core-app-api';\n\nimport {\n createApiFactory,\n alertApiRef,\n analyticsApiRef,\n errorApiRef,\n discoveryApiRef,\n oauthRequestApiRef,\n googleAuthApiRef,\n githubAuthApiRef,\n oktaAuthApiRef,\n gitlabAuthApiRef,\n microsoftAuthApiRef,\n storageApiRef,\n configApiRef,\n oneloginAuthApiRef,\n bitbucketAuthApiRef,\n atlassianAuthApiRef,\n} from '@backstage/core-plugin-api';\n\n// TODO(Rugvip): This is just a copy of the createApp default APIs for now, but\n// we should clean up this list a bit move more things over to mocks.\nexport const defaultApis = [\n createApiFactory({\n api: discoveryApiRef,\n deps: { configApi: configApiRef },\n factory: ({ configApi }) =>\n UrlPatternDiscovery.compile(\n `${configApi.getString('backend.baseUrl')}/api/{{ pluginId }}`,\n ),\n }),\n createApiFactory(alertApiRef, new AlertApiForwarder()),\n createApiFactory(analyticsApiRef, new NoOpAnalyticsApi()),\n createApiFactory({\n api: errorApiRef,\n deps: { alertApi: alertApiRef },\n factory: ({ alertApi }) => {\n const errorApi = new ErrorAlerter(alertApi, new ErrorApiForwarder());\n UnhandledErrorForwarder.forward(errorApi, { hidden: false });\n return errorApi;\n },\n }),\n createApiFactory({\n api: storageApiRef,\n deps: { errorApi: errorApiRef },\n factory: ({ errorApi }) => WebStorage.create({ errorApi }),\n }),\n createApiFactory(oauthRequestApiRef, new OAuthRequestManager()),\n createApiFactory({\n api: googleAuthApiRef,\n deps: {\n discoveryApi: discoveryApiRef,\n oauthRequestApi: oauthRequestApiRef,\n configApi: configApiRef,\n },\n factory: ({ discoveryApi, oauthRequestApi, configApi }) =>\n GoogleAuth.create({\n configApi,\n discoveryApi,\n oauthRequestApi,\n environment: configApi.getOptionalString('auth.environment'),\n }),\n }),\n createApiFactory({\n api: microsoftAuthApiRef,\n deps: {\n discoveryApi: discoveryApiRef,\n oauthRequestApi: oauthRequestApiRef,\n configApi: configApiRef,\n },\n factory: ({ discoveryApi, oauthRequestApi, configApi }) =>\n MicrosoftAuth.create({\n configApi,\n discoveryApi,\n oauthRequestApi,\n environment: configApi.getOptionalString('auth.environment'),\n }),\n }),\n createApiFactory({\n api: githubAuthApiRef,\n deps: {\n discoveryApi: discoveryApiRef,\n oauthRequestApi: oauthRequestApiRef,\n configApi: configApiRef,\n },\n factory: ({ discoveryApi, oauthRequestApi, configApi }) =>\n GithubAuth.create({\n configApi,\n discoveryApi,\n oauthRequestApi,\n defaultScopes: ['read:user'],\n environment: configApi.getOptionalString('auth.environment'),\n }),\n }),\n createApiFactory({\n api: oktaAuthApiRef,\n deps: {\n discoveryApi: discoveryApiRef,\n oauthRequestApi: oauthRequestApiRef,\n configApi: configApiRef,\n },\n factory: ({ discoveryApi, oauthRequestApi, configApi }) =>\n OktaAuth.create({\n configApi,\n discoveryApi,\n oauthRequestApi,\n environment: configApi.getOptionalString('auth.environment'),\n }),\n }),\n createApiFactory({\n api: gitlabAuthApiRef,\n deps: {\n discoveryApi: discoveryApiRef,\n oauthRequestApi: oauthRequestApiRef,\n configApi: configApiRef,\n },\n factory: ({ discoveryApi, oauthRequestApi, configApi }) =>\n GitlabAuth.create({\n configApi,\n discoveryApi,\n oauthRequestApi,\n environment: configApi.getOptionalString('auth.environment'),\n }),\n }),\n createApiFactory({\n api: oneloginAuthApiRef,\n deps: {\n discoveryApi: discoveryApiRef,\n oauthRequestApi: oauthRequestApiRef,\n configApi: configApiRef,\n },\n factory: ({ discoveryApi, oauthRequestApi, configApi }) =>\n OneLoginAuth.create({\n configApi,\n discoveryApi,\n oauthRequestApi,\n environment: configApi.getOptionalString('auth.environment'),\n }),\n }),\n createApiFactory({\n api: bitbucketAuthApiRef,\n deps: {\n discoveryApi: discoveryApiRef,\n oauthRequestApi: oauthRequestApiRef,\n configApi: configApiRef,\n },\n factory: ({ discoveryApi, oauthRequestApi, configApi }) =>\n BitbucketAuth.create({\n configApi,\n discoveryApi,\n oauthRequestApi,\n defaultScopes: ['account'],\n environment: configApi.getOptionalString('auth.environment'),\n }),\n }),\n createApiFactory({\n api: atlassianAuthApiRef,\n deps: {\n discoveryApi: discoveryApiRef,\n oauthRequestApi: oauthRequestApiRef,\n configApi: configApiRef,\n },\n factory: ({ discoveryApi, oauthRequestApi, configApi }) => {\n return AtlassianAuth.create({\n configApi,\n discoveryApi,\n oauthRequestApi,\n environment: configApi.getOptionalString('auth.environment'),\n });\n },\n }),\n];\n"],"names":[],"mappings":";;;AAwDO,MAAM,WAAc,GAAA;AAAA,EACzB,gBAAiB,CAAA;AAAA,IACf,GAAK,EAAA,eAAA;AAAA,IACL,IAAA,EAAM,EAAE,SAAA,EAAW,YAAa,EAAA;AAAA,IAChC,OAAS,EAAA,CAAC,EAAE,SAAA,OACV,mBAAoB,CAAA,OAAA;AAAA,MAClB,CAAG,EAAA,SAAA,CAAU,SAAU,CAAA,iBAAiB,CAAC,CAAA,mBAAA,CAAA;AAAA,KAC3C;AAAA,GACH,CAAA;AAAA,EACD,gBAAiB,CAAA,WAAA,EAAa,IAAI,iBAAA,EAAmB,CAAA;AAAA,EACrD,gBAAiB,CAAA,eAAA,EAAiB,IAAI,gBAAA,EAAkB,CAAA;AAAA,EACxD,gBAAiB,CAAA;AAAA,IACf,GAAK,EAAA,WAAA;AAAA,IACL,IAAA,EAAM,EAAE,QAAA,EAAU,WAAY,EAAA;AAAA,IAC9B,OAAS,EAAA,CAAC,EAAE,QAAA,EAAe,KAAA;AACzB,MAAA,MAAM,WAAW,IAAI,YAAA,CAAa,QAAU,EAAA,IAAI,mBAAmB,CAAA,CAAA;AACnE,MAAA,uBAAA,CAAwB,OAAQ,CAAA,QAAA,EAAU,EAAE,MAAA,EAAQ,OAAO,CAAA,CAAA;AAC3D,MAAO,OAAA,QAAA,CAAA;AAA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A,QACA,eAAA;AAAA,QACA,WAAA,EAAa,SAAU,CAAA,iBAAA,CAAkB,kBAAkB,CAAA;AAAA,OAC5D,CAAA,CAAA;AAAA,KACH;AAAA,GACD,CAAA;AACH;;;;"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
const allCategories = ["log", "warn", "error"];
|
|
2
|
+
function withLogCollector(logsToCollect, callback) {
|
|
3
|
+
const oneArg = !callback;
|
|
4
|
+
const actualCallback = oneArg ? logsToCollect : callback;
|
|
5
|
+
const categories = oneArg ? allCategories : logsToCollect;
|
|
6
|
+
const logs = {
|
|
7
|
+
log: new Array(),
|
|
8
|
+
warn: new Array(),
|
|
9
|
+
error: new Array()
|
|
10
|
+
};
|
|
11
|
+
const origLog = console.log;
|
|
12
|
+
const origWarn = console.warn;
|
|
13
|
+
const origError = console.error;
|
|
14
|
+
if (categories.includes("log")) {
|
|
15
|
+
console.log = (message) => {
|
|
16
|
+
logs.log.push(message);
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
if (categories.includes("warn")) {
|
|
20
|
+
console.warn = (message) => {
|
|
21
|
+
logs.warn.push(message);
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
if (categories.includes("error")) {
|
|
25
|
+
console.error = (message) => {
|
|
26
|
+
logs.error.push(message);
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
const restore = () => {
|
|
30
|
+
console.log = origLog;
|
|
31
|
+
console.warn = origWarn;
|
|
32
|
+
console.error = origError;
|
|
33
|
+
};
|
|
34
|
+
try {
|
|
35
|
+
const ret = actualCallback();
|
|
36
|
+
if (!ret || !ret.then) {
|
|
37
|
+
restore();
|
|
38
|
+
return logs;
|
|
39
|
+
}
|
|
40
|
+
return ret.then(
|
|
41
|
+
() => {
|
|
42
|
+
restore();
|
|
43
|
+
return logs;
|
|
44
|
+
},
|
|
45
|
+
(error) => {
|
|
46
|
+
restore();
|
|
47
|
+
throw error;
|
|
48
|
+
}
|
|
49
|
+
);
|
|
50
|
+
} catch (error) {
|
|
51
|
+
restore();
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export { withLogCollector };
|
|
57
|
+
//# sourceMappingURL=logCollector.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logCollector.esm.js","sources":["../../src/testUtils/logCollector.ts"],"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\n/* eslint-disable no-console */\n\n/**\n * Severity levels of {@link CollectedLogs}\n * @public\n */\nexport type LogFuncs = 'log' | 'warn' | 'error';\n/**\n * AsyncLogCollector type used in {@link (withLogCollector:1)} callback function.\n * @public\n */\nexport type AsyncLogCollector = () => Promise<void>;\n/**\n * SyncLogCollector type used in {@link (withLogCollector:2)} callback function.\n * @public\n */\nexport type SyncLogCollector = () => void;\n/**\n * Union type used in {@link (withLogCollector:3)} callback function.\n * @public\n */\nexport type LogCollector = AsyncLogCollector | SyncLogCollector;\n/**\n * Map of severity level and corresponding log lines.\n * @public\n */\nexport type CollectedLogs<T extends LogFuncs> = { [key in T]: string[] };\n\nconst allCategories = ['log', 'warn', 'error'];\n\n/**\n * Asynchronous log collector with that collects all categories\n * @public\n */\nexport function withLogCollector(\n callback: AsyncLogCollector,\n): Promise<CollectedLogs<LogFuncs>>;\n\n/**\n * Synchronous log collector with that collects all categories\n * @public\n */\nexport function withLogCollector(\n callback: SyncLogCollector,\n): CollectedLogs<LogFuncs>;\n\n/**\n * Asynchronous log collector with that only collects selected categories\n * @public\n */\nexport function withLogCollector<T extends LogFuncs>(\n logsToCollect: T[],\n callback: AsyncLogCollector,\n): Promise<CollectedLogs<T>>;\n\n/**\n * Synchronous log collector with that only collects selected categories\n * @public\n */\nexport function withLogCollector<T extends LogFuncs>(\n logsToCollect: T[],\n callback: SyncLogCollector,\n): CollectedLogs<T>;\n\n/**\n * Log collector that collect logs either from a sync or async collector.\n * @public\n */\nexport function withLogCollector(\n logsToCollect: LogFuncs[] | LogCollector,\n callback?: LogCollector,\n): CollectedLogs<LogFuncs> | Promise<CollectedLogs<LogFuncs>> {\n const oneArg = !callback;\n const actualCallback = (oneArg ? logsToCollect : callback) as LogCollector;\n const categories = (oneArg ? allCategories : logsToCollect) as LogFuncs[];\n\n const logs = {\n log: new Array<string>(),\n warn: new Array<string>(),\n error: new Array<string>(),\n };\n\n const origLog = console.log;\n const origWarn = console.warn;\n const origError = console.error;\n\n if (categories.includes('log')) {\n console.log = (message: string) => {\n logs.log.push(message);\n };\n }\n if (categories.includes('warn')) {\n console.warn = (message: string) => {\n logs.warn.push(message);\n };\n }\n if (categories.includes('error')) {\n console.error = (message: string) => {\n logs.error.push(message);\n };\n }\n\n const restore = () => {\n console.log = origLog;\n console.warn = origWarn;\n console.error = origError;\n };\n\n try {\n const ret = actualCallback();\n\n if (!ret || !ret.then) {\n restore();\n return logs;\n }\n\n return ret.then(\n () => {\n restore();\n return logs;\n },\n error => {\n restore();\n throw error;\n },\n );\n } catch (error) {\n restore();\n throw error;\n }\n}\n"],"names":[],"mappings":"AA4CA,MAAM,aAAgB,GAAA,CAAC,KAAO,EAAA,MAAA,EAAQ,OAAO,CAAA,CAAA;AAwC7B,SAAA,gBAAA,CACd,eACA,QAC4D,EAAA;AAC5D,EAAA,MAAM,SAAS,CAAC,QAAA,CAAA;AAChB,EAAM,MAAA,cAAA,GAAkB,SAAS,aAAgB,GAAA,QAAA,CAAA;AACjD,EAAM,MAAA,UAAA,GAAc,SAAS,aAAgB,GAAA,aAAA,CAAA;AAE7C,EAAA,MAAM,IAAO,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,EAAA;AACrB,MAAQ,OAAA,EAAA,CAAA;AACR,MAAO,OAAA,IAAA,CAAA;AAAA,KACT;AAEA,IAAA,OAAO,GAAI,CAAA,IAAA;AAAA,MACT,MAAM;AACJ,QAAQ,OAAA,EAAA,CAAA;AACR,QAAO,OAAA,IAAA,CAAA;AAAA,OACT;AAAA,MACA,CAAS,KAAA,KAAA;AACP,QAAQ,OAAA,EAAA,CAAA;AACR,QAAM,MAAA,KAAA,CAAA;AAAA,OACR;AAAA,KACF,CAAA;AAAA,WACO,KAAO,EAAA;AACd,IAAQ,OAAA,EAAA,CAAA;AACR,IAAM,MAAA,KAAA,CAAA;AAAA,GACR;AACF;;;;"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { createApiFactory, errorApiRef, fetchApiRef, storageApiRef } from '@backstage/core-plugin-api';
|
|
2
|
+
import { translationApiRef } from '@backstage/core-plugin-api/alpha';
|
|
3
|
+
import '@backstage/config';
|
|
4
|
+
import { MockErrorApi } from './apis/ErrorApi/MockErrorApi.esm.js';
|
|
5
|
+
import { MockFetchApi } from './apis/FetchApi/MockFetchApi.esm.js';
|
|
6
|
+
import '@backstage/plugin-permission-common';
|
|
7
|
+
import { MockStorageApi } from './apis/StorageApi/MockStorageApi.esm.js';
|
|
8
|
+
import { MockTranslationApi } from './apis/TranslationApi/MockTranslationApi.esm.js';
|
|
9
|
+
|
|
10
|
+
const mockApis = [
|
|
11
|
+
createApiFactory(errorApiRef, new MockErrorApi()),
|
|
12
|
+
createApiFactory(fetchApiRef, new MockFetchApi()),
|
|
13
|
+
createApiFactory(storageApiRef, MockStorageApi.create()),
|
|
14
|
+
createApiFactory(translationApiRef, MockTranslationApi.create())
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
export { mockApis };
|
|
18
|
+
//# sourceMappingURL=mockApis.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mockApis.esm.js","sources":["../../src/testUtils/mockApis.ts"],"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 {\n createApiFactory,\n errorApiRef,\n fetchApiRef,\n storageApiRef,\n} from '@backstage/core-plugin-api';\nimport { translationApiRef } from '@backstage/core-plugin-api/alpha';\nimport { MockErrorApi, MockFetchApi, MockStorageApi } from './apis';\nimport { MockTranslationApi } from './apis/TranslationApi';\n\nexport const mockApis = [\n createApiFactory(errorApiRef, new MockErrorApi()),\n createApiFactory(fetchApiRef, new MockFetchApi()),\n createApiFactory(storageApiRef, MockStorageApi.create()),\n createApiFactory(translationApiRef, MockTranslationApi.create()),\n];\n"],"names":[],"mappings":";;;;;;;;;AA0BO,MAAM,QAAW,GAAA;AAAA,EACtB,gBAAiB,CAAA,WAAA,EAAa,IAAI,YAAA,EAAc,CAAA;AAAA,EAChD,gBAAiB,CAAA,WAAA,EAAa,IAAI,YAAA,EAAc,CAAA;AAAA,EAChD,gBAAiB,CAAA,aAAA,EAAe,cAAe,CAAA,MAAA,EAAQ,CAAA;AAAA,EACvD,gBAAiB,CAAA,iBAAA,EAAmB,kBAAmB,CAAA,MAAA,EAAQ,CAAA;AACjE;;;;"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
function mockBreakpoint(options) {
|
|
2
|
+
Object.defineProperty(window, "matchMedia", {
|
|
3
|
+
writable: true,
|
|
4
|
+
value: jest.fn().mockImplementation((query) => {
|
|
5
|
+
var _a;
|
|
6
|
+
return {
|
|
7
|
+
matches: (_a = options.matches) != null ? _a : false,
|
|
8
|
+
media: query,
|
|
9
|
+
onchange: null,
|
|
10
|
+
addListener: jest.fn(),
|
|
11
|
+
// deprecated
|
|
12
|
+
removeListener: jest.fn(),
|
|
13
|
+
// deprecated
|
|
14
|
+
addEventListener: jest.fn(),
|
|
15
|
+
removeEventListener: jest.fn(),
|
|
16
|
+
dispatchEvent: jest.fn()
|
|
17
|
+
};
|
|
18
|
+
})
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { mockBreakpoint as default };
|
|
23
|
+
//# sourceMappingURL=mockBreakpoint.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mockBreakpoint.esm.js","sources":["../../src/testUtils/mockBreakpoint.ts"],"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\n/**\n * This is a mocking method suggested in the Jest docs, as it is not implemented in JSDOM yet.\n * It can be used to mock values for the Material UI `useMediaQuery` hook if it is used in a tested component.\n *\n * For issues checkout the documentation:\n * https://jestjs.io/docs/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom\n *\n * If there are any updates from Material UI React on testing `useMediaQuery` this mock should be replaced\n * https://mui.com/material-ui/react-use-media-query/#testing\n *\n * @public\n * @deprecated Import from `@backstage/core-components/testUtils` instead.\n */\nexport default function mockBreakpoint(options: { matches: boolean }) {\n Object.defineProperty(window, 'matchMedia', {\n writable: true,\n value: jest.fn().mockImplementation(query => ({\n matches: options.matches ?? false,\n media: query,\n onchange: null,\n addListener: jest.fn(), // deprecated\n removeListener: jest.fn(), // deprecated\n addEventListener: jest.fn(),\n removeEventListener: jest.fn(),\n dispatchEvent: jest.fn(),\n })),\n });\n}\n"],"names":[],"mappings":"AA6BA,SAAwB,eAAe,OAA+B,EAAA;AACpE,EAAO,MAAA,CAAA,cAAA,CAAe,QAAQ,YAAc,EAAA;AAAA,IAC1C,QAAU,EAAA,IAAA;AAAA,IACV,KAAO,EAAA,IAAA,CAAK,EAAG,EAAA,CAAE,mBAAmB,CAAM,KAAA,KAAA;AAhC9C,MAAA,IAAA,EAAA,CAAA;AAgCkD,MAAA,OAAA;AAAA,QAC5C,OAAA,EAAA,CAAS,EAAQ,GAAA,OAAA,CAAA,OAAA,KAAR,IAAmB,GAAA,EAAA,GAAA,KAAA;AAAA,QAC5B,KAAO,EAAA,KAAA;AAAA,QACP,QAAU,EAAA,IAAA;AAAA,QACV,WAAA,EAAa,KAAK,EAAG,EAAA;AAAA;AAAA,QACrB,cAAA,EAAgB,KAAK,EAAG,EAAA;AAAA;AAAA,QACxB,gBAAA,EAAkB,KAAK,EAAG,EAAA;AAAA,QAC1B,mBAAA,EAAqB,KAAK,EAAG,EAAA;AAAA,QAC7B,aAAA,EAAe,KAAK,EAAG,EAAA;AAAA,OACzB,CAAA;AAAA,KAAE,CAAA;AAAA,GACH,CAAA,CAAA;AACH;;;;"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
function setupRequestMockHandlers(worker) {
|
|
2
|
+
beforeAll(() => worker.listen({ onUnhandledRequest: "error" }));
|
|
3
|
+
afterAll(() => worker.close());
|
|
4
|
+
afterEach(() => worker.resetHandlers());
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export { setupRequestMockHandlers };
|
|
8
|
+
//# sourceMappingURL=setupRequestMockHandlers.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setupRequestMockHandlers.esm.js","sources":["../../../src/testUtils/msw/setupRequestMockHandlers.ts"],"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\n/**\n * Sets up handlers for request mocking\n * @public\n * @param worker - service worker\n */\nexport function setupRequestMockHandlers(worker: {\n listen: (t: any) => void;\n close: () => void;\n resetHandlers: () => void;\n}) {\n beforeAll(() => worker.listen({ onUnhandledRequest: 'error' }));\n afterAll(() => worker.close());\n afterEach(() => worker.resetHandlers());\n}\n"],"names":[],"mappings":"AAqBO,SAAS,yBAAyB,MAItC,EAAA;AACD,EAAA,SAAA,CAAU,MAAM,MAAO,CAAA,MAAA,CAAO,EAAE,kBAAoB,EAAA,OAAA,EAAS,CAAC,CAAA,CAAA;AAC9D,EAAS,QAAA,CAAA,MAAM,MAAO,CAAA,KAAA,EAAO,CAAA,CAAA;AAC7B,EAAU,SAAA,CAAA,MAAM,MAAO,CAAA,aAAA,EAAe,CAAA,CAAA;AACxC;;;;"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { act, render } from '@testing-library/react';
|
|
2
|
+
|
|
3
|
+
async function renderWithEffects(nodes, options) {
|
|
4
|
+
let value;
|
|
5
|
+
await act(async () => {
|
|
6
|
+
value = render(nodes, options);
|
|
7
|
+
});
|
|
8
|
+
return value;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { renderWithEffects };
|
|
12
|
+
//# sourceMappingURL=testingLibrary.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testingLibrary.esm.js","sources":["../../src/testUtils/testingLibrary.ts"],"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 { ReactElement } from 'react';\nimport {\n act,\n render,\n RenderOptions,\n RenderResult,\n} from '@testing-library/react';\n\n/**\n * @public\n * Set legacy mode when using React 18/RTL 13+.\n * Mock this option while we're working against React 17 or lower.\n */\nexport type LegacyRootOption = { legacyRoot?: boolean };\n\n/**\n * @public\n * Simplifies rendering of async components in by taking care of the wrapping inside act\n *\n * @remarks\n *\n * Components using useEffect to perform an asynchronous action (such as fetch) must be rendered within an async\n * act call to properly get the final state, even with mocked responses. This utility method makes the signature a bit\n * cleaner, since act doesn't return the result of the evaluated function.\n * https://github.com/testing-library/react-testing-library/issues/281\n * https://github.com/facebook/react/pull/14853\n */\nexport async function renderWithEffects(\n nodes: ReactElement,\n options?: Pick<RenderOptions, 'wrapper'> & LegacyRootOption,\n): Promise<RenderResult> {\n let value: RenderResult;\n await act(async () => {\n value = render(nodes, options);\n });\n return value!;\n}\n"],"names":[],"mappings":";;AA2CsB,eAAA,iBAAA,CACpB,OACA,OACuB,EAAA;AACvB,EAAI,IAAA,KAAA,CAAA;AACJ,EAAA,MAAM,IAAI,YAAY;AACpB,IAAQ,KAAA,GAAA,MAAA,CAAO,OAAO,OAAO,CAAA,CAAA;AAAA,GAC9B,CAAA,CAAA;AACD,EAAO,OAAA,KAAA,CAAA;AACT;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/test-utils",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.5-next.0",
|
|
4
4
|
"description": "Utilities to test Backstage plugins and apps.",
|
|
5
5
|
"backstage": {
|
|
6
6
|
"role": "web-library"
|
|
@@ -49,11 +49,11 @@
|
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"@backstage/config": "^1.2.0",
|
|
52
|
-
"@backstage/core-app-api": "^1.12.4
|
|
53
|
-
"@backstage/core-plugin-api": "^1.9.
|
|
52
|
+
"@backstage/core-app-api": "^1.12.4",
|
|
53
|
+
"@backstage/core-plugin-api": "^1.9.2",
|
|
54
54
|
"@backstage/plugin-permission-common": "^0.7.13",
|
|
55
|
-
"@backstage/plugin-permission-react": "^0.4.
|
|
56
|
-
"@backstage/theme": "^0.5.
|
|
55
|
+
"@backstage/plugin-permission-react": "^0.4.22",
|
|
56
|
+
"@backstage/theme": "^0.5.4-next.0",
|
|
57
57
|
"@backstage/types": "^1.1.1",
|
|
58
58
|
"@material-ui/core": "^4.12.2",
|
|
59
59
|
"@material-ui/icons": "^4.9.1",
|
|
@@ -63,12 +63,12 @@
|
|
|
63
63
|
"zen-observable": "^0.10.0"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
|
-
"@backstage/cli": "^0.26.
|
|
66
|
+
"@backstage/cli": "^0.26.5-next.0",
|
|
67
67
|
"@testing-library/jest-dom": "^6.0.0",
|
|
68
68
|
"msw": "^1.0.0"
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
71
|
-
"@testing-library/react": "^
|
|
71
|
+
"@testing-library/react": "^15.0.0",
|
|
72
72
|
"react": "^16.13.1 || ^17.0.0 || ^18.0.0",
|
|
73
73
|
"react-dom": "^16.13.1 || ^17.0.0 || ^18.0.0",
|
|
74
74
|
"react-router-dom": "6.0.0-beta.0 || ^6.3.0"
|