diff --git a/packages/test-utils/package.json b/packages/test-utils/package.json index cb6e13d7df..6791d9c132 100644 --- a/packages/test-utils/package.json +++ b/packages/test-utils/package.json @@ -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", diff --git a/packages/test-utils/src/testUtils/apis/ErrorApi/MockErrorApi.ts b/packages/test-utils/src/testUtils/apis/ErrorApi/MockErrorApi.ts index b90646201a..b4bcb673ee 100644 --- a/packages/test-utils/src/testUtils/apis/ErrorApi/MockErrorApi.ts +++ b/packages/test-utils/src/testUtils/apis/ErrorApi/MockErrorApi.ts @@ -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; diff --git a/packages/test-utils/src/testUtils/apis/StorageApi/MockStorageApi.test.ts b/packages/test-utils/src/testUtils/apis/StorageApi/MockStorageApi.test.ts index 7c92c71460..7b5f2e1ae6 100644 --- a/packages/test-utils/src/testUtils/apis/StorageApi/MockStorageApi.test.ts +++ b/packages/test-utils/src/testUtils/apis/StorageApi/MockStorageApi.test.ts @@ -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 => { diff --git a/packages/test-utils/src/testUtils/apis/StorageApi/MockStorageApi.ts b/packages/test-utils/src/testUtils/apis/StorageApi/MockStorageApi.ts index 5cb4bdfff6..e3a564bd86 100644 --- a/packages/test-utils/src/testUtils/apis/StorageApi/MockStorageApi.ts +++ b/packages/test-utils/src/testUtils/apis/StorageApi/MockStorageApi.ts @@ -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 }; diff --git a/packages/test-utils/src/testUtils/appWrappers.test.tsx b/packages/test-utils/src/testUtils/appWrappers.test.tsx index 1283128df2..56dfb5f174 100644 --- a/packages/test-utils/src/testUtils/appWrappers.test.tsx +++ b/packages/test-utils/src/testUtils/appWrappers.test.tsx @@ -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\(...\)/, + ), ]); }); diff --git a/packages/test-utils/src/testUtils/appWrappers.tsx b/packages/test-utils/src/testUtils/appWrappers.tsx index add7b4479c..8d11f7db39 100644 --- a/packages/test-utils/src/testUtils/appWrappers.tsx +++ b/packages/test-utils/src/testUtils/appWrappers.tsx @@ -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(); - 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 }) => ( ), }, - icons: defaultSystemIcons, plugins: [], themes: [ { @@ -107,7 +111,6 @@ export function wrapInTestApp( variant: 'light', }, ], - defaultApis: mockApis, bindRoutes: ({ bind }) => { for (const [externalRef, absoluteRef] of boundRoutes) { bind( diff --git a/packages/test-utils/src/testUtils/mockApis.ts b/packages/test-utils/src/testUtils/mockApis.ts index 0fe9a30926..71a1f35285 100644 --- a/packages/test-utils/src/testUtils/mockApis.ts +++ b/packages/test-utils/src/testUtils/mockApis.ts @@ -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()), ];