@backstage/frontend-test-utils 0.3.7-next.1 → 0.4.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 +15 -0
- package/dist/app/renderInTestApp.esm.js +9 -9
- package/dist/app/renderInTestApp.esm.js.map +1 -1
- package/dist/app/renderTestApp.esm.js +54 -0
- package/dist/app/renderTestApp.esm.js.map +1 -0
- package/dist/index.d.ts +32 -3
- package/dist/index.esm.js +1 -0
- package/dist/index.esm.js.map +1 -1
- package/package.json +9 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @backstage/frontend-test-utils
|
|
2
2
|
|
|
3
|
+
## 0.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- c41dd80: **BREAKING**: Removed the `extensions` option from `renderInTestApp`. If you need to pass extensions to the test app, use the new `renderTestApp` utility instead.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies
|
|
12
|
+
- @backstage/plugin-app@0.3.1
|
|
13
|
+
- @backstage/frontend-plugin-api@0.12.1
|
|
14
|
+
- @backstage/config@1.3.5
|
|
15
|
+
- @backstage/frontend-app-api@0.13.1
|
|
16
|
+
- @backstage/test-utils@1.7.12
|
|
17
|
+
|
|
3
18
|
## 0.3.7-next.1
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
|
@@ -28,6 +28,12 @@ const appPluginOverride = appPlugin.withOverrides({
|
|
|
28
28
|
appPlugin.getExtension("sign-in-page:app").override({
|
|
29
29
|
disabled: true
|
|
30
30
|
}),
|
|
31
|
+
appPlugin.getExtension("app/layout").override({
|
|
32
|
+
disabled: true
|
|
33
|
+
}),
|
|
34
|
+
appPlugin.getExtension("app/routes").override({
|
|
35
|
+
disabled: true
|
|
36
|
+
}),
|
|
31
37
|
appPlugin.getExtension("app/nav").override({
|
|
32
38
|
output: [coreExtensionData.reactElement],
|
|
33
39
|
factory(_originalFactory, { inputs }) {
|
|
@@ -56,13 +62,10 @@ const appPluginOverride = appPlugin.withOverrides({
|
|
|
56
62
|
function renderInTestApp(element, options) {
|
|
57
63
|
const extensions = [
|
|
58
64
|
createExtension({
|
|
59
|
-
attachTo: { id: "app/
|
|
60
|
-
output: [coreExtensionData.reactElement
|
|
65
|
+
attachTo: { id: "app/root", input: "children" },
|
|
66
|
+
output: [coreExtensionData.reactElement],
|
|
61
67
|
factory: () => {
|
|
62
|
-
return [
|
|
63
|
-
coreExtensionData.reactElement(element),
|
|
64
|
-
coreExtensionData.routePath("/")
|
|
65
|
-
];
|
|
68
|
+
return [coreExtensionData.reactElement(element)];
|
|
66
69
|
}
|
|
67
70
|
}),
|
|
68
71
|
RouterBlueprint.make({
|
|
@@ -92,9 +95,6 @@ function renderInTestApp(element, options) {
|
|
|
92
95
|
);
|
|
93
96
|
}
|
|
94
97
|
}
|
|
95
|
-
if (options?.extensions) {
|
|
96
|
-
extensions.push(...options.extensions);
|
|
97
|
-
}
|
|
98
98
|
const features = [
|
|
99
99
|
createFrontendPlugin({
|
|
100
100
|
pluginId: "test",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderInTestApp.esm.js","sources":["../../src/app/renderInTestApp.tsx"],"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 { Fragment } from 'react';\nimport { Link, MemoryRouter } from 'react-router-dom';\nimport { createSpecializedApp } from '@backstage/frontend-app-api';\nimport { RenderResult, render } from '@testing-library/react';\nimport { ConfigReader } from '@backstage/config';\nimport { JsonObject } from '@backstage/types';\nimport {\n createExtension,\n ExtensionDefinition,\n coreExtensionData,\n RouteRef,\n useRouteRef,\n IconComponent,\n RouterBlueprint,\n NavItemBlueprint,\n createFrontendPlugin,\n FrontendFeature,\n} from '@backstage/frontend-plugin-api';\nimport appPlugin from '@backstage/plugin-app';\n\nconst DEFAULT_MOCK_CONFIG = {\n app: { baseUrl: 'http://localhost:3000' },\n backend: { baseUrl: 'http://localhost:7007' },\n};\n\n/**\n * Options to customize the behavior of the test app.\n * @public\n */\nexport type TestAppOptions = {\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 * ```ts\n * renderInTestApp(<MyComponent />, {\n * mountedRoutes: {\n * '/my-path': myRouteRef,\n * }\n * })\n * // ...\n * const link = useRouteRef(myRouteRef)\n * ```\n */\n mountedRoutes?: { [path: string]: RouteRef };\n\n /**\n * Additional configuration passed to the app when rendering elements inside it.\n */\n config?: JsonObject;\n\n /**\n * Additional
|
|
1
|
+
{"version":3,"file":"renderInTestApp.esm.js","sources":["../../src/app/renderInTestApp.tsx"],"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 { Fragment } from 'react';\nimport { Link, MemoryRouter } from 'react-router-dom';\nimport { createSpecializedApp } from '@backstage/frontend-app-api';\nimport { RenderResult, render } from '@testing-library/react';\nimport { ConfigReader } from '@backstage/config';\nimport { JsonObject } from '@backstage/types';\nimport {\n createExtension,\n ExtensionDefinition,\n coreExtensionData,\n RouteRef,\n useRouteRef,\n IconComponent,\n RouterBlueprint,\n NavItemBlueprint,\n createFrontendPlugin,\n FrontendFeature,\n} from '@backstage/frontend-plugin-api';\nimport appPlugin from '@backstage/plugin-app';\n\nconst DEFAULT_MOCK_CONFIG = {\n app: { baseUrl: 'http://localhost:3000' },\n backend: { baseUrl: 'http://localhost:7007' },\n};\n\n/**\n * Options to customize the behavior of the test app.\n * @public\n */\nexport type TestAppOptions = {\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 * ```ts\n * renderInTestApp(<MyComponent />, {\n * mountedRoutes: {\n * '/my-path': myRouteRef,\n * }\n * })\n * // ...\n * const link = useRouteRef(myRouteRef)\n * ```\n */\n mountedRoutes?: { [path: string]: RouteRef };\n\n /**\n * Additional configuration passed to the app when rendering elements inside it.\n */\n config?: JsonObject;\n\n /**\n * Additional features to add to the test app.\n */\n features?: FrontendFeature[];\n\n /**\n * Initial route entries to use for the router.\n */\n initialRouteEntries?: string[];\n};\n\nconst NavItem = (props: {\n routeRef: RouteRef<undefined>;\n title: string;\n icon: IconComponent;\n}) => {\n const { routeRef, title, icon: Icon } = props;\n const link = useRouteRef(routeRef);\n if (!link) {\n return null;\n }\n return (\n <li>\n <Link to={link()}>\n <Icon /> {title}\n </Link>\n </li>\n );\n};\n\nconst appPluginOverride = appPlugin.withOverrides({\n extensions: [\n appPlugin.getExtension('sign-in-page:app').override({\n disabled: true,\n }),\n appPlugin.getExtension('app/layout').override({\n disabled: true,\n }),\n appPlugin.getExtension('app/routes').override({\n disabled: true,\n }),\n appPlugin.getExtension('app/nav').override({\n output: [coreExtensionData.reactElement],\n factory(_originalFactory, { inputs }) {\n return [\n coreExtensionData.reactElement(\n <nav>\n <ul>\n {inputs.items.map((item, index) => {\n const { icon, title, routeRef } = item.get(\n NavItemBlueprint.dataRefs.target,\n );\n\n return (\n <NavItem\n key={index}\n icon={icon}\n title={title}\n routeRef={routeRef}\n />\n );\n })}\n </ul>\n </nav>,\n ),\n ];\n },\n }),\n ],\n});\n\n/**\n * @public\n * Renders the given element in a test app, for use in unit tests.\n */\nexport function renderInTestApp(\n element: JSX.Element,\n options?: TestAppOptions,\n): RenderResult {\n const extensions: Array<ExtensionDefinition> = [\n createExtension({\n attachTo: { id: 'app/root', input: 'children' },\n output: [coreExtensionData.reactElement],\n factory: () => {\n return [coreExtensionData.reactElement(element)];\n },\n }),\n RouterBlueprint.make({\n params: {\n component: ({ children }) => (\n <MemoryRouter initialEntries={options?.initialRouteEntries}>\n {children}\n </MemoryRouter>\n ),\n },\n }),\n ];\n\n if (options?.mountedRoutes) {\n for (const [path, routeRef] of Object.entries(options.mountedRoutes)) {\n // TODO(Rugvip): add support for external route refs\n extensions.push(\n createExtension({\n kind: 'test-route',\n name: path,\n attachTo: { id: 'app/root', input: 'elements' },\n output: [\n coreExtensionData.reactElement,\n coreExtensionData.routePath,\n coreExtensionData.routeRef,\n ],\n factory: () => [\n coreExtensionData.reactElement(<Fragment />),\n coreExtensionData.routePath(path),\n coreExtensionData.routeRef(routeRef),\n ],\n }),\n );\n }\n }\n\n const features: FrontendFeature[] = [\n createFrontendPlugin({\n pluginId: 'test',\n extensions,\n }),\n appPluginOverride,\n ];\n\n if (options?.features) {\n features.push(...options.features);\n }\n\n const app = createSpecializedApp({\n features,\n config: ConfigReader.fromConfigs([\n {\n context: 'render-config',\n data: options?.config ?? DEFAULT_MOCK_CONFIG,\n },\n ]),\n });\n\n return render(\n app.tree.root.instance!.getData(coreExtensionData.reactElement),\n );\n}\n"],"names":[],"mappings":";;;;;;;;;AAoCA,MAAM,mBAAA,GAAsB;AAAA,EAC1B,GAAA,EAAK,EAAE,OAAA,EAAS,uBAAA,EAAwB;AAAA,EACxC,OAAA,EAAS,EAAE,OAAA,EAAS,uBAAA;AACtB,CAAA;AAyCA,MAAM,OAAA,GAAU,CAAC,KAAA,KAIX;AACJ,E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AA,YACN,iBAAA,CAAkB,YAAA;AAAA,YAClB,iBAAA,CAAkB,SAAA;AAAA,YAClB,iBAAA,CAAkB;AAAA,WACpB;AAAA,UACA,SAAS,MAAM;AAAA,YACb,iBAAA,CAAkB,YAAA,iBAAa,GAAA,CAAC,QAAA,EAAA,EAAS,CAAE,CAAA;AAAA,YAC3C,iBAAA,CAAkB,UAAU,IAAI,CAAA;AAAA,YAChC,iBAAA,CAAkB,SAAS,QAAQ;AAAA;AACrC,SACD;AAAA,OACH;AAAA,IACF;AAAA,EACF;AAEA,EAAA,MAAM,QAAA,GAA8B;AAAA,IAClC,oBAAA,CAAqB;AAAA,MACnB,QAAA,EAAU,MAAA;AAAA,MACV;AAAA,KACD,CAAA;AAAA,IACD;AAAA,GACF;AAEA,EAAA,IAAI,SAAS,QAAA,EAAU;AACrB,IAAA,QAAA,CAAS,IAAA,CAAK,GAAG,OAAA,CAAQ,QAAQ,CAAA;AAAA,EACnC;AAEA,EAAA,MAAM,MAAM,oBAAA,CAAqB;AAAA,IAC/B,QAAA;AAAA,IACA,MAAA,EAAQ,aAAa,WAAA,CAAY;AAAA,MAC/B;AAAA,QACE,OAAA,EAAS,eAAA;AAAA,QACT,IAAA,EAAM,SAAS,MAAA,IAAU;AAAA;AAC3B,KACD;AAAA,GACF,CAAA;AAED,EAAA,OAAO,MAAA;AAAA,IACL,IAAI,IAAA,CAAK,IAAA,CAAK,QAAA,CAAU,OAAA,CAAQ,kBAAkB,YAAY;AAAA,GAChE;AACF;;;;"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { createSpecializedApp } from '@backstage/frontend-app-api';
|
|
3
|
+
import { RouterBlueprint, createFrontendPlugin, coreExtensionData } from '@backstage/frontend-plugin-api';
|
|
4
|
+
import { render } from '@testing-library/react';
|
|
5
|
+
import appPlugin from '@backstage/plugin-app';
|
|
6
|
+
import { ConfigReader } from '@backstage/config';
|
|
7
|
+
import { MemoryRouter } from 'react-router-dom';
|
|
8
|
+
|
|
9
|
+
const DEFAULT_MOCK_CONFIG = {
|
|
10
|
+
app: { baseUrl: "http://localhost:3000" },
|
|
11
|
+
backend: { baseUrl: "http://localhost:7007" }
|
|
12
|
+
};
|
|
13
|
+
const appPluginOverride = appPlugin.withOverrides({
|
|
14
|
+
extensions: [
|
|
15
|
+
appPlugin.getExtension("sign-in-page:app").override({
|
|
16
|
+
disabled: true
|
|
17
|
+
})
|
|
18
|
+
]
|
|
19
|
+
});
|
|
20
|
+
function renderTestApp(options) {
|
|
21
|
+
const extensions = [
|
|
22
|
+
RouterBlueprint.make({
|
|
23
|
+
params: {
|
|
24
|
+
component: ({ children }) => /* @__PURE__ */ jsx(MemoryRouter, { initialEntries: options.initialRouteEntries, children })
|
|
25
|
+
}
|
|
26
|
+
}),
|
|
27
|
+
...options.extensions ?? []
|
|
28
|
+
];
|
|
29
|
+
const features = [
|
|
30
|
+
createFrontendPlugin({
|
|
31
|
+
pluginId: "test",
|
|
32
|
+
extensions
|
|
33
|
+
}),
|
|
34
|
+
appPluginOverride
|
|
35
|
+
];
|
|
36
|
+
if (options.features) {
|
|
37
|
+
features.push(...options.features);
|
|
38
|
+
}
|
|
39
|
+
const app = createSpecializedApp({
|
|
40
|
+
features,
|
|
41
|
+
config: ConfigReader.fromConfigs([
|
|
42
|
+
{
|
|
43
|
+
context: "render-config",
|
|
44
|
+
data: options?.config ?? DEFAULT_MOCK_CONFIG
|
|
45
|
+
}
|
|
46
|
+
])
|
|
47
|
+
});
|
|
48
|
+
return render(
|
|
49
|
+
app.tree.root.instance.getData(coreExtensionData.reactElement)
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export { renderTestApp };
|
|
54
|
+
//# sourceMappingURL=renderTestApp.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderTestApp.esm.js","sources":["../../src/app/renderTestApp.tsx"],"sourcesContent":["/*\n * Copyright 2025 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 { createSpecializedApp } from '@backstage/frontend-app-api';\nimport {\n coreExtensionData,\n createFrontendPlugin,\n ExtensionDefinition,\n FrontendFeature,\n RouterBlueprint,\n} from '@backstage/frontend-plugin-api';\nimport { render } from '@testing-library/react';\nimport appPlugin from '@backstage/plugin-app';\nimport { JsonObject } from '@backstage/types';\nimport { ConfigReader } from '@backstage/config';\nimport { MemoryRouter } from 'react-router-dom';\n\nconst DEFAULT_MOCK_CONFIG = {\n app: { baseUrl: 'http://localhost:3000' },\n backend: { baseUrl: 'http://localhost:7007' },\n};\n\n/**\n * Options for `renderTestApp`.\n *\n * @public\n */\nexport type RenderTestAppOptions = {\n /**\n * Additional configuration passed to the app when rendering elements inside it.\n */\n config?: JsonObject;\n /**\n * Additional extensions to add to the test app.\n */\n extensions?: ExtensionDefinition<any>[];\n\n /**\n * Additional features to add to the test app.\n */\n features?: FrontendFeature[];\n\n /**\n * Initial route entries to use for the router.\n */\n initialRouteEntries?: string[];\n};\n\nconst appPluginOverride = appPlugin.withOverrides({\n extensions: [\n appPlugin.getExtension('sign-in-page:app').override({\n disabled: true,\n }),\n ],\n});\n\n/**\n * Renders the provided extensions inside a Backstage app, returning the same\n * utilities as `@testing-library/react` `render` function.\n *\n * @public\n */\nexport function renderTestApp(options: RenderTestAppOptions) {\n const extensions = [\n RouterBlueprint.make({\n params: {\n component: ({ children }) => (\n <MemoryRouter initialEntries={options.initialRouteEntries}>\n {children}\n </MemoryRouter>\n ),\n },\n }),\n ...(options.extensions ?? []),\n ];\n\n const features: FrontendFeature[] = [\n createFrontendPlugin({\n pluginId: 'test',\n extensions,\n }),\n appPluginOverride,\n ];\n\n if (options.features) {\n features.push(...options.features);\n }\n\n const app = createSpecializedApp({\n features,\n config: ConfigReader.fromConfigs([\n {\n context: 'render-config',\n data: options?.config ?? DEFAULT_MOCK_CONFIG,\n },\n ]),\n });\n\n return render(\n app.tree.root.instance!.getData(coreExtensionData.reactElement),\n );\n}\n"],"names":[],"mappings":";;;;;;;;AA8BA,MAAM,mBAAA,GAAsB;AAAA,EAC1B,GAAA,EAAK,EAAE,OAAA,EAAS,uBAAA,EAAwB;AAAA,EACxC,OAAA,EAAS,EAAE,OAAA,EAAS,uBAAA;AACtB,CAAA;AA4BA,MAAM,iBAAA,GAAoB,UAAU,aAAA,CAAc;AAAA,EAChD,UAAA,EAAY;AAAA,IACV,SAAA,CAAU,YAAA,CAAa,kBAAkB,CAAA,CAAE,QAAA,CAAS;AAAA,MAClD,QAAA,EAAU;AAAA,KACX;AAAA;AAEL,CAAC,CAAA;AAQM,SAAS,cAAc,OAAA,EAA+B;AAC3D,EAAA,MAAM,UAAA,GAAa;AAAA,IACjB,gBAAgB,IAAA,CAAK;AAAA,MACnB,MAAA,EAAQ;AAAA,QACN,SAAA,EAAW,CAAC,EAAE,QAAA,EAAS,yBACpB,YAAA,EAAA,EAAa,cAAA,EAAgB,OAAA,CAAQ,mBAAA,EACnC,QAAA,EACH;AAAA;AAEJ,KACD,CAAA;AAAA,IACD,GAAI,OAAA,CAAQ,UAAA,IAAc;AAAC,GAC7B;AAEA,EAAA,MAAM,QAAA,GAA8B;AAAA,IAClC,oBAAA,CAAqB;AAAA,MACnB,QAAA,EAAU,MAAA;AAAA,MACV;AAAA,KACD,CAAA;AAAA,IACD;AAAA,GACF;AAEA,EAAA,IAAI,QAAQ,QAAA,EAAU;AACpB,IAAA,QAAA,CAAS,IAAA,CAAK,GAAG,OAAA,CAAQ,QAAQ,CAAA;AAAA,EACnC;AAEA,EAAA,MAAM,MAAM,oBAAA,CAAqB;AAAA,IAC/B,QAAA;AAAA,IACA,MAAA,EAAQ,aAAa,WAAA,CAAY;AAAA,MAC/B;AAAA,QACE,OAAA,EAAS,eAAA;AAAA,QACT,IAAA,EAAM,SAAS,MAAA,IAAU;AAAA;AAC3B,KACD;AAAA,GACF,CAAA;AAED,EAAA,OAAO,MAAA;AAAA,IACL,IAAI,IAAA,CAAK,IAAA,CAAK,QAAA,CAAU,OAAA,CAAQ,kBAAkB,YAAY;AAAA,GAChE;AACF;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
export { ApiMock, ErrorWithContext, MockConfigApi, MockErrorApi, MockErrorApiOptions, MockFetchApi, MockFetchApiOptions, MockPermissionApi, MockStorageApi, MockStorageBucket, TestApiProvider, TestApiProviderProps, TestApiRegistry, mockApis, registerMswTestHooks, withLogCollector } from '@backstage/test-utils';
|
|
2
2
|
import * as _backstage_frontend_plugin_api from '@backstage/frontend-plugin-api';
|
|
3
3
|
import { AnalyticsApi, AnalyticsEvent, ExtensionDefinitionParameters, ExtensionDefinition, ExtensionDataRef, AppNode, RouteRef, FrontendFeature } from '@backstage/frontend-plugin-api';
|
|
4
|
+
import * as _testing_library_react from '@testing-library/react';
|
|
4
5
|
import { RenderResult } from '@testing-library/react';
|
|
5
6
|
import { JsonObject } from '@backstage/types';
|
|
7
|
+
import * as _testing_library_dom_types_queries from '@testing-library/dom/types/queries';
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* Mock implementation of {@link frontend-plugin-api#AnalyticsApi} with helpers to ensure that events are sent correctly.
|
|
@@ -63,6 +65,31 @@ type TestAppOptions = {
|
|
|
63
65
|
mountedRoutes?: {
|
|
64
66
|
[path: string]: RouteRef;
|
|
65
67
|
};
|
|
68
|
+
/**
|
|
69
|
+
* Additional configuration passed to the app when rendering elements inside it.
|
|
70
|
+
*/
|
|
71
|
+
config?: JsonObject;
|
|
72
|
+
/**
|
|
73
|
+
* Additional features to add to the test app.
|
|
74
|
+
*/
|
|
75
|
+
features?: FrontendFeature[];
|
|
76
|
+
/**
|
|
77
|
+
* Initial route entries to use for the router.
|
|
78
|
+
*/
|
|
79
|
+
initialRouteEntries?: string[];
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* @public
|
|
83
|
+
* Renders the given element in a test app, for use in unit tests.
|
|
84
|
+
*/
|
|
85
|
+
declare function renderInTestApp(element: JSX.Element, options?: TestAppOptions): RenderResult;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Options for `renderTestApp`.
|
|
89
|
+
*
|
|
90
|
+
* @public
|
|
91
|
+
*/
|
|
92
|
+
type RenderTestAppOptions = {
|
|
66
93
|
/**
|
|
67
94
|
* Additional configuration passed to the app when rendering elements inside it.
|
|
68
95
|
*/
|
|
@@ -81,9 +108,11 @@ type TestAppOptions = {
|
|
|
81
108
|
initialRouteEntries?: string[];
|
|
82
109
|
};
|
|
83
110
|
/**
|
|
111
|
+
* Renders the provided extensions inside a Backstage app, returning the same
|
|
112
|
+
* utilities as `@testing-library/react` `render` function.
|
|
113
|
+
*
|
|
84
114
|
* @public
|
|
85
|
-
* Renders the given element in a test app, for use in unit tests.
|
|
86
115
|
*/
|
|
87
|
-
declare function
|
|
116
|
+
declare function renderTestApp(options: RenderTestAppOptions): _testing_library_react.RenderResult<typeof _testing_library_dom_types_queries, HTMLElement, HTMLElement>;
|
|
88
117
|
|
|
89
|
-
export { ExtensionQuery, ExtensionTester, MockAnalyticsApi, type TestAppOptions, createExtensionTester, renderInTestApp };
|
|
118
|
+
export { ExtensionQuery, ExtensionTester, MockAnalyticsApi, type RenderTestAppOptions, type TestAppOptions, createExtensionTester, renderInTestApp, renderTestApp };
|
package/dist/index.esm.js
CHANGED
|
@@ -2,4 +2,5 @@ export { MockConfigApi, MockErrorApi, MockFetchApi, MockPermissionApi, MockStora
|
|
|
2
2
|
export { MockAnalyticsApi } from './apis/AnalyticsApi/MockAnalyticsApi.esm.js';
|
|
3
3
|
export { createExtensionTester } from './app/createExtensionTester.esm.js';
|
|
4
4
|
export { renderInTestApp } from './app/renderInTestApp.esm.js';
|
|
5
|
+
export { renderTestApp } from './app/renderTestApp.esm.js';
|
|
5
6
|
//# sourceMappingURL=index.esm.js.map
|
package/dist/index.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/frontend-test-utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"backstage": {
|
|
5
5
|
"role": "web-library"
|
|
6
6
|
},
|
|
@@ -31,17 +31,17 @@
|
|
|
31
31
|
"test": "backstage-cli package test"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@backstage/config": "1.3.
|
|
35
|
-
"@backstage/frontend-app-api": "0.13.1
|
|
36
|
-
"@backstage/frontend-plugin-api": "0.12.1
|
|
37
|
-
"@backstage/plugin-app": "0.3.1
|
|
38
|
-
"@backstage/test-utils": "1.7.12
|
|
39
|
-
"@backstage/types": "1.2.2",
|
|
40
|
-
"@backstage/version-bridge": "1.0.11",
|
|
34
|
+
"@backstage/config": "^1.3.5",
|
|
35
|
+
"@backstage/frontend-app-api": "^0.13.1",
|
|
36
|
+
"@backstage/frontend-plugin-api": "^0.12.1",
|
|
37
|
+
"@backstage/plugin-app": "^0.3.1",
|
|
38
|
+
"@backstage/test-utils": "^1.7.12",
|
|
39
|
+
"@backstage/types": "^1.2.2",
|
|
40
|
+
"@backstage/version-bridge": "^1.0.11",
|
|
41
41
|
"zod": "^3.22.4"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@backstage/cli": "0.34.4
|
|
44
|
+
"@backstage/cli": "^0.34.4",
|
|
45
45
|
"@testing-library/jest-dom": "^6.0.0",
|
|
46
46
|
"@types/react": "^18.0.0",
|
|
47
47
|
"react": "^18.0.2",
|