remove most usages of node-fetch
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
@@ -22,7 +22,7 @@ import {
|
||||
registerMswTestHooks,
|
||||
} from '@backstage/backend-test-utils';
|
||||
import { setupServer } from 'msw/node';
|
||||
import { rest } from 'msw';
|
||||
import { http, HttpResponse } from 'msw';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import { TECHDOCS_ANNOTATION } from '@backstage/plugin-techdocs-common';
|
||||
import { DiscoveryService } from '@backstage/backend-plugin-api';
|
||||
@@ -106,12 +106,12 @@ describe('TechDocs Collator', () => {
|
||||
});
|
||||
|
||||
worker.use(
|
||||
rest.get(
|
||||
http.get(
|
||||
'http://test-backend/static/docs/default/Component/test-entity-with-docs/search/search_index.json',
|
||||
(_, res, ctx) => res(ctx.status(200), ctx.json(mockSearchDocIndex)),
|
||||
() => HttpResponse.json(mockSearchDocIndex),
|
||||
),
|
||||
rest.get('http://test-backend/entities', (_, res, ctx) =>
|
||||
res(ctx.status(200), ctx.json(expectedEntities)),
|
||||
http.get('http://test-backend/entities', () =>
|
||||
HttpResponse.json(expectedEntities),
|
||||
),
|
||||
);
|
||||
});
|
||||
@@ -164,12 +164,12 @@ describe('TechDocs Collator', () => {
|
||||
});
|
||||
|
||||
worker.use(
|
||||
rest.get(
|
||||
http.get(
|
||||
'http://test-backend/static/docs/default/component/test-entity-with-docs/search/search_index.json',
|
||||
(_, res, ctx) => res(ctx.status(200), ctx.json(mockSearchDocIndex)),
|
||||
() => HttpResponse.json(mockSearchDocIndex),
|
||||
),
|
||||
rest.get('http://test-backend/entities', (_, res, ctx) =>
|
||||
res(ctx.status(200), ctx.json(expectedEntities)),
|
||||
http.get('http://test-backend/entities', () =>
|
||||
HttpResponse.json(expectedEntities),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -21,7 +21,6 @@ import {
|
||||
RELATION_OWNED_BY,
|
||||
stringifyEntityRef,
|
||||
} from '@backstage/catalog-model';
|
||||
import fetch from 'node-fetch';
|
||||
import unescape from 'lodash/unescape';
|
||||
import { Logger } from 'winston';
|
||||
import pLimit from 'p-limit';
|
||||
|
||||
@@ -27,28 +27,23 @@ import * as winston from 'winston';
|
||||
import { TechDocsCache } from '../cache';
|
||||
import { DocsBuilder, shouldCheckForUpdate } from '../DocsBuilder';
|
||||
import { DocsSynchronizer, DocsSynchronizerSyncOpts } from './DocsSynchronizer';
|
||||
import { mockServices } from '@backstage/backend-test-utils';
|
||||
import {
|
||||
mockServices,
|
||||
registerMswTestHooks,
|
||||
} from '@backstage/backend-test-utils';
|
||||
import { DiscoveryService } from '@backstage/backend-plugin-api';
|
||||
import { http, HttpResponse } from 'msw';
|
||||
import { setupServer } from 'msw/node';
|
||||
|
||||
jest.mock('../DocsBuilder');
|
||||
jest.useFakeTimers();
|
||||
|
||||
jest.mock('node-fetch', () => ({
|
||||
__esModule: true,
|
||||
default: async () => {
|
||||
return {
|
||||
json: async () => {
|
||||
return {
|
||||
build_timestamp: 123,
|
||||
};
|
||||
},
|
||||
};
|
||||
},
|
||||
}));
|
||||
|
||||
const MockedDocsBuilder = DocsBuilder as jest.MockedClass<typeof DocsBuilder>;
|
||||
|
||||
describe('DocsSynchronizer', () => {
|
||||
const worker = setupServer();
|
||||
registerMswTestHooks(worker);
|
||||
|
||||
const preparers: jest.Mocked<PreparerBuilder> = {
|
||||
register: jest.fn(),
|
||||
get: jest.fn(),
|
||||
@@ -101,6 +96,13 @@ describe('DocsSynchronizer', () => {
|
||||
scmIntegrations: ScmIntegrations.fromConfig(new ConfigReader({})),
|
||||
cache,
|
||||
});
|
||||
|
||||
worker.use(
|
||||
http.get(
|
||||
'http://backstage.local/api/techdocs/static/docs/default/component/test/techdocs_metadata.json',
|
||||
() => HttpResponse.json({ build_timestamp: 123 }),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
||||
@@ -27,7 +27,6 @@ import {
|
||||
PreparerBuilder,
|
||||
PublisherBase,
|
||||
} from '@backstage/plugin-techdocs-node';
|
||||
import fetch from 'node-fetch';
|
||||
import pLimit, { Limit } from 'p-limit';
|
||||
import { PassThrough } from 'stream';
|
||||
import * as winston from 'winston';
|
||||
|
||||
Reference in New Issue
Block a user