test-utils: migrate to new core packages

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2021-06-17 20:35:26 +02:00
parent 8997d3fcca
commit 8ca26f1f75
7 changed files with 25 additions and 22 deletions
+2 -1
View File
@@ -29,7 +29,8 @@
"clean": "backstage-cli clean"
},
"dependencies": {
"@backstage/core-api": "^0.2.22",
"@backstage/core-app-api": "^0.1.2",
"@backstage/core-plugin-api": "^0.1.2",
"@backstage/test-utils-core": "^0.1.1",
"@backstage/theme": "^0.2.8",
"@material-ui/core": "^4.11.0",
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { ErrorApi, ErrorContext, Observable } from '@backstage/core-api';
import { ErrorApi, ErrorContext, Observable } from '@backstage/core-plugin-api';
type Options = {
collect?: boolean;
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { MockStorageApi } from './MockStorageApi';
import { StorageApi } from '@backstage/core-api';
import { StorageApi } from '@backstage/core-plugin-api';
describe('WebStorage Storage API', () => {
const createMockStorage = (): StorageApi => {
@@ -18,7 +18,7 @@ import {
Observable,
StorageApi,
StorageValueChange,
} from '@backstage/core-api';
} from '@backstage/core-plugin-api';
import ObservableImpl from 'zen-observable';
export type MockStorageBucket = { [key: string]: any };
@@ -14,16 +14,15 @@
* limitations under the License.
*/
import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
import {
ApiProvider,
ApiRegistry,
createExternalRouteRef,
createRouteRef,
createSubRouteRef,
errorApiRef,
useApi,
useRouteRef,
} from '@backstage/core-api';
} from '@backstage/core-plugin-api';
import { withLogCollector } from '@backstage/test-utils-core';
import { render } from '@testing-library/react';
import React, { useEffect } from 'react';
@@ -53,6 +52,9 @@ describe('wrapInTestApp', () => {
expect.stringMatching(
/^Warning: An update to %s inside a test was not wrapped in act\(...\)/,
),
expect.stringMatching(
/^Warning: An update to %s inside a test was not wrapped in act\(...\)/,
),
]);
});
@@ -18,20 +18,21 @@ import React, { ComponentType, ReactNode, ReactElement } from 'react';
import { MemoryRouter } from 'react-router';
import { Route } from 'react-router-dom';
import { lightTheme } from '@backstage/theme';
import privateExports, {
defaultSystemIcons,
import { createApp } from '@backstage/core-app-api';
import {
BootErrorPageProps,
RouteRef,
ExternalRouteRef,
attachComponentData,
createRouteRef,
} from '@backstage/core-api';
} from '@backstage/core-plugin-api';
import { RenderResult } from '@testing-library/react';
import { renderWithEffects } from '@backstage/test-utils-core';
import { mockApis } from './mockApis';
const { PrivateAppImpl } = privateExports;
const ErrorBoundaryFallback = ({ error }: { error: Error }) => {
throw new Error(`Reached ErrorBoundaryFallback Page with error, ${error}`);
};
const NotFoundErrorPage = () => {
throw new Error('Reached NotFound Page');
};
@@ -87,17 +88,20 @@ export function wrapInTestApp(
const { routeEntries = ['/'] } = options;
const boundRoutes = new Map<ExternalRouteRef, RouteRef>();
const app = new PrivateAppImpl({
apis: [],
const app = createApp({
apis: mockApis,
// Bit of a hack to make sure that the default config loader isn't used
// as that would force every single test to wait for config loading.
configLoader: (false as unknown) as undefined,
components: {
NotFoundErrorPage,
BootErrorPage,
Progress,
BootErrorPage,
NotFoundErrorPage,
ErrorBoundaryFallback,
Router: ({ children }) => (
<MemoryRouter initialEntries={routeEntries} children={children} />
),
},
icons: defaultSystemIcons,
plugins: [],
themes: [
{
@@ -107,7 +111,6 @@ export function wrapInTestApp(
variant: 'light',
},
],
defaultApis: mockApis,
bindRoutes: ({ bind }) => {
for (const [externalRef, absoluteRef] of boundRoutes) {
bind(
@@ -18,13 +18,10 @@ import {
storageApiRef,
errorApiRef,
createApiFactory,
AlertApiForwarder,
alertApiRef,
} from '@backstage/core-api';
} from '@backstage/core-plugin-api';
import { MockErrorApi, MockStorageApi } from './apis';
export const mockApis = [
createApiFactory(errorApiRef, new MockErrorApi()),
createApiFactory(storageApiRef, MockStorageApi.create()),
createApiFactory(alertApiRef, new AlertApiForwarder()),
];