remove most usages of node-fetch

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2024-11-29 16:54:28 +01:00
parent f19c16fad2
commit 5c9cc05eee
75 changed files with 93 additions and 163 deletions
+1 -2
View File
@@ -77,7 +77,6 @@
"fs-extra": "^11.2.0",
"knex": "^3.0.0",
"lodash": "^4.17.21",
"node-fetch": "^2.7.0",
"p-limit": "^3.1.0",
"winston": "^3.2.1"
},
@@ -85,7 +84,7 @@
"@backstage/backend-defaults": "workspace:^",
"@backstage/backend-test-utils": "workspace:^",
"@backstage/cli": "workspace:^",
"msw": "^1.0.0",
"msw": "^2.0.0",
"supertest": "^7.0.0"
},
"configSchema": "config.d.ts"
@@ -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';