frontend-test-utils: refactor to use createSpecializedApp + API report

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2023-11-15 13:11:42 +01:00
parent b8cb7804c8
commit d69b0fcd2b
5 changed files with 50 additions and 13 deletions
@@ -0,0 +1,32 @@
## API Report File for "@backstage/frontend-test-utils"
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
```ts
import { Extension } from '@backstage/frontend-plugin-api';
import { JsonObject } from '@backstage/types';
import { RenderResult } from '@testing-library/react';
// @public (undocumented)
export function createExtensionTester<TConfig>(
subject: Extension<TConfig>,
options?: {
config?: TConfig;
},
): ExtensionTester;
// @public (undocumented)
export class ExtensionTester {
// (undocumented)
add<TConfig>(
extension: Extension<TConfig>,
options?: {
config?: TConfig;
},
): ExtensionTester;
// (undocumented)
render(options?: { config?: JsonObject }): Promise<RenderResult>;
}
// (No @packageDocumentation comment for this package)
```
@@ -35,5 +35,8 @@
"@backstage/test-utils": "workspace:^",
"@backstage/types": "workspace:^",
"@testing-library/react": "^14.0.0"
},
"peerDependencies": {
"react": "^16.13.1 || ^17.0.0 || ^18.0.0"
}
}
@@ -14,13 +14,14 @@
* limitations under the License.
*/
import { createApp } from '@backstage/frontend-app-api';
import { createSpecializedApp } from '@backstage/frontend-app-api';
import { Extension, createPlugin } from '@backstage/frontend-plugin-api';
import { MockConfigApi } from '@backstage/test-utils';
import { JsonArray, JsonObject, JsonValue } from '@backstage/types';
import { RenderResult, render, waitFor } from '@testing-library/react';
import { RenderResult, render } from '@testing-library/react';
class ExtensionTester {
/** @public */
export class ExtensionTester {
/** @internal */
static forSubject<TConfig>(
subject: Extension<TConfig>,
@@ -90,25 +91,21 @@ class ExtensionTester {
},
};
const app = createApp({
const app = createSpecializedApp({
features: [
createPlugin({
id: 'test',
extensions: this.#extensions.map(entry => entry.extension),
}),
],
configLoader: async () => new MockConfigApi(finalConfig),
config: new MockConfigApi(finalConfig),
});
const result = render(app.createRoot());
await waitFor(() =>
// eslint-disable-next-line jest/no-standalone-expect
expect(result.queryByText('Loading...')).not.toBeInTheDocument(),
);
return result;
return render(app.createRoot());
}
}
/** @public */
export function createExtensionTester<TConfig>(
subject: Extension<TConfig>,
options?: { config?: TConfig },
@@ -14,4 +14,7 @@
* limitations under the License.
*/
export { createExtensionTester } from './createExtensionTester';
export {
createExtensionTester,
type ExtensionTester,
} from './createExtensionTester';
+3 -1
View File
@@ -4345,7 +4345,7 @@ __metadata:
languageName: unknown
linkType: soft
"@backstage/frontend-test-utils@workspace:packages/frontend-test-utils":
"@backstage/frontend-test-utils@workspace:^, @backstage/frontend-test-utils@workspace:packages/frontend-test-utils":
version: 0.0.0-use.local
resolution: "@backstage/frontend-test-utils@workspace:packages/frontend-test-utils"
dependencies:
@@ -4356,6 +4356,8 @@ __metadata:
"@backstage/types": "workspace:^"
"@testing-library/jest-dom": ^6.0.0
"@testing-library/react": ^14.0.0
peerDependencies:
react: ^16.13.1 || ^17.0.0 || ^18.0.0
languageName: unknown
linkType: soft