Create mocked APIs each time build is called
Signed-off-by: Dylan O'Gara <dogara@webstaurantstore.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-techdocs-addons-test-utils': patch
|
||||
---
|
||||
|
||||
Fix bug in TechDocsAddonTester when jest.resetAllMocks is called between tests
|
||||
@@ -49,46 +49,6 @@ if (!global.TextEncoder) {
|
||||
const { renderToStaticMarkup } =
|
||||
require('react-dom/server') as typeof import('react-dom/server');
|
||||
|
||||
const techdocsApi = {
|
||||
getTechDocsMetadata: jest.fn(),
|
||||
getEntityMetadata: jest.fn(),
|
||||
getCookie: jest.fn().mockReturnValue({
|
||||
// Expires in 10 minutes
|
||||
expiresAt: new Date(Date.now() + 10 * 60 * 1000).toISOString(),
|
||||
}),
|
||||
};
|
||||
|
||||
const techdocsStorageApi = {
|
||||
getApiOrigin: jest.fn(),
|
||||
getBaseUrl: jest.fn(),
|
||||
getEntityDocs: jest.fn(),
|
||||
syncEntityDocs: jest.fn(),
|
||||
};
|
||||
|
||||
const searchApi = {
|
||||
query: jest.fn().mockResolvedValue({ results: [] }),
|
||||
};
|
||||
|
||||
const scmIntegrationsApi = {
|
||||
fromConfig: jest.fn().mockReturnValue({}),
|
||||
};
|
||||
|
||||
const discoveryApi = {
|
||||
getBaseUrl: jest
|
||||
.fn()
|
||||
.mockResolvedValue('https://backstage.example.com/api/techdocs'),
|
||||
};
|
||||
|
||||
const fetchApi = {
|
||||
fetch: jest.fn().mockResolvedValue({
|
||||
ok: true,
|
||||
json: jest.fn().mockResolvedValue({
|
||||
// Expires in 10 minutes
|
||||
expiresAt: new Date(Date.now() + 10 * 60 * 1000).toISOString(),
|
||||
}),
|
||||
}),
|
||||
};
|
||||
|
||||
/** @ignore */
|
||||
type TechDocsAddonTesterTestApiPair<TApi> = TApi extends infer TImpl
|
||||
? readonly [ApiRef<TApi>, Partial<TImpl>]
|
||||
@@ -223,6 +183,46 @@ export class TechDocsAddonTester {
|
||||
* App instance, using the given Addon(s).
|
||||
*/
|
||||
build() {
|
||||
const techdocsApi = {
|
||||
getTechDocsMetadata: jest.fn(),
|
||||
getEntityMetadata: jest.fn(),
|
||||
getCookie: jest.fn().mockReturnValue({
|
||||
// Expires in 10 minutes
|
||||
expiresAt: new Date(Date.now() + 10 * 60 * 1000).toISOString(),
|
||||
}),
|
||||
};
|
||||
|
||||
const techdocsStorageApi = {
|
||||
getApiOrigin: jest.fn(),
|
||||
getBaseUrl: jest.fn(),
|
||||
getEntityDocs: jest.fn(),
|
||||
syncEntityDocs: jest.fn(),
|
||||
};
|
||||
|
||||
const searchApi = {
|
||||
query: jest.fn().mockResolvedValue({ results: [] }),
|
||||
};
|
||||
|
||||
const scmIntegrationsApi = {
|
||||
fromConfig: jest.fn().mockReturnValue({}),
|
||||
};
|
||||
|
||||
const discoveryApi = {
|
||||
getBaseUrl: jest
|
||||
.fn()
|
||||
.mockResolvedValue('https://backstage.example.com/api/techdocs'),
|
||||
};
|
||||
|
||||
const fetchApi = {
|
||||
fetch: jest.fn().mockResolvedValue({
|
||||
ok: true,
|
||||
json: jest.fn().mockResolvedValue({
|
||||
// Expires in 10 minutes
|
||||
expiresAt: new Date(Date.now() + 10 * 60 * 1000).toISOString(),
|
||||
}),
|
||||
}),
|
||||
};
|
||||
|
||||
const apis: TechdocsAddonTesterApis<any[]> = [
|
||||
[fetchApiRef, fetchApi],
|
||||
[discoveryApiRef, discoveryApi],
|
||||
|
||||
Reference in New Issue
Block a user