From fdf090b57fc77ff98d23d41354be68203d29eb34 Mon Sep 17 00:00:00 2001 From: blam Date: Wed, 7 Oct 2020 17:20:26 +0200 Subject: [PATCH 01/40] feat(msw); refactor away the setup commands into ttestutils --- packages/test-utils/src/testUtils/index.tsx | 1 + .../test-utils/src/testUtils/msw/index.ts | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 packages/test-utils/src/testUtils/msw/index.ts diff --git a/packages/test-utils/src/testUtils/index.tsx b/packages/test-utils/src/testUtils/index.tsx index 4c5eb642bd..8206d10834 100644 --- a/packages/test-utils/src/testUtils/index.tsx +++ b/packages/test-utils/src/testUtils/index.tsx @@ -17,3 +17,4 @@ export * from './apis'; export { default as mockBreakpoint } from './mockBreakpoint'; export { wrapInTestApp, renderInTestApp } from './appWrappers'; +export * from './msw'; diff --git a/packages/test-utils/src/testUtils/msw/index.ts b/packages/test-utils/src/testUtils/msw/index.ts new file mode 100644 index 0000000000..5bae182cb1 --- /dev/null +++ b/packages/test-utils/src/testUtils/msw/index.ts @@ -0,0 +1,22 @@ +/* + * Copyright 2020 Spotify AB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export const msw = { + setupDefaultHandlers: (worker: any) => { + beforeAll(() => worker.listen({ onUnhandledRequest: 'error' })); + afterAll(() => worker.close()); + afterEach(() => worker.resetHandlers()); + }, +}; From ec1ee64b738ebcedc677f8f06dab013417c0796d Mon Sep 17 00:00:00 2001 From: blam Date: Wed, 7 Oct 2020 17:20:51 +0200 Subject: [PATCH 02/40] chore(catalog-graphql): moving to the new msw test util helper --- plugins/catalog-graphql/package.json | 1 + plugins/catalog-graphql/src/graphql/module.test.ts | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/catalog-graphql/package.json b/plugins/catalog-graphql/package.json index 0c18624e0f..6f036686de 100644 --- a/plugins/catalog-graphql/package.json +++ b/plugins/catalog-graphql/package.json @@ -33,6 +33,7 @@ }, "devDependencies": { "@backstage/cli": "^0.1.1-alpha.24", + "@backstage/test-utils": "^0.1.1-alpha.24", "@graphql-codegen/cli": "^1.17.7", "@graphql-codegen/typescript": "^1.17.7", "@graphql-codegen/typescript-resolvers": "^1.17.7", diff --git a/plugins/catalog-graphql/src/graphql/module.test.ts b/plugins/catalog-graphql/src/graphql/module.test.ts index e3e03a9b4a..b359c4396b 100644 --- a/plugins/catalog-graphql/src/graphql/module.test.ts +++ b/plugins/catalog-graphql/src/graphql/module.test.ts @@ -21,6 +21,7 @@ import { setupServer } from 'msw/node'; import { ConfigReader } from '@backstage/config'; import { ReaderEntity } from '../service/client'; import { createLogger } from 'winston'; +import { msw } from '@backstage/test-utils'; import { gql } from 'apollo-server'; describe('Catalog Module', () => { @@ -37,9 +38,7 @@ describe('Catalog Module', () => { }, ]); - beforeAll(() => worker.listen({ onUnhandledRequest: 'error' })); - afterAll(() => worker.close()); - afterEach(() => worker.resetHandlers()); + msw.setupDefaultHandlers(worker); describe('Default Entity', () => { beforeEach(() => { From cee9ca8777c9afa9dec87168a623e7ee5b7ae835 Mon Sep 17 00:00:00 2001 From: blam Date: Thu, 8 Oct 2020 21:37:45 +0200 Subject: [PATCH 03/40] chore(catalog): using msw instead of jest-fetch-mock --- plugins/catalog/package.json | 4 +--- plugins/catalog/src/api/CatalogClient.test.ts | 7 +++---- plugins/catalog/src/setupTests.ts | 4 +++- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/plugins/catalog/package.json b/plugins/catalog/package.json index ea270b6fe9..e4b9fda24a 100644 --- a/plugins/catalog/package.json +++ b/plugins/catalog/package.json @@ -50,11 +50,9 @@ "@testing-library/user-event": "^12.0.7", "@types/jest": "^26.0.7", "@types/node": "^12.0.0", - "jest-fetch-mock": "^3.0.3", "msw": "^0.20.5", "node-fetch": "^2.6.1", - "react-test-renderer": "^16.13.1", - "whatwg-fetch": "^3.4.0" + "react-test-renderer": "^16.13.1" }, "files": [ "dist" diff --git a/plugins/catalog/src/api/CatalogClient.test.ts b/plugins/catalog/src/api/CatalogClient.test.ts index 832a114276..7c0123317d 100644 --- a/plugins/catalog/src/api/CatalogClient.test.ts +++ b/plugins/catalog/src/api/CatalogClient.test.ts @@ -19,18 +19,17 @@ import { setupServer } from 'msw/node'; import { CatalogClient } from './CatalogClient'; import { Entity } from '@backstage/catalog-model'; import { UrlPatternDiscovery } from '@backstage/core'; +import { msw } from '@backstage/test-utils'; const server = setupServer(); const mockBaseUrl = 'http://backstage:9191/i-am-a-mock-base'; const discoveryApi = UrlPatternDiscovery.compile(mockBaseUrl); describe('CatalogClient', () => { - beforeAll(() => server.listen({ onUnhandledRequest: 'error' })); - afterEach(() => server.resetHandlers()); - afterAll(() => server.close()); - let client = new CatalogClient({ discoveryApi }); + msw.setupDefaultHandlers(server); + beforeEach(() => { client = new CatalogClient({ discoveryApi }); }); diff --git a/plugins/catalog/src/setupTests.ts b/plugins/catalog/src/setupTests.ts index 4016f3f38e..aef3b98817 100644 --- a/plugins/catalog/src/setupTests.ts +++ b/plugins/catalog/src/setupTests.ts @@ -14,5 +14,7 @@ * limitations under the License. */ +import fetch from 'node-fetch'; import '@testing-library/jest-dom'; -import 'whatwg-fetch'; + +global.fetch = fetch as any; From 827bb733bfc5c07e7710159c334fec454df097fc Mon Sep 17 00:00:00 2001 From: blam Date: Thu, 8 Oct 2020 21:57:27 +0200 Subject: [PATCH 04/40] chore: reworking all deps to use cross-fetch instead --- packages/cli/templates/default-plugin/package.json.hbs | 4 ++-- packages/cli/templates/default-plugin/src/setupTests.ts | 2 +- plugins/api-docs/package.json | 1 - plugins/api-docs/src/setupTests.ts | 2 -- plugins/auth-backend/package.json | 1 - plugins/auth-backend/src/lib/catalog/CatalogIdentityClient.ts | 2 +- plugins/auth-backend/src/setupTests.ts | 2 -- plugins/catalog-backend/package.json | 1 + plugins/catalog-graphql/src/service/client.ts | 2 +- plugins/catalog/src/setupTests.ts | 4 ++-- yarn.lock | 2 +- 11 files changed, 9 insertions(+), 14 deletions(-) diff --git a/packages/cli/templates/default-plugin/package.json.hbs b/packages/cli/templates/default-plugin/package.json.hbs index e024884547..cf07851f31 100644 --- a/packages/cli/templates/default-plugin/package.json.hbs +++ b/packages/cli/templates/default-plugin/package.json.hbs @@ -41,8 +41,8 @@ "@testing-library/user-event": "^12.0.7", "@types/jest": "^26.0.7", "@types/node": "^12.0.0", - "msw": "^0.20.5", - "node-fetch": "^2.6.1" + "msw": "^0.21.2", + "cross-fetch": "^3.0.6" }, "files": [ "dist" diff --git a/packages/cli/templates/default-plugin/src/setupTests.ts b/packages/cli/templates/default-plugin/src/setupTests.ts index cc559f672e..ddc061ad7e 100644 --- a/packages/cli/templates/default-plugin/src/setupTests.ts +++ b/packages/cli/templates/default-plugin/src/setupTests.ts @@ -1,2 +1,2 @@ import '@testing-library/jest-dom'; -global.fetch = require('node-fetch'); +import 'cross-fetch/register' diff --git a/plugins/api-docs/package.json b/plugins/api-docs/package.json index a703b6afe5..ba3a21ab1f 100644 --- a/plugins/api-docs/package.json +++ b/plugins/api-docs/package.json @@ -49,7 +49,6 @@ "@types/node": "^12.0.0", "@types/react": "^16.9", "@types/swagger-ui-react": "^3.23.3", - "jest-fetch-mock": "^3.0.3", "msw": "^0.20.5", "node-fetch": "^2.6.1" }, diff --git a/plugins/api-docs/src/setupTests.ts b/plugins/api-docs/src/setupTests.ts index 8553642152..825bcd4115 100644 --- a/plugins/api-docs/src/setupTests.ts +++ b/plugins/api-docs/src/setupTests.ts @@ -15,5 +15,3 @@ */ import '@testing-library/jest-dom'; - -require('jest-fetch-mock').enableMocks(); diff --git a/plugins/auth-backend/package.json b/plugins/auth-backend/package.json index fca8fb7178..4579892d34 100644 --- a/plugins/auth-backend/package.json +++ b/plugins/auth-backend/package.json @@ -61,7 +61,6 @@ "@types/passport-google-oauth20": "^2.0.3", "@types/passport-microsoft": "^0.0.0", "@types/passport-saml": "^1.1.2", - "jest-fetch-mock": "^3.0.3", "msw": "^0.20.5" }, "files": [ diff --git a/plugins/auth-backend/src/lib/catalog/CatalogIdentityClient.ts b/plugins/auth-backend/src/lib/catalog/CatalogIdentityClient.ts index 2c1d66e1f8..b6919a98c1 100644 --- a/plugins/auth-backend/src/lib/catalog/CatalogIdentityClient.ts +++ b/plugins/auth-backend/src/lib/catalog/CatalogIdentityClient.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import fetch from 'node-fetch'; +import fetch from 'cross-fetch'; import { UserEntity } from '@backstage/catalog-model'; import { ConflictError, diff --git a/plugins/auth-backend/src/setupTests.ts b/plugins/auth-backend/src/setupTests.ts index f7b6ca962d..ba33cf996b 100644 --- a/plugins/auth-backend/src/setupTests.ts +++ b/plugins/auth-backend/src/setupTests.ts @@ -14,6 +14,4 @@ * limitations under the License. */ -require('jest-fetch-mock').enableMocks(); - export {}; diff --git a/plugins/catalog-backend/package.json b/plugins/catalog-backend/package.json index f16f629c44..83b9391732 100644 --- a/plugins/catalog-backend/package.json +++ b/plugins/catalog-backend/package.json @@ -23,6 +23,7 @@ "@backstage/backend-common": "^0.1.1-alpha.24", "@backstage/catalog-model": "^0.1.1-alpha.24", "@backstage/config": "^0.1.1-alpha.24", + "@backstage/test-utils": "^0.1.1-alpha.24", "@octokit/graphql": "^4.5.6", "@types/express": "^4.17.6", "@types/node-fetch": "^2.5.7", diff --git a/plugins/catalog-graphql/src/service/client.ts b/plugins/catalog-graphql/src/service/client.ts index 8af97a89b1..59f9e90254 100644 --- a/plugins/catalog-graphql/src/service/client.ts +++ b/plugins/catalog-graphql/src/service/client.ts @@ -15,7 +15,7 @@ */ import { Entity, EntityMeta } from '@backstage/catalog-model'; -import fetch from 'node-fetch'; +import fetch from 'cross-fetch'; import { JsonObject } from '@backstage/config'; export interface ReaderEntityMeta extends EntityMeta { diff --git a/plugins/catalog/src/setupTests.ts b/plugins/catalog/src/setupTests.ts index aef3b98817..778a9dfaa4 100644 --- a/plugins/catalog/src/setupTests.ts +++ b/plugins/catalog/src/setupTests.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import fetch from 'node-fetch'; import '@testing-library/jest-dom'; +import fetch from 'node-fetch'; -global.fetch = fetch as any; +window.fetch = fetch; diff --git a/yarn.lock b/yarn.lock index b9f5733acd..2d2665fcb4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -23514,7 +23514,7 @@ whatwg-fetch@^2.0.4: resolved "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-2.0.4.tgz#dde6a5df315f9d39991aa17621853d720b85566f" integrity sha512-dcQ1GWpOD/eEQ97k66aiEVpNnapVj90/+R+SXTPYGHpYBBypfKJEQjLrvMZ7YXbKm21gXd4NcuxUTjiv1YtLng== -whatwg-fetch@^3.0.0, whatwg-fetch@^3.4.0, whatwg-fetch@^3.4.1: +whatwg-fetch@^3.0.0, whatwg-fetch@^3.4.1: version "3.4.1" resolved "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-3.4.1.tgz#e5f871572d6879663fa5674c8f833f15a8425ab3" integrity sha512-sofZVzE1wKwO+EYPbWfiwzaKovWiZXf4coEzjGP9b2GBVgQRLQUZ2QcuPpQExGDAW5GItpEm6Tl4OU5mywnAoQ== From 813504018e241ca1edf2deda014f0eb087315684 Mon Sep 17 00:00:00 2001 From: blam Date: Thu, 8 Oct 2020 21:58:24 +0200 Subject: [PATCH 05/40] chore: update deps --- plugins/api-docs/package.json | 5 +++-- plugins/catalog/package.json | 5 +++-- plugins/circleci/package.json | 5 +++-- plugins/cloudbuild/package.json | 5 +++-- plugins/cost-insights/package.json | 5 +++-- plugins/explore/package.json | 5 +++-- plugins/gcp-projects/package.json | 5 +++-- plugins/github-actions/package.json | 5 +++-- plugins/gitops-profiles/package.json | 5 +++-- plugins/graphiql/package.json | 5 +++-- plugins/jenkins/package.json | 5 +++-- plugins/kubernetes/package.json | 5 +++-- plugins/lighthouse/package.json | 5 +++-- plugins/newrelic/package.json | 5 +++-- plugins/register-component/package.json | 5 +++-- plugins/rollbar/package.json | 5 +++-- plugins/scaffolder/package.json | 5 +++-- plugins/sentry/package.json | 5 +++-- plugins/tech-radar/package.json | 5 +++-- plugins/techdocs/package.json | 5 +++-- plugins/welcome/package.json | 5 +++-- 21 files changed, 63 insertions(+), 42 deletions(-) diff --git a/plugins/api-docs/package.json b/plugins/api-docs/package.json index ba3a21ab1f..82faad0853 100644 --- a/plugins/api-docs/package.json +++ b/plugins/api-docs/package.json @@ -49,8 +49,9 @@ "@types/node": "^12.0.0", "@types/react": "^16.9", "@types/swagger-ui-react": "^3.23.3", - "msw": "^0.20.5", - "node-fetch": "^2.6.1" + "msw": "^0.21.2", + "node-fetch": "^2.6.1", + "cross-fetch": "^3.0.6" }, "files": [ "dist" diff --git a/plugins/catalog/package.json b/plugins/catalog/package.json index e4b9fda24a..b57136b7db 100644 --- a/plugins/catalog/package.json +++ b/plugins/catalog/package.json @@ -50,9 +50,10 @@ "@testing-library/user-event": "^12.0.7", "@types/jest": "^26.0.7", "@types/node": "^12.0.0", - "msw": "^0.20.5", + "msw": "^0.21.2", "node-fetch": "^2.6.1", - "react-test-renderer": "^16.13.1" + "react-test-renderer": "^16.13.1", + "cross-fetch": "^3.0.6" }, "files": [ "dist" diff --git a/plugins/circleci/package.json b/plugins/circleci/package.json index 24dc8a40e1..27ae63aae5 100644 --- a/plugins/circleci/package.json +++ b/plugins/circleci/package.json @@ -47,8 +47,9 @@ "@types/node": "^12.0.0", "@types/react-lazylog": "^4.5.0", "jest-fetch-mock": "^3.0.3", - "msw": "^0.20.5", - "node-fetch": "^2.6.1" + "msw": "^0.21.2", + "node-fetch": "^2.6.1", + "cross-fetch": "^3.0.6" }, "files": [ "dist" diff --git a/plugins/cloudbuild/package.json b/plugins/cloudbuild/package.json index 1caac1ecc5..81e7e7cc68 100644 --- a/plugins/cloudbuild/package.json +++ b/plugins/cloudbuild/package.json @@ -48,8 +48,9 @@ "@types/jest": "^26.0.7", "@types/node": "^12.0.0", "jest-fetch-mock": "^3.0.3", - "msw": "^0.20.5", - "node-fetch": "^2.6.1" + "msw": "^0.21.2", + "node-fetch": "^2.6.1", + "cross-fetch": "^3.0.6" }, "files": [ "dist" diff --git a/plugins/cost-insights/package.json b/plugins/cost-insights/package.json index a9b6a646c4..ab97e78026 100644 --- a/plugins/cost-insights/package.json +++ b/plugins/cost-insights/package.json @@ -50,8 +50,9 @@ "@types/node": "^12.0.0", "@types/recharts": "^1.8.14", "jest-fetch-mock": "^3.0.3", - "msw": "^0.20.5", - "node-fetch": "^2.6.1" + "msw": "^0.21.2", + "node-fetch": "^2.6.1", + "cross-fetch": "^3.0.6" }, "files": [ "dist" diff --git a/plugins/explore/package.json b/plugins/explore/package.json index 5bd78ab088..07265bc8d1 100644 --- a/plugins/explore/package.json +++ b/plugins/explore/package.json @@ -42,8 +42,9 @@ "@types/jest": "^26.0.7", "@types/node": "^12.0.0", "jest-fetch-mock": "^3.0.3", - "msw": "^0.20.5", - "node-fetch": "^2.6.1" + "msw": "^0.21.2", + "node-fetch": "^2.6.1", + "cross-fetch": "^3.0.6" }, "files": [ "dist" diff --git a/plugins/gcp-projects/package.json b/plugins/gcp-projects/package.json index 18a957d701..04a1b4286c 100644 --- a/plugins/gcp-projects/package.json +++ b/plugins/gcp-projects/package.json @@ -39,8 +39,9 @@ "@types/jest": "^26.0.7", "@types/node": "^12.0.0", "jest-fetch-mock": "^3.0.3", - "msw": "^0.20.5", - "node-fetch": "^2.6.1" + "msw": "^0.21.2", + "node-fetch": "^2.6.1", + "cross-fetch": "^3.0.6" }, "files": [ "dist" diff --git a/plugins/github-actions/package.json b/plugins/github-actions/package.json index a43e351d47..7afe674686 100644 --- a/plugins/github-actions/package.json +++ b/plugins/github-actions/package.json @@ -48,8 +48,9 @@ "@types/jest": "^26.0.7", "@types/node": "^12.0.0", "jest-fetch-mock": "^3.0.3", - "msw": "^0.20.5", - "node-fetch": "^2.6.1" + "msw": "^0.21.2", + "node-fetch": "^2.6.1", + "cross-fetch": "^3.0.6" }, "files": [ "dist" diff --git a/plugins/gitops-profiles/package.json b/plugins/gitops-profiles/package.json index 7c63ea350c..478637510d 100644 --- a/plugins/gitops-profiles/package.json +++ b/plugins/gitops-profiles/package.json @@ -40,8 +40,9 @@ "@types/jest": "^26.0.7", "@types/node": "^12.0.0", "jest-fetch-mock": "^3.0.3", - "msw": "^0.20.5", - "node-fetch": "^2.6.1" + "msw": "^0.21.2", + "node-fetch": "^2.6.1", + "cross-fetch": "^3.0.6" }, "files": [ "dist" diff --git a/plugins/graphiql/package.json b/plugins/graphiql/package.json index 654c5ab378..e8a6722167 100644 --- a/plugins/graphiql/package.json +++ b/plugins/graphiql/package.json @@ -53,9 +53,10 @@ "@types/jest": "^26.0.7", "@types/node": "^12.0.0", "jest-fetch-mock": "^3.0.3", - "msw": "^0.20.5", + "msw": "^0.21.2", "node-fetch": "^2.6.1", - "react-router-dom": "6.0.0-beta.0" + "react-router-dom": "6.0.0-beta.0", + "cross-fetch": "^3.0.6" }, "files": [ "dist" diff --git a/plugins/jenkins/package.json b/plugins/jenkins/package.json index 186fdbcc33..53c17b8e3d 100644 --- a/plugins/jenkins/package.json +++ b/plugins/jenkins/package.json @@ -45,8 +45,9 @@ "@types/node": "^12.0.0", "@types/testing-library__jest-dom": "^5.9.1", "jest-fetch-mock": "^3.0.3", - "msw": "^0.20.5", - "node-fetch": "^2.6.1" + "msw": "^0.21.2", + "node-fetch": "^2.6.1", + "cross-fetch": "^3.0.6" }, "files": [ "dist" diff --git a/plugins/kubernetes/package.json b/plugins/kubernetes/package.json index 5dc9231c2a..da3dac6c63 100644 --- a/plugins/kubernetes/package.json +++ b/plugins/kubernetes/package.json @@ -43,8 +43,9 @@ "@types/jest": "^26.0.7", "@types/node": "^12.0.0", "jest-fetch-mock": "^3.0.3", - "msw": "^0.20.5", - "node-fetch": "^2.6.1" + "msw": "^0.21.2", + "node-fetch": "^2.6.1", + "cross-fetch": "^3.0.6" }, "files": [ "dist" diff --git a/plugins/lighthouse/package.json b/plugins/lighthouse/package.json index 0b30e48689..2954cb7afb 100644 --- a/plugins/lighthouse/package.json +++ b/plugins/lighthouse/package.json @@ -43,8 +43,9 @@ "@types/jest": "^26.0.7", "@types/node": "^12.0.0", "jest-fetch-mock": "^3.0.3", - "msw": "^0.20.5", - "node-fetch": "^2.6.1" + "msw": "^0.21.2", + "node-fetch": "^2.6.1", + "cross-fetch": "^3.0.6" }, "files": [ "dist" diff --git a/plugins/newrelic/package.json b/plugins/newrelic/package.json index 603d01d62b..a616a810a7 100644 --- a/plugins/newrelic/package.json +++ b/plugins/newrelic/package.json @@ -39,8 +39,9 @@ "@types/jest": "^26.0.7", "@types/node": "^12.0.0", "jest-fetch-mock": "^3.0.3", - "msw": "^0.20.5", - "node-fetch": "^2.6.1" + "msw": "^0.21.2", + "node-fetch": "^2.6.1", + "cross-fetch": "^3.0.6" }, "files": [ "dist" diff --git a/plugins/register-component/package.json b/plugins/register-component/package.json index 9dbd598dee..d459a6e815 100644 --- a/plugins/register-component/package.json +++ b/plugins/register-component/package.json @@ -44,8 +44,9 @@ "@types/jest": "^26.0.7", "@types/node": "^12.0.0", "jest-fetch-mock": "^3.0.3", - "msw": "^0.20.5", - "node-fetch": "^2.6.1" + "msw": "^0.21.2", + "node-fetch": "^2.6.1", + "cross-fetch": "^3.0.6" }, "files": [ "dist" diff --git a/plugins/rollbar/package.json b/plugins/rollbar/package.json index ba690fde64..e6574b4ae7 100644 --- a/plugins/rollbar/package.json +++ b/plugins/rollbar/package.json @@ -48,8 +48,9 @@ "@types/node": "^12.0.0", "@types/react": "^16.9", "jest-fetch-mock": "^3.0.3", - "msw": "^0.20.5", - "node-fetch": "^2.6.1" + "msw": "^0.21.2", + "node-fetch": "^2.6.1", + "cross-fetch": "^3.0.6" }, "files": [ "dist" diff --git a/plugins/scaffolder/package.json b/plugins/scaffolder/package.json index 1e59019ad7..6bb0e88fb0 100644 --- a/plugins/scaffolder/package.json +++ b/plugins/scaffolder/package.json @@ -50,8 +50,9 @@ "@types/jest": "^26.0.7", "@types/node": "^12.0.0", "jest-fetch-mock": "^3.0.3", - "msw": "^0.20.5", - "node-fetch": "^2.6.1" + "msw": "^0.21.2", + "node-fetch": "^2.6.1", + "cross-fetch": "^3.0.6" }, "files": [ "dist" diff --git a/plugins/sentry/package.json b/plugins/sentry/package.json index 6972b87823..14c583f4db 100644 --- a/plugins/sentry/package.json +++ b/plugins/sentry/package.json @@ -44,8 +44,9 @@ "@types/jest": "^26.0.7", "@types/node": "^12.0.0", "jest-fetch-mock": "^3.0.3", - "msw": "^0.20.5", - "node-fetch": "^2.6.1" + "msw": "^0.21.2", + "node-fetch": "^2.6.1", + "cross-fetch": "^3.0.6" }, "files": [ "dist" diff --git a/plugins/tech-radar/package.json b/plugins/tech-radar/package.json index d6067ba3e2..a49bb805eb 100644 --- a/plugins/tech-radar/package.json +++ b/plugins/tech-radar/package.json @@ -46,8 +46,9 @@ "@types/node": "^12.0.0", "@types/react": "^16.9", "jest-fetch-mock": "^3.0.3", - "msw": "^0.20.5", - "node-fetch": "^2.6.1" + "msw": "^0.21.2", + "node-fetch": "^2.6.1", + "cross-fetch": "^3.0.6" }, "files": [ "dist" diff --git a/plugins/techdocs/package.json b/plugins/techdocs/package.json index 27b0b0b881..79eeb8ed5f 100644 --- a/plugins/techdocs/package.json +++ b/plugins/techdocs/package.json @@ -49,8 +49,9 @@ "@types/node": "^12.0.0", "canvas": "^2.6.1", "jest-fetch-mock": "^3.0.3", - "msw": "^0.20.5", - "node-fetch": "^2.6.1" + "msw": "^0.21.2", + "node-fetch": "^2.6.1", + "cross-fetch": "^3.0.6" }, "files": [ "dist" diff --git a/plugins/welcome/package.json b/plugins/welcome/package.json index 80f930bbc2..7c50b200e6 100644 --- a/plugins/welcome/package.json +++ b/plugins/welcome/package.json @@ -40,8 +40,9 @@ "@types/jest": "^26.0.7", "@types/node": "^12.0.0", "jest-fetch-mock": "^3.0.3", - "msw": "^0.20.5", - "node-fetch": "^2.6.1" + "msw": "^0.21.2", + "node-fetch": "^2.6.1", + "cross-fetch": "^3.0.6" }, "files": [ "dist" From d30ef3924bfb9eea9846ffb0097ba6d75efd5e62 Mon Sep 17 00:00:00 2001 From: blam Date: Thu, 8 Oct 2020 22:38:06 +0200 Subject: [PATCH 06/40] chore(catalog-backend): updating to use msw + cross-fetch --- plugins/catalog-backend/package.json | 10 ++++------ .../ingestion/processors/AzureApiReaderProcessor.ts | 8 +++----- .../processors/BitbucketApiReaderProcessor.ts | 6 +++--- .../src/ingestion/processors/GithubReaderProcessor.ts | 6 +++--- .../ingestion/processors/GitlabApiReaderProcessor.ts | 6 +++--- .../src/ingestion/processors/GitlabReaderProcessor.ts | 6 +++--- 6 files changed, 19 insertions(+), 23 deletions(-) diff --git a/plugins/catalog-backend/package.json b/plugins/catalog-backend/package.json index 83b9391732..77564d1dee 100644 --- a/plugins/catalog-backend/package.json +++ b/plugins/catalog-backend/package.json @@ -23,10 +23,8 @@ "@backstage/backend-common": "^0.1.1-alpha.24", "@backstage/catalog-model": "^0.1.1-alpha.24", "@backstage/config": "^0.1.1-alpha.24", - "@backstage/test-utils": "^0.1.1-alpha.24", "@octokit/graphql": "^4.5.6", "@types/express": "^4.17.6", - "@types/node-fetch": "^2.5.7", "codeowners-utils": "^1.0.2", "core-js": "^3.6.5", "express": "^4.17.1", @@ -36,8 +34,8 @@ "knex": "^0.21.1", "ldapjs": "^2.2.0", "lodash": "^4.17.15", + "cross-fetch": "^3.0.6", "morgan": "^1.10.0", - "node-fetch": "^2.6.0", "sqlite3": "^5.0.0", "uuid": "^8.0.0", "winston": "^3.2.1", @@ -54,9 +52,9 @@ "@types/supertest": "^2.0.8", "@types/uuid": "^8.0.0", "@types/yup": "^0.28.2", - "jest-fetch-mock": "^3.0.3", - "msw": "^0.20.5", - "supertest": "^4.0.2" + "@backstage/test-utils": "^0.1.1-alpha.24", + "supertest": "^4.0.2", + "msw": "^0.21.2" }, "files": [ "dist", diff --git a/plugins/catalog-backend/src/ingestion/processors/AzureApiReaderProcessor.ts b/plugins/catalog-backend/src/ingestion/processors/AzureApiReaderProcessor.ts index 2a15c18c84..2e28da1d93 100644 --- a/plugins/catalog-backend/src/ingestion/processors/AzureApiReaderProcessor.ts +++ b/plugins/catalog-backend/src/ingestion/processors/AzureApiReaderProcessor.ts @@ -15,7 +15,7 @@ */ import { LocationSpec } from '@backstage/catalog-model'; -import fetch, { RequestInit, HeadersInit } from 'node-fetch'; +import fetch from 'cross-fetch'; import * as result from './results'; import { LocationProcessor, LocationProcessorEmit } from './types'; import { Config } from '@backstage/config'; @@ -44,11 +44,9 @@ export class AzureApiReaderProcessor implements LocationProcessor { ).toString('base64')}`; } - const requestOptions: RequestInit = { + return { headers, }; - - return requestOptions; } async readLocation( @@ -67,7 +65,7 @@ export class AzureApiReaderProcessor implements LocationProcessor { // for private repos when PAT is not valid, Azure API returns a http status code 203 with sign in page html if (response.ok && response.status !== 203) { - const data = await response.buffer(); + const data = Buffer.from(await response.text()); emit(result.data(location, data)); } else { const message = `${location.target} could not be read as ${url}, ${response.status} ${response.statusText}`; diff --git a/plugins/catalog-backend/src/ingestion/processors/BitbucketApiReaderProcessor.ts b/plugins/catalog-backend/src/ingestion/processors/BitbucketApiReaderProcessor.ts index b3720a5b76..a982b4d268 100644 --- a/plugins/catalog-backend/src/ingestion/processors/BitbucketApiReaderProcessor.ts +++ b/plugins/catalog-backend/src/ingestion/processors/BitbucketApiReaderProcessor.ts @@ -15,7 +15,7 @@ */ import { LocationSpec } from '@backstage/catalog-model'; -import fetch, { RequestInit, HeadersInit } from 'node-fetch'; +import fetch from 'cross-fetch'; import * as result from './results'; import { LocationProcessor, LocationProcessorEmit } from './types'; import { Config } from '@backstage/config'; @@ -70,8 +70,8 @@ export class BitbucketApiReaderProcessor implements LocationProcessor { const response = await fetch(url.toString(), this.getRequestOptions()); if (response.ok) { - const data = await response.buffer(); - emit(result.data(location, data)); + const data = await response.text(); + emit(result.data(location, Buffer.from(data))); } else { const message = `${location.target} could not be read as ${url}, ${response.status} ${response.statusText}`; if (response.status === 404) { diff --git a/plugins/catalog-backend/src/ingestion/processors/GithubReaderProcessor.ts b/plugins/catalog-backend/src/ingestion/processors/GithubReaderProcessor.ts index 89d1f69860..372ef5d20b 100644 --- a/plugins/catalog-backend/src/ingestion/processors/GithubReaderProcessor.ts +++ b/plugins/catalog-backend/src/ingestion/processors/GithubReaderProcessor.ts @@ -17,7 +17,7 @@ import { LocationSpec } from '@backstage/catalog-model'; import { Config } from '@backstage/config'; import parseGitUri from 'git-url-parse'; -import fetch, { HeadersInit, RequestInit } from 'node-fetch'; +import fetch from 'cross-fetch'; import { Logger } from 'winston'; import * as result from './results'; import { LocationProcessor, LocationProcessorEmit } from './types'; @@ -252,8 +252,8 @@ export class GithubReaderProcessor implements LocationProcessor { const response = await fetch(url.toString(), options); if (response.ok) { - const data = await response.buffer(); - emit(result.data(location, data)); + const data = await response.text(); + emit(result.data(location, Buffer.from(data))); } else { const message = `${location.target} could not be read as ${url}, ${response.status} ${response.statusText}`; if (response.status === 404) { diff --git a/plugins/catalog-backend/src/ingestion/processors/GitlabApiReaderProcessor.ts b/plugins/catalog-backend/src/ingestion/processors/GitlabApiReaderProcessor.ts index aeba7a7ebe..c55c203b51 100644 --- a/plugins/catalog-backend/src/ingestion/processors/GitlabApiReaderProcessor.ts +++ b/plugins/catalog-backend/src/ingestion/processors/GitlabApiReaderProcessor.ts @@ -15,7 +15,7 @@ */ import { LocationSpec } from '@backstage/catalog-model'; -import fetch, { RequestInit, HeadersInit } from 'node-fetch'; +import fetch from 'cross-fetch'; import * as result from './results'; import { LocationProcessor, LocationProcessorEmit } from './types'; import { Config } from '@backstage/config'; @@ -61,8 +61,8 @@ export class GitlabApiReaderProcessor implements LocationProcessor { const url = this.buildRawUrl(location.target, projectID); const response = await fetch(url.toString(), this.getRequestOptions()); if (response.ok) { - const data = await response.buffer(); - emit(result.data(location, data)); + const data = await response.text(); + emit(result.data(location, Buffer.from(data))); } else { const message = `${location.target} could not be read as ${url}, ${response.status} ${response.statusText}`; if (response.status === 404) { diff --git a/plugins/catalog-backend/src/ingestion/processors/GitlabReaderProcessor.ts b/plugins/catalog-backend/src/ingestion/processors/GitlabReaderProcessor.ts index b51bf85a8e..c682300706 100644 --- a/plugins/catalog-backend/src/ingestion/processors/GitlabReaderProcessor.ts +++ b/plugins/catalog-backend/src/ingestion/processors/GitlabReaderProcessor.ts @@ -15,7 +15,7 @@ */ import { LocationSpec } from '@backstage/catalog-model'; -import fetch from 'node-fetch'; +import fetch from 'cross-fetch'; import * as result from './results'; import { LocationProcessor, LocationProcessorEmit } from './types'; @@ -40,8 +40,8 @@ export class GitlabReaderProcessor implements LocationProcessor { const response = await fetch(url.toString()); if (response.ok) { - const data = await response.buffer(); - emit(result.data(location, data)); + const data = await response.text(); + emit(result.data(location, Buffer.from(data))); } else { const message = `${location.target} could not be read as ${url}, ${response.status} ${response.statusText}`; if (response.status === 404) { From 2abca02daa56e90231e6fe9e3f4019d17bfae58e Mon Sep 17 00:00:00 2001 From: blam Date: Thu, 8 Oct 2020 22:42:09 +0200 Subject: [PATCH 07/40] chore(catalog-backend): fixing some more testsn --- plugins/catalog-backend/package.json | 8 ++++---- .../src/ingestion/processors/UrlReaderProcessor.test.ts | 6 ++---- .../src/ingestion/processors/util/github.test.ts | 5 ++--- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/plugins/catalog-backend/package.json b/plugins/catalog-backend/package.json index 77564d1dee..4a3b2c7442 100644 --- a/plugins/catalog-backend/package.json +++ b/plugins/catalog-backend/package.json @@ -27,6 +27,7 @@ "@types/express": "^4.17.6", "codeowners-utils": "^1.0.2", "core-js": "^3.6.5", + "cross-fetch": "^3.0.6", "express": "^4.17.1", "express-promise-router": "^3.0.3", "fs-extra": "^9.0.0", @@ -34,7 +35,6 @@ "knex": "^0.21.1", "ldapjs": "^2.2.0", "lodash": "^4.17.15", - "cross-fetch": "^3.0.6", "morgan": "^1.10.0", "sqlite3": "^5.0.0", "uuid": "^8.0.0", @@ -45,6 +45,7 @@ }, "devDependencies": { "@backstage/cli": "^0.1.1-alpha.24", + "@backstage/test-utils": "^0.1.1-alpha.24", "@types/core-js": "^2.5.4", "@types/git-url-parse": "^9.0.0", "@types/ldapjs": "^1.0.9", @@ -52,9 +53,8 @@ "@types/supertest": "^2.0.8", "@types/uuid": "^8.0.0", "@types/yup": "^0.28.2", - "@backstage/test-utils": "^0.1.1-alpha.24", - "supertest": "^4.0.2", - "msw": "^0.21.2" + "msw": "^0.21.2", + "supertest": "^4.0.2" }, "files": [ "dist", diff --git a/plugins/catalog-backend/src/ingestion/processors/UrlReaderProcessor.test.ts b/plugins/catalog-backend/src/ingestion/processors/UrlReaderProcessor.test.ts index 009872cda3..751897bea9 100644 --- a/plugins/catalog-backend/src/ingestion/processors/UrlReaderProcessor.test.ts +++ b/plugins/catalog-backend/src/ingestion/processors/UrlReaderProcessor.test.ts @@ -22,6 +22,7 @@ import { } from './types'; import { setupServer } from 'msw/node'; import { rest } from 'msw'; +import { msw } from '@backstage/test-utils'; import { getVoidLogger, UrlReaders } from '@backstage/backend-common'; import { ConfigReader } from '@backstage/config'; @@ -29,10 +30,7 @@ describe('UrlReaderProcessor', () => { const mockApiOrigin = 'http://localhost:23000'; const server = setupServer(); - beforeAll(() => server.listen({ onUnhandledRequest: 'error' })); - afterEach(() => server.resetHandlers()); - afterAll(() => server.close()); - + msw.setupDefaultHandlers(server); it('should load from url', async () => { const logger = getVoidLogger(); const reader = UrlReaders.default({ logger, config: new ConfigReader({}) }); diff --git a/plugins/catalog-backend/src/ingestion/processors/util/github.test.ts b/plugins/catalog-backend/src/ingestion/processors/util/github.test.ts index 25a37e0546..54afdd1bdc 100644 --- a/plugins/catalog-backend/src/ingestion/processors/util/github.test.ts +++ b/plugins/catalog-backend/src/ingestion/processors/util/github.test.ts @@ -17,6 +17,7 @@ import { graphql } from '@octokit/graphql'; import { graphql as graphqlMsw } from 'msw'; import { setupServer } from 'msw/node'; +import { msw } from '@backstage/test-utils'; import { getOrganizationTeams, getOrganizationUsers, @@ -26,9 +27,7 @@ import { describe('github', () => { const server = setupServer(); - beforeAll(() => server.listen({ onUnhandledRequest: 'error' })); - afterEach(() => server.resetHandlers()); - afterAll(() => server.close()); + msw.setupDefaultHandlers(server); describe('getOrganizationUsers', () => { it('reads members', async () => { From 9f1e30a3bd5d244b9777fb2e78c856aed2ff505a Mon Sep 17 00:00:00 2001 From: blam Date: Thu, 8 Oct 2020 22:47:46 +0200 Subject: [PATCH 08/40] chore: remove some occurrences of node-fetch --- plugins/api-docs/package.json | 1 - plugins/auth-backend/package.json | 5 ++--- plugins/catalog-graphql/package.json | 4 ++-- plugins/catalog/src/setupTests.ts | 4 +--- 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/plugins/api-docs/package.json b/plugins/api-docs/package.json index 82faad0853..d00d4497da 100644 --- a/plugins/api-docs/package.json +++ b/plugins/api-docs/package.json @@ -50,7 +50,6 @@ "@types/react": "^16.9", "@types/swagger-ui-react": "^3.23.3", "msw": "^0.21.2", - "node-fetch": "^2.6.1", "cross-fetch": "^3.0.6" }, "files": [ diff --git a/plugins/auth-backend/package.json b/plugins/auth-backend/package.json index 4579892d34..513fb540f2 100644 --- a/plugins/auth-backend/package.json +++ b/plugins/auth-backend/package.json @@ -37,7 +37,6 @@ "knex": "^0.21.1", "moment": "^2.26.0", "morgan": "^1.10.0", - "node-fetch": "^2.6.1", "passport": "^0.4.1", "passport-github2": "^0.1.12", "passport-gitlab2": "^5.0.0", @@ -55,13 +54,13 @@ "@types/body-parser": "^1.19.0", "@types/cookie-parser": "^1.4.2", "@types/jwt-decode": "2.2.1", - "@types/node-fetch": "^2.5.7", "@types/passport": "^1.0.3", "@types/passport-github2": "^1.2.4", "@types/passport-google-oauth20": "^2.0.3", "@types/passport-microsoft": "^0.0.0", "@types/passport-saml": "^1.1.2", - "msw": "^0.20.5" + "msw": "^0.21.2", + "cross-fetch": "^3.0.6" }, "files": [ "dist", diff --git a/plugins/catalog-graphql/package.json b/plugins/catalog-graphql/package.json index 6f036686de..29f85005c1 100644 --- a/plugins/catalog-graphql/package.json +++ b/plugins/catalog-graphql/package.json @@ -28,7 +28,7 @@ "graphql": "^15.3.0", "graphql-tag": "^2.11.0", "graphql-type-json": "^0.3.2", - "node-fetch": "^2.6.0", + "cross-fetch": "^3.0.6", "winston": "^3.2.1" }, "devDependencies": { @@ -40,8 +40,8 @@ "@types/express": "^4.17.7", "@types/supertest": "^2.0.8", "eslint-plugin-graphql": "^4.0.0", - "msw": "^0.20.5", "supertest": "^4.0.2", + "msw": "^0.21.2", "ts-node": "^8.10.2" }, "files": [ diff --git a/plugins/catalog/src/setupTests.ts b/plugins/catalog/src/setupTests.ts index 778a9dfaa4..aea2220869 100644 --- a/plugins/catalog/src/setupTests.ts +++ b/plugins/catalog/src/setupTests.ts @@ -15,6 +15,4 @@ */ import '@testing-library/jest-dom'; -import fetch from 'node-fetch'; - -window.fetch = fetch; +import 'cross-fetch/polyfill'; From c82a87f035db9ec18d17e0e1a5120fcf119efb11 Mon Sep 17 00:00:00 2001 From: blam Date: Thu, 8 Oct 2020 22:56:14 +0200 Subject: [PATCH 09/40] chore(catalog-graphql): updating package deps and using the new way to test --- plugins/catalog-graphql/src/service/client.test.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/plugins/catalog-graphql/src/service/client.test.ts b/plugins/catalog-graphql/src/service/client.test.ts index d8cc59d1a8..c9708af2d0 100644 --- a/plugins/catalog-graphql/src/service/client.test.ts +++ b/plugins/catalog-graphql/src/service/client.test.ts @@ -16,13 +16,11 @@ import { CatalogClient } from './client'; import { rest } from 'msw'; import { setupServer } from 'msw/node'; +import { msw } from '@backstage/test-utils'; describe('Catalog GraphQL Module', () => { const worker = setupServer(); - - beforeAll(() => worker.listen({ onUnhandledRequest: 'error' })); - afterAll(() => worker.close()); - afterEach(() => worker.resetHandlers()); + msw.setupDefaultHandlers(worker); const baseUrl = 'http://localhost:1234'; From 00eaa37a1b07a9a5df2da44a8773a45a4d102b9c Mon Sep 17 00:00:00 2001 From: blam Date: Thu, 8 Oct 2020 23:01:23 +0200 Subject: [PATCH 10/40] chore(circleci): removing jest-fetch-mock dependency --- plugins/circleci/package.json | 2 -- plugins/circleci/src/setupTests.ts | 2 -- 2 files changed, 4 deletions(-) diff --git a/plugins/circleci/package.json b/plugins/circleci/package.json index 27ae63aae5..761f22f4b1 100644 --- a/plugins/circleci/package.json +++ b/plugins/circleci/package.json @@ -46,9 +46,7 @@ "@types/jest": "^26.0.7", "@types/node": "^12.0.0", "@types/react-lazylog": "^4.5.0", - "jest-fetch-mock": "^3.0.3", "msw": "^0.21.2", - "node-fetch": "^2.6.1", "cross-fetch": "^3.0.6" }, "files": [ diff --git a/plugins/circleci/src/setupTests.ts b/plugins/circleci/src/setupTests.ts index a838246198..8925258421 100644 --- a/plugins/circleci/src/setupTests.ts +++ b/plugins/circleci/src/setupTests.ts @@ -15,5 +15,3 @@ */ import '@testing-library/jest-dom/extend-expect'; - -require('jest-fetch-mock').enableMocks(); From 3cf6336a50a6deb59f60abe591961ed251178643 Mon Sep 17 00:00:00 2001 From: blam Date: Fri, 9 Oct 2020 12:04:27 +0200 Subject: [PATCH 11/40] chore(cloudbuild): removing the dependency on jest-fetch-mock and node-fetch --- plugins/cloudbuild/package.json | 2 -- plugins/cloudbuild/src/setupTests.ts | 2 -- 2 files changed, 4 deletions(-) diff --git a/plugins/cloudbuild/package.json b/plugins/cloudbuild/package.json index 81e7e7cc68..290e3f2e80 100644 --- a/plugins/cloudbuild/package.json +++ b/plugins/cloudbuild/package.json @@ -47,9 +47,7 @@ "@testing-library/user-event": "^12.0.7", "@types/jest": "^26.0.7", "@types/node": "^12.0.0", - "jest-fetch-mock": "^3.0.3", "msw": "^0.21.2", - "node-fetch": "^2.6.1", "cross-fetch": "^3.0.6" }, "files": [ diff --git a/plugins/cloudbuild/src/setupTests.ts b/plugins/cloudbuild/src/setupTests.ts index 4b4cdbdaaf..0bfa67b49a 100644 --- a/plugins/cloudbuild/src/setupTests.ts +++ b/plugins/cloudbuild/src/setupTests.ts @@ -14,5 +14,3 @@ * limitations under the License. */ import '@testing-library/jest-dom'; - -require('jest-fetch-mock').enableMocks(); From b31a2ea352d5437b81e29957b4c50f7f0aeb41b0 Mon Sep 17 00:00:00 2001 From: blam Date: Fri, 9 Oct 2020 12:10:40 +0200 Subject: [PATCH 12/40] chore(cost-insigts): removing jest-fetch-mock and node-fetch dependency --- plugins/cost-insights/package.json | 2 -- plugins/cost-insights/src/setupTests.ts | 2 -- 2 files changed, 4 deletions(-) diff --git a/plugins/cost-insights/package.json b/plugins/cost-insights/package.json index ab97e78026..36e6a16218 100644 --- a/plugins/cost-insights/package.json +++ b/plugins/cost-insights/package.json @@ -49,9 +49,7 @@ "@types/jest": "^26.0.7", "@types/node": "^12.0.0", "@types/recharts": "^1.8.14", - "jest-fetch-mock": "^3.0.3", "msw": "^0.21.2", - "node-fetch": "^2.6.1", "cross-fetch": "^3.0.6" }, "files": [ diff --git a/plugins/cost-insights/src/setupTests.ts b/plugins/cost-insights/src/setupTests.ts index 8553642152..825bcd4115 100644 --- a/plugins/cost-insights/src/setupTests.ts +++ b/plugins/cost-insights/src/setupTests.ts @@ -15,5 +15,3 @@ */ import '@testing-library/jest-dom'; - -require('jest-fetch-mock').enableMocks(); From 304a7cdaf806bed134e6cbfb244355fcd4dcb236 Mon Sep 17 00:00:00 2001 From: blam Date: Fri, 9 Oct 2020 12:12:36 +0200 Subject: [PATCH 13/40] chore(explore): removing the node-fetch and jest-fetch-mock dependency --- plugins/explore/package.json | 2 -- plugins/explore/src/setupTests.ts | 2 -- 2 files changed, 4 deletions(-) diff --git a/plugins/explore/package.json b/plugins/explore/package.json index 07265bc8d1..5d0c139b8b 100644 --- a/plugins/explore/package.json +++ b/plugins/explore/package.json @@ -41,9 +41,7 @@ "@testing-library/user-event": "^12.0.7", "@types/jest": "^26.0.7", "@types/node": "^12.0.0", - "jest-fetch-mock": "^3.0.3", "msw": "^0.21.2", - "node-fetch": "^2.6.1", "cross-fetch": "^3.0.6" }, "files": [ diff --git a/plugins/explore/src/setupTests.ts b/plugins/explore/src/setupTests.ts index 8553642152..825bcd4115 100644 --- a/plugins/explore/src/setupTests.ts +++ b/plugins/explore/src/setupTests.ts @@ -15,5 +15,3 @@ */ import '@testing-library/jest-dom'; - -require('jest-fetch-mock').enableMocks(); From 5f66d4f86b16deb0bebaa8a8e9a51f6851279e93 Mon Sep 17 00:00:00 2001 From: blam Date: Fri, 9 Oct 2020 12:56:17 +0200 Subject: [PATCH 14/40] chore(gcp-projects): removing node-fetch and jest-fetch-mock as dependencies --- plugins/gcp-projects/package.json | 2 -- plugins/gcp-projects/src/setupTests.ts | 2 -- 2 files changed, 4 deletions(-) diff --git a/plugins/gcp-projects/package.json b/plugins/gcp-projects/package.json index 04a1b4286c..0862cdc0d4 100644 --- a/plugins/gcp-projects/package.json +++ b/plugins/gcp-projects/package.json @@ -38,9 +38,7 @@ "@testing-library/user-event": "^12.0.7", "@types/jest": "^26.0.7", "@types/node": "^12.0.0", - "jest-fetch-mock": "^3.0.3", "msw": "^0.21.2", - "node-fetch": "^2.6.1", "cross-fetch": "^3.0.6" }, "files": [ diff --git a/plugins/gcp-projects/src/setupTests.ts b/plugins/gcp-projects/src/setupTests.ts index 8553642152..825bcd4115 100644 --- a/plugins/gcp-projects/src/setupTests.ts +++ b/plugins/gcp-projects/src/setupTests.ts @@ -15,5 +15,3 @@ */ import '@testing-library/jest-dom'; - -require('jest-fetch-mock').enableMocks(); From 338baece6feb11422b790bef05f91b0cb499183c Mon Sep 17 00:00:00 2001 From: blam Date: Fri, 9 Oct 2020 12:57:58 +0200 Subject: [PATCH 15/40] chore(github-actions): removing node-fetch and jest-fetch-mock as dependencies --- plugins/github-actions/package.json | 2 -- plugins/github-actions/src/setupTests.ts | 2 -- 2 files changed, 4 deletions(-) diff --git a/plugins/github-actions/package.json b/plugins/github-actions/package.json index 7afe674686..9a3856275a 100644 --- a/plugins/github-actions/package.json +++ b/plugins/github-actions/package.json @@ -47,9 +47,7 @@ "@testing-library/user-event": "^12.0.7", "@types/jest": "^26.0.7", "@types/node": "^12.0.0", - "jest-fetch-mock": "^3.0.3", "msw": "^0.21.2", - "node-fetch": "^2.6.1", "cross-fetch": "^3.0.6" }, "files": [ diff --git a/plugins/github-actions/src/setupTests.ts b/plugins/github-actions/src/setupTests.ts index 8553642152..825bcd4115 100644 --- a/plugins/github-actions/src/setupTests.ts +++ b/plugins/github-actions/src/setupTests.ts @@ -15,5 +15,3 @@ */ import '@testing-library/jest-dom'; - -require('jest-fetch-mock').enableMocks(); From 7e71404786297bd1b099c4545a716da0919f733d Mon Sep 17 00:00:00 2001 From: blam Date: Fri, 9 Oct 2020 13:02:21 +0200 Subject: [PATCH 16/40] chore(gitops-profiles)): removing node-fetch and jest-fetch-mock as dependencies --- plugins/gitops-profiles/package.json | 2 -- plugins/gitops-profiles/src/setupTests.ts | 2 -- 2 files changed, 4 deletions(-) diff --git a/plugins/gitops-profiles/package.json b/plugins/gitops-profiles/package.json index 478637510d..1426158ca4 100644 --- a/plugins/gitops-profiles/package.json +++ b/plugins/gitops-profiles/package.json @@ -39,9 +39,7 @@ "@testing-library/user-event": "^12.0.7", "@types/jest": "^26.0.7", "@types/node": "^12.0.0", - "jest-fetch-mock": "^3.0.3", "msw": "^0.21.2", - "node-fetch": "^2.6.1", "cross-fetch": "^3.0.6" }, "files": [ diff --git a/plugins/gitops-profiles/src/setupTests.ts b/plugins/gitops-profiles/src/setupTests.ts index 8553642152..825bcd4115 100644 --- a/plugins/gitops-profiles/src/setupTests.ts +++ b/plugins/gitops-profiles/src/setupTests.ts @@ -15,5 +15,3 @@ */ import '@testing-library/jest-dom'; - -require('jest-fetch-mock').enableMocks(); From a584730e14b4451dca27796d44998a69dccfe564 Mon Sep 17 00:00:00 2001 From: blam Date: Fri, 9 Oct 2020 13:03:12 +0200 Subject: [PATCH 17/40] chore(graphiql): removing node-fetch and jest-fetch-mock as dependencies --- plugins/graphiql/package.json | 2 -- plugins/graphiql/src/setupTests.ts | 2 -- 2 files changed, 4 deletions(-) diff --git a/plugins/graphiql/package.json b/plugins/graphiql/package.json index e8a6722167..b81d78715a 100644 --- a/plugins/graphiql/package.json +++ b/plugins/graphiql/package.json @@ -52,9 +52,7 @@ "@types/codemirror": "^0.0.97", "@types/jest": "^26.0.7", "@types/node": "^12.0.0", - "jest-fetch-mock": "^3.0.3", "msw": "^0.21.2", - "node-fetch": "^2.6.1", "react-router-dom": "6.0.0-beta.0", "cross-fetch": "^3.0.6" }, diff --git a/plugins/graphiql/src/setupTests.ts b/plugins/graphiql/src/setupTests.ts index 8553642152..825bcd4115 100644 --- a/plugins/graphiql/src/setupTests.ts +++ b/plugins/graphiql/src/setupTests.ts @@ -15,5 +15,3 @@ */ import '@testing-library/jest-dom'; - -require('jest-fetch-mock').enableMocks(); From de9840f98cfff6e8f06c4c96e1ed2a26755d3cd9 Mon Sep 17 00:00:00 2001 From: blam Date: Fri, 9 Oct 2020 13:07:26 +0200 Subject: [PATCH 18/40] chore(graphql): removing node-fetch dependnecy --- plugins/graphql/package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/graphql/package.json b/plugins/graphql/package.json index edd3f2782e..6fa210f33e 100644 --- a/plugins/graphql/package.json +++ b/plugins/graphql/package.json @@ -30,7 +30,6 @@ "express-promise-router": "^3.0.3", "graphql": "^15.3.0", "helmet": "^4.0.0", - "node-fetch": "^2.6.0", "reflect-metadata": "^0.1.13", "winston": "^3.2.1", "yn": "^4.0.0" From 8f7db2ec1fe274df101b3b0053ebee1bc89cbb4b Mon Sep 17 00:00:00 2001 From: blam Date: Fri, 9 Oct 2020 13:19:22 +0200 Subject: [PATCH 19/40] chore(yarn.lock): prune some yarn lock stuff --- .../default-backend-plugin/package.json.hbs | 3 +- yarn.lock | 29 ++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/packages/cli/templates/default-backend-plugin/package.json.hbs b/packages/cli/templates/default-backend-plugin/package.json.hbs index 40e612609a..c9c8488721 100644 --- a/packages/cli/templates/default-backend-plugin/package.json.hbs +++ b/packages/cli/templates/default-backend-plugin/package.json.hbs @@ -36,7 +36,8 @@ "@backstage/cli": "^{{version}}", "@types/supertest": "^2.0.8", "supertest": "^4.0.2", - "msw": "^0.20.5" + "msw": "^0.21.2", + "cross-fetch": "^3.0.6" }, "files": [ "dist" diff --git a/yarn.lock b/yarn.lock index 2d2665fcb4..9afd4e6e4f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8967,7 +8967,7 @@ cross-env@^7.0.0: dependencies: cross-spawn "^7.0.1" -cross-fetch@3.0.6, cross-fetch@^3.0.4, cross-fetch@^3.0.5: +cross-fetch@3.0.6, cross-fetch@^3.0.4, cross-fetch@^3.0.5, cross-fetch@^3.0.6: version "3.0.6" resolved "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.0.6.tgz#3a4040bc8941e653e0e9cf17f29ebcd177d3365c" integrity sha512-KBPUbqgFjzWlVcURG+Svp9TlhA5uliYtiNx/0r8nv0pdypeQCRJ9IaSIc3q/x3q8t3F75cHuwxVql1HFGHCNJQ== @@ -16308,6 +16308,24 @@ msw@^0.20.5: statuses "^2.0.0" yargs "^15.4.1" +msw@^0.21.2: + version "0.21.2" + resolved "https://registry.npmjs.org/msw/-/msw-0.21.2.tgz#74ed10b8eb224325652a3c3812b5460dac297bd8" + integrity sha512-XOJehxtJThNFdMJdVjxDAbZ8KuC3UltOlO5nQDks0Q1yzSUqqKcVUjbKrH7T+K2hckBr0KEY2fwJHv21R4BV2A== + dependencies: + "@open-draft/until" "^1.0.3" + "@types/cookie" "^0.4.0" + chalk "^4.1.0" + chokidar "^3.4.2" + cookie "^0.4.1" + graphql "^15.3.0" + headers-utils "^1.2.0" + node-fetch "^2.6.1" + node-match-path "^0.4.4" + node-request-interceptor "^0.5.1" + statuses "^2.0.0" + yargs "^16.0.3" + multicast-dns-service-types@^1.1.0: version "1.1.0" resolved "https://registry.npmjs.org/multicast-dns-service-types/-/multicast-dns-service-types-1.1.0.tgz#899f11d9686e5e05cb91b35d5f0e63b773cfc901" @@ -16636,6 +16654,15 @@ node-request-interceptor@^0.3.5: debug "^4.1.1" headers-utils "^1.2.0" +node-request-interceptor@^0.5.1: + version "0.5.1" + resolved "https://registry.npmjs.org/node-request-interceptor/-/node-request-interceptor-0.5.1.tgz#b4757a033bde4412d9ffc4503804abb28ed962d2" + integrity sha512-ex5mlI5nGokxocomS2Rj2r1aspmt7qZoI8OvKLt24ylp1bYCzGQ+0XD911guCNDb/kKLMIGC67HHyeFrJCz7jA== + dependencies: + "@open-draft/until" "^1.0.3" + debug "^4.1.1" + headers-utils "^1.2.0" + nodegit@0.27.0, nodegit@^0.27.0: version "0.27.0" resolved "https://registry.npmjs.org/nodegit/-/nodegit-0.27.0.tgz#4e8cc236f60e1c97324a5acff99056fe116a6ebe" From 707c2751ab1228ded0b4844401f54180c062936e Mon Sep 17 00:00:00 2001 From: blam Date: Fri, 9 Oct 2020 13:21:04 +0200 Subject: [PATCH 20/40] chore(jenkins): removing node-fetch and jest-fetch-mock as dependencies --- plugins/jenkins/package.json | 2 -- plugins/jenkins/src/setupTests.ts | 2 -- 2 files changed, 4 deletions(-) diff --git a/plugins/jenkins/package.json b/plugins/jenkins/package.json index 53c17b8e3d..93bcdf2247 100644 --- a/plugins/jenkins/package.json +++ b/plugins/jenkins/package.json @@ -44,9 +44,7 @@ "@types/jest": "^26.0.7", "@types/node": "^12.0.0", "@types/testing-library__jest-dom": "^5.9.1", - "jest-fetch-mock": "^3.0.3", "msw": "^0.21.2", - "node-fetch": "^2.6.1", "cross-fetch": "^3.0.6" }, "files": [ diff --git a/plugins/jenkins/src/setupTests.ts b/plugins/jenkins/src/setupTests.ts index 8553642152..825bcd4115 100644 --- a/plugins/jenkins/src/setupTests.ts +++ b/plugins/jenkins/src/setupTests.ts @@ -15,5 +15,3 @@ */ import '@testing-library/jest-dom'; - -require('jest-fetch-mock').enableMocks(); From f258c5e3ff09e120074841233730c821c53e1ff0 Mon Sep 17 00:00:00 2001 From: blam Date: Fri, 9 Oct 2020 13:28:24 +0200 Subject: [PATCH 21/40] chore(kuberenetes): removing node-fetch and jest-fetch-mock as dependencies --- plugins/kubernetes/package.json | 2 -- plugins/kubernetes/src/setupTests.ts | 2 -- 2 files changed, 4 deletions(-) diff --git a/plugins/kubernetes/package.json b/plugins/kubernetes/package.json index da3dac6c63..11b2f5078d 100644 --- a/plugins/kubernetes/package.json +++ b/plugins/kubernetes/package.json @@ -42,9 +42,7 @@ "@testing-library/user-event": "^12.0.7", "@types/jest": "^26.0.7", "@types/node": "^12.0.0", - "jest-fetch-mock": "^3.0.3", "msw": "^0.21.2", - "node-fetch": "^2.6.1", "cross-fetch": "^3.0.6" }, "files": [ diff --git a/plugins/kubernetes/src/setupTests.ts b/plugins/kubernetes/src/setupTests.ts index 4b4cdbdaaf..0bfa67b49a 100644 --- a/plugins/kubernetes/src/setupTests.ts +++ b/plugins/kubernetes/src/setupTests.ts @@ -14,5 +14,3 @@ * limitations under the License. */ import '@testing-library/jest-dom'; - -require('jest-fetch-mock').enableMocks(); From 54ef1eea7e14d8c7df8a91b0073d311b4cb527eb Mon Sep 17 00:00:00 2001 From: blam Date: Fri, 9 Oct 2020 13:30:49 +0200 Subject: [PATCH 22/40] chore(kubernetes-backend): removing node-fetch and jest-fetch-mock --- plugins/kubernetes-backend/package.json | 1 - plugins/kubernetes-backend/src/setupTests.ts | 2 -- 2 files changed, 3 deletions(-) diff --git a/plugins/kubernetes-backend/package.json b/plugins/kubernetes-backend/package.json index a44199ec8b..c248b74482 100644 --- a/plugins/kubernetes-backend/package.json +++ b/plugins/kubernetes-backend/package.json @@ -38,7 +38,6 @@ }, "devDependencies": { "@backstage/cli": "^0.1.1-alpha.24", - "jest-fetch-mock": "^3.0.3", "supertest": "^4.0.2" }, "files": [ diff --git a/plugins/kubernetes-backend/src/setupTests.ts b/plugins/kubernetes-backend/src/setupTests.ts index f7b6ca962d..ba33cf996b 100644 --- a/plugins/kubernetes-backend/src/setupTests.ts +++ b/plugins/kubernetes-backend/src/setupTests.ts @@ -14,6 +14,4 @@ * limitations under the License. */ -require('jest-fetch-mock').enableMocks(); - export {}; From 97e0b6df35fc9734ce126417b5ee676009f4e914 Mon Sep 17 00:00:00 2001 From: blam Date: Fri, 9 Oct 2020 13:34:08 +0200 Subject: [PATCH 23/40] chore: removing more occurences of jest-fetch-mock and node-fetch --- plugins/lighthouse/package.json | 2 -- plugins/lighthouse/src/setupTests.ts | 2 -- plugins/newrelic/package.json | 2 -- plugins/newrelic/src/setupTests.ts | 2 -- plugins/proxy-backend/package.json | 2 -- plugins/proxy-backend/src/setupTests.ts | 2 -- plugins/register-component/package.json | 2 -- plugins/register-component/src/setupTests.ts | 2 -- plugins/rollbar-backend/package.json | 1 - plugins/rollbar-backend/src/setupTests.ts | 2 -- plugins/rollbar/package.json | 2 -- plugins/rollbar/src/setupTests.ts | 2 -- 12 files changed, 23 deletions(-) diff --git a/plugins/lighthouse/package.json b/plugins/lighthouse/package.json index 2954cb7afb..6b26cf0d3b 100644 --- a/plugins/lighthouse/package.json +++ b/plugins/lighthouse/package.json @@ -42,9 +42,7 @@ "@testing-library/user-event": "^12.0.7", "@types/jest": "^26.0.7", "@types/node": "^12.0.0", - "jest-fetch-mock": "^3.0.3", "msw": "^0.21.2", - "node-fetch": "^2.6.1", "cross-fetch": "^3.0.6" }, "files": [ diff --git a/plugins/lighthouse/src/setupTests.ts b/plugins/lighthouse/src/setupTests.ts index 8553642152..825bcd4115 100644 --- a/plugins/lighthouse/src/setupTests.ts +++ b/plugins/lighthouse/src/setupTests.ts @@ -15,5 +15,3 @@ */ import '@testing-library/jest-dom'; - -require('jest-fetch-mock').enableMocks(); diff --git a/plugins/newrelic/package.json b/plugins/newrelic/package.json index a616a810a7..fbdb43fadc 100644 --- a/plugins/newrelic/package.json +++ b/plugins/newrelic/package.json @@ -38,9 +38,7 @@ "@testing-library/user-event": "^12.0.7", "@types/jest": "^26.0.7", "@types/node": "^12.0.0", - "jest-fetch-mock": "^3.0.3", "msw": "^0.21.2", - "node-fetch": "^2.6.1", "cross-fetch": "^3.0.6" }, "files": [ diff --git a/plugins/newrelic/src/setupTests.ts b/plugins/newrelic/src/setupTests.ts index 8553642152..825bcd4115 100644 --- a/plugins/newrelic/src/setupTests.ts +++ b/plugins/newrelic/src/setupTests.ts @@ -15,5 +15,3 @@ */ import '@testing-library/jest-dom'; - -require('jest-fetch-mock').enableMocks(); diff --git a/plugins/proxy-backend/package.json b/plugins/proxy-backend/package.json index 723c3e395e..0e6b8a3458 100644 --- a/plugins/proxy-backend/package.json +++ b/plugins/proxy-backend/package.json @@ -27,7 +27,6 @@ "express-promise-router": "^3.0.3", "http-proxy-middleware": "^0.19.1", "morgan": "^1.10.0", - "node-fetch": "^2.6.0", "uuid": "^8.0.0", "winston": "^3.2.1", "yaml": "^1.9.2", @@ -40,7 +39,6 @@ "@types/supertest": "^2.0.8", "@types/uuid": "^8.0.0", "@types/yup": "^0.28.2", - "jest-fetch-mock": "^3.0.3", "supertest": "^4.0.2" }, "files": [ diff --git a/plugins/proxy-backend/src/setupTests.ts b/plugins/proxy-backend/src/setupTests.ts index f7b6ca962d..ba33cf996b 100644 --- a/plugins/proxy-backend/src/setupTests.ts +++ b/plugins/proxy-backend/src/setupTests.ts @@ -14,6 +14,4 @@ * limitations under the License. */ -require('jest-fetch-mock').enableMocks(); - export {}; diff --git a/plugins/register-component/package.json b/plugins/register-component/package.json index d459a6e815..7d2482fcf3 100644 --- a/plugins/register-component/package.json +++ b/plugins/register-component/package.json @@ -43,9 +43,7 @@ "@testing-library/user-event": "^12.0.7", "@types/jest": "^26.0.7", "@types/node": "^12.0.0", - "jest-fetch-mock": "^3.0.3", "msw": "^0.21.2", - "node-fetch": "^2.6.1", "cross-fetch": "^3.0.6" }, "files": [ diff --git a/plugins/register-component/src/setupTests.ts b/plugins/register-component/src/setupTests.ts index 8553642152..825bcd4115 100644 --- a/plugins/register-component/src/setupTests.ts +++ b/plugins/register-component/src/setupTests.ts @@ -15,5 +15,3 @@ */ import '@testing-library/jest-dom'; - -require('jest-fetch-mock').enableMocks(); diff --git a/plugins/rollbar-backend/package.json b/plugins/rollbar-backend/package.json index cda105a73f..c1ea46f95e 100644 --- a/plugins/rollbar-backend/package.json +++ b/plugins/rollbar-backend/package.json @@ -39,7 +39,6 @@ "devDependencies": { "@backstage/cli": "^0.1.1-alpha.24", "@types/supertest": "^2.0.8", - "jest-fetch-mock": "^3.0.3", "supertest": "^4.0.2" }, "files": [ diff --git a/plugins/rollbar-backend/src/setupTests.ts b/plugins/rollbar-backend/src/setupTests.ts index f7b6ca962d..ba33cf996b 100644 --- a/plugins/rollbar-backend/src/setupTests.ts +++ b/plugins/rollbar-backend/src/setupTests.ts @@ -14,6 +14,4 @@ * limitations under the License. */ -require('jest-fetch-mock').enableMocks(); - export {}; diff --git a/plugins/rollbar/package.json b/plugins/rollbar/package.json index e6574b4ae7..7d5d72357e 100644 --- a/plugins/rollbar/package.json +++ b/plugins/rollbar/package.json @@ -47,9 +47,7 @@ "@types/jest": "^26.0.7", "@types/node": "^12.0.0", "@types/react": "^16.9", - "jest-fetch-mock": "^3.0.3", "msw": "^0.21.2", - "node-fetch": "^2.6.1", "cross-fetch": "^3.0.6" }, "files": [ diff --git a/plugins/rollbar/src/setupTests.ts b/plugins/rollbar/src/setupTests.ts index 8553642152..825bcd4115 100644 --- a/plugins/rollbar/src/setupTests.ts +++ b/plugins/rollbar/src/setupTests.ts @@ -15,5 +15,3 @@ */ import '@testing-library/jest-dom'; - -require('jest-fetch-mock').enableMocks(); From a0604474c1b0b8af94e60e05b3f9622f1875409c Mon Sep 17 00:00:00 2001 From: blam Date: Fri, 9 Oct 2020 13:49:10 +0200 Subject: [PATCH 24/40] chore: removing the last of the deps in the plugins --- plugins/scaffolder/package.json | 2 -- plugins/scaffolder/src/setupTests.ts | 2 -- plugins/sentry-backend/package.json | 3 +-- plugins/sentry/package.json | 2 -- plugins/sentry/src/setupTests.ts | 2 -- plugins/tech-radar/package.json | 2 -- plugins/tech-radar/src/setupTests.ts | 2 -- plugins/techdocs-backend/package.json | 2 -- plugins/techdocs/package.json | 2 -- plugins/techdocs/src/setupTests.ts | 2 -- plugins/welcome/package.json | 3 --- 11 files changed, 1 insertion(+), 23 deletions(-) diff --git a/plugins/scaffolder/package.json b/plugins/scaffolder/package.json index 6bb0e88fb0..b2518d27bf 100644 --- a/plugins/scaffolder/package.json +++ b/plugins/scaffolder/package.json @@ -49,9 +49,7 @@ "@testing-library/user-event": "^12.0.7", "@types/jest": "^26.0.7", "@types/node": "^12.0.0", - "jest-fetch-mock": "^3.0.3", "msw": "^0.21.2", - "node-fetch": "^2.6.1", "cross-fetch": "^3.0.6" }, "files": [ diff --git a/plugins/scaffolder/src/setupTests.ts b/plugins/scaffolder/src/setupTests.ts index 8553642152..825bcd4115 100644 --- a/plugins/scaffolder/src/setupTests.ts +++ b/plugins/scaffolder/src/setupTests.ts @@ -15,5 +15,3 @@ */ import '@testing-library/jest-dom'; - -require('jest-fetch-mock').enableMocks(); diff --git a/plugins/sentry-backend/package.json b/plugins/sentry-backend/package.json index c52f7176e3..91b94696ed 100644 --- a/plugins/sentry-backend/package.json +++ b/plugins/sentry-backend/package.json @@ -34,8 +34,7 @@ "yn": "^4.0.0" }, "devDependencies": { - "@backstage/cli": "^0.1.1-alpha.24", - "jest-fetch-mock": "^3.0.3" + "@backstage/cli": "^0.1.1-alpha.24" }, "files": [ "dist" diff --git a/plugins/sentry/package.json b/plugins/sentry/package.json index 14c583f4db..126c7d0c45 100644 --- a/plugins/sentry/package.json +++ b/plugins/sentry/package.json @@ -43,9 +43,7 @@ "@testing-library/user-event": "^12.0.7", "@types/jest": "^26.0.7", "@types/node": "^12.0.0", - "jest-fetch-mock": "^3.0.3", "msw": "^0.21.2", - "node-fetch": "^2.6.1", "cross-fetch": "^3.0.6" }, "files": [ diff --git a/plugins/sentry/src/setupTests.ts b/plugins/sentry/src/setupTests.ts index 8553642152..825bcd4115 100644 --- a/plugins/sentry/src/setupTests.ts +++ b/plugins/sentry/src/setupTests.ts @@ -15,5 +15,3 @@ */ import '@testing-library/jest-dom'; - -require('jest-fetch-mock').enableMocks(); diff --git a/plugins/tech-radar/package.json b/plugins/tech-radar/package.json index a49bb805eb..805946c4e3 100644 --- a/plugins/tech-radar/package.json +++ b/plugins/tech-radar/package.json @@ -45,9 +45,7 @@ "@types/jest": "^26.0.7", "@types/node": "^12.0.0", "@types/react": "^16.9", - "jest-fetch-mock": "^3.0.3", "msw": "^0.21.2", - "node-fetch": "^2.6.1", "cross-fetch": "^3.0.6" }, "files": [ diff --git a/plugins/tech-radar/src/setupTests.ts b/plugins/tech-radar/src/setupTests.ts index 8553642152..825bcd4115 100644 --- a/plugins/tech-radar/src/setupTests.ts +++ b/plugins/tech-radar/src/setupTests.ts @@ -15,5 +15,3 @@ */ import '@testing-library/jest-dom'; - -require('jest-fetch-mock').enableMocks(); diff --git a/plugins/techdocs-backend/package.json b/plugins/techdocs-backend/package.json index 75f6071464..de50bea910 100644 --- a/plugins/techdocs-backend/package.json +++ b/plugins/techdocs-backend/package.json @@ -33,13 +33,11 @@ "fs-extra": "^9.0.1", "git-url-parse": "^11.2.0", "knex": "^0.21.1", - "node-fetch": "^2.6.0", "nodegit": "^0.27.0", "winston": "^3.2.1" }, "devDependencies": { "@backstage/cli": "^0.1.1-alpha.24", - "@types/node-fetch": "^2.5.7", "supertest": "^4.0.2" }, "files": [ diff --git a/plugins/techdocs/package.json b/plugins/techdocs/package.json index 79eeb8ed5f..70a3535a89 100644 --- a/plugins/techdocs/package.json +++ b/plugins/techdocs/package.json @@ -48,9 +48,7 @@ "@types/jest": "^26.0.7", "@types/node": "^12.0.0", "canvas": "^2.6.1", - "jest-fetch-mock": "^3.0.3", "msw": "^0.21.2", - "node-fetch": "^2.6.1", "cross-fetch": "^3.0.6" }, "files": [ diff --git a/plugins/techdocs/src/setupTests.ts b/plugins/techdocs/src/setupTests.ts index 8553642152..825bcd4115 100644 --- a/plugins/techdocs/src/setupTests.ts +++ b/plugins/techdocs/src/setupTests.ts @@ -15,5 +15,3 @@ */ import '@testing-library/jest-dom'; - -require('jest-fetch-mock').enableMocks(); diff --git a/plugins/welcome/package.json b/plugins/welcome/package.json index 7c50b200e6..ed99e1ee19 100644 --- a/plugins/welcome/package.json +++ b/plugins/welcome/package.json @@ -38,10 +38,7 @@ "@testing-library/react": "^10.4.1", "@testing-library/user-event": "^12.0.7", "@types/jest": "^26.0.7", - "@types/node": "^12.0.0", - "jest-fetch-mock": "^3.0.3", "msw": "^0.21.2", - "node-fetch": "^2.6.1", "cross-fetch": "^3.0.6" }, "files": [ From a45a5d941828c2a2eb6a78b86872cb006e6c7912 Mon Sep 17 00:00:00 2001 From: blam Date: Fri, 9 Oct 2020 14:02:07 +0200 Subject: [PATCH 25/40] chore(backend-common): reworking backend common to use cross-fetch and new msw --- packages/backend-common/package.json | 6 +++--- packages/backend-common/src/reading/AzureUrlReader.test.ts | 6 ++---- packages/backend-common/src/reading/AzureUrlReader.ts | 4 ++-- .../backend-common/src/reading/BitbucketUrlReader.test.ts | 5 ++--- packages/backend-common/src/reading/BitbucketUrlReader.ts | 4 ++-- packages/backend-common/src/reading/FetchUrlReader.ts | 4 ++-- packages/backend-common/src/reading/GithubUrlReader.ts | 4 ++-- packages/backend-common/src/reading/GitlabUrlReader.test.ts | 5 ++--- packages/backend-common/src/reading/GitlabUrlReader.ts | 4 ++-- 9 files changed, 19 insertions(+), 23 deletions(-) diff --git a/packages/backend-common/package.json b/packages/backend-common/package.json index 1c888ab8fe..eb74546f23 100644 --- a/packages/backend-common/package.json +++ b/packages/backend-common/package.json @@ -32,10 +32,12 @@ "@backstage/cli-common": "^0.1.1-alpha.24", "@backstage/config": "^0.1.1-alpha.24", "@backstage/config-loader": "^0.1.1-alpha.24", + "@backstage/test-utils": "^0.1.1-alpha.24", "@types/cors": "^2.8.6", "@types/express": "^4.17.6", "compression": "^1.7.4", "cors": "^2.8.5", + "cross-fetch": "^3.0.6", "express": "^4.17.1", "express-prom-bundle": "^6.1.0", "express-promise-router": "^3.0.3", @@ -45,7 +47,6 @@ "lodash": "^4.17.15", "logform": "^2.1.1", "morgan": "^1.10.0", - "node-fetch": "^2.6.0", "prom-client": "^12.0.0", "selfsigned": "^1.10.7", "stoppable": "^1.1.0", @@ -72,8 +73,7 @@ "get-port": "^5.1.1", "http-errors": "^1.7.3", "jest": "^26.0.1", - "jest-fetch-mock": "^3.0.3", - "msw": "^0.20.5", + "msw": "^0.21.2", "supertest": "^4.0.2" }, "files": [ diff --git a/packages/backend-common/src/reading/AzureUrlReader.test.ts b/packages/backend-common/src/reading/AzureUrlReader.test.ts index c9e1fc5bc7..24b435006a 100644 --- a/packages/backend-common/src/reading/AzureUrlReader.test.ts +++ b/packages/backend-common/src/reading/AzureUrlReader.test.ts @@ -19,14 +19,13 @@ import { setupServer } from 'msw/node'; import { ConfigReader } from '@backstage/config'; import { getVoidLogger } from '../logging'; import { AzureUrlReader } from './AzureUrlReader'; +import { msw } from '@backstage/test-utils'; const logger = getVoidLogger(); describe('AzureUrlReader', () => { const worker = setupServer(); - - beforeAll(() => worker.listen({ onUnhandledRequest: 'error' })); - afterAll(() => worker.close()); + msw.setupDefaultHandlers(worker); beforeEach(() => { worker.use( @@ -41,7 +40,6 @@ describe('AzureUrlReader', () => { ), ); }); - afterEach(() => worker.resetHandlers()); const createConfig = (token?: string) => new ConfigReader( diff --git a/packages/backend-common/src/reading/AzureUrlReader.ts b/packages/backend-common/src/reading/AzureUrlReader.ts index 28fbf25eea..8e6e6a75df 100644 --- a/packages/backend-common/src/reading/AzureUrlReader.ts +++ b/packages/backend-common/src/reading/AzureUrlReader.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import fetch, { RequestInit, HeadersInit, Response } from 'node-fetch'; +import fetch from 'cross-fetch'; import { Config } from '@backstage/config'; import { NotFoundError } from '../errors'; import { ReaderFactory, UrlReader } from './types'; @@ -76,7 +76,7 @@ export class AzureUrlReader implements UrlReader { // for private repos when PAT is not valid, Azure API returns a http status code 203 with sign in page html if (response.ok && response.status !== 203) { - return response.buffer(); + return Buffer.from(await response.text()); } const message = `${url} could not be read as ${builtUrl}, ${response.status} ${response.statusText}`; diff --git a/packages/backend-common/src/reading/BitbucketUrlReader.test.ts b/packages/backend-common/src/reading/BitbucketUrlReader.test.ts index c3e61fb821..bd7c43d887 100644 --- a/packages/backend-common/src/reading/BitbucketUrlReader.test.ts +++ b/packages/backend-common/src/reading/BitbucketUrlReader.test.ts @@ -19,14 +19,14 @@ import { setupServer } from 'msw/node'; import { ConfigReader } from '@backstage/config'; import { getVoidLogger } from '../logging'; import { BitbucketUrlReader } from './BitbucketUrlReader'; +import { msw } from '@backstage/test-utils'; const logger = getVoidLogger(); describe('BitbucketUrlReader', () => { const worker = setupServer(); - beforeAll(() => worker.listen({ onUnhandledRequest: 'error' })); - afterAll(() => worker.close()); + msw.setupDefaultHandlers(worker); beforeEach(() => { worker.use( @@ -41,7 +41,6 @@ describe('BitbucketUrlReader', () => { ), ); }); - afterEach(() => worker.resetHandlers()); const createConfig = (username?: string, appPassword?: string) => new ConfigReader( diff --git a/packages/backend-common/src/reading/BitbucketUrlReader.ts b/packages/backend-common/src/reading/BitbucketUrlReader.ts index e2576eed47..bf07dc18a6 100644 --- a/packages/backend-common/src/reading/BitbucketUrlReader.ts +++ b/packages/backend-common/src/reading/BitbucketUrlReader.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import fetch, { RequestInit, HeadersInit, Response } from 'node-fetch'; +import fetch from 'cross-fetch'; import { Config } from '@backstage/config'; import { ReaderFactory, UrlReader } from './types'; import { NotFoundError } from '../errors'; @@ -84,7 +84,7 @@ export class BitbucketUrlReader implements UrlReader { } if (response.ok) { - return response.buffer(); + return Buffer.from(await response.text()); } const message = `${url} could not be read as ${builtUrl}, ${response.status} ${response.statusText}`; diff --git a/packages/backend-common/src/reading/FetchUrlReader.ts b/packages/backend-common/src/reading/FetchUrlReader.ts index ea56f2182d..46db3e73ee 100644 --- a/packages/backend-common/src/reading/FetchUrlReader.ts +++ b/packages/backend-common/src/reading/FetchUrlReader.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import fetch, { Response } from 'node-fetch'; +import fetch from 'cross-fetch'; import { NotFoundError } from '../errors'; import { UrlReader } from './types'; @@ -31,7 +31,7 @@ export class FetchUrlReader implements UrlReader { } if (response.ok) { - return response.buffer(); + return Buffer.from(''); } const message = `could not read ${url}, ${response.status} ${response.statusText}`; diff --git a/packages/backend-common/src/reading/GithubUrlReader.ts b/packages/backend-common/src/reading/GithubUrlReader.ts index e5bed6dd26..d12344ec91 100644 --- a/packages/backend-common/src/reading/GithubUrlReader.ts +++ b/packages/backend-common/src/reading/GithubUrlReader.ts @@ -16,7 +16,7 @@ import { Config } from '@backstage/config'; import parseGitUri from 'git-url-parse'; -import fetch, { HeadersInit, RequestInit, Response } from 'node-fetch'; +import fetch from 'cross-fetch'; import { NotFoundError } from '../errors'; import { ReaderFactory, UrlReader } from './types'; @@ -219,7 +219,7 @@ export class GithubUrlReader implements UrlReader { } if (response.ok) { - return response.buffer(); + return Buffer.from(await response.text()); } const message = `${url} could not be read as ${ghUrl}, ${response.status} ${response.statusText}`; diff --git a/packages/backend-common/src/reading/GitlabUrlReader.test.ts b/packages/backend-common/src/reading/GitlabUrlReader.test.ts index 09da9c4e0a..4b3aa471c3 100644 --- a/packages/backend-common/src/reading/GitlabUrlReader.test.ts +++ b/packages/backend-common/src/reading/GitlabUrlReader.test.ts @@ -19,14 +19,14 @@ import { setupServer } from 'msw/node'; import { ConfigReader } from '@backstage/config'; import { getVoidLogger } from '../logging'; import { GitlabUrlReader } from './GitlabUrlReader'; +import { msw } from '@backstage/test-utils'; const logger = getVoidLogger(); describe('GitlabUrlReader', () => { const worker = setupServer(); - beforeAll(() => worker.listen({ onUnhandledRequest: 'error' })); - afterAll(() => worker.close()); + msw.setupDefaultHandlers(worker); beforeEach(() => { worker.use( @@ -44,7 +44,6 @@ describe('GitlabUrlReader', () => { ), ); }); - afterEach(() => worker.resetHandlers()); const createConfig = (token?: string) => new ConfigReader( diff --git a/packages/backend-common/src/reading/GitlabUrlReader.ts b/packages/backend-common/src/reading/GitlabUrlReader.ts index 0e430d650c..378e76fb61 100644 --- a/packages/backend-common/src/reading/GitlabUrlReader.ts +++ b/packages/backend-common/src/reading/GitlabUrlReader.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import fetch, { RequestInit, Response } from 'node-fetch'; +import fetch from 'cross-fetch'; import { Config } from '@backstage/config'; import { NotFoundError } from '../errors'; import { ReaderFactory, UrlReader } from './types'; @@ -77,7 +77,7 @@ export class GitlabUrlReader implements UrlReader { } if (response.ok) { - return response.buffer(); + return Buffer.from(await response.text()); } const message = `${url} could not be read as ${builtUrl}, ${response.status} ${response.statusText}`; From f36e1e9fe772bcfdfbe55af9bd8f53f60c8f8483 Mon Sep 17 00:00:00 2001 From: blam Date: Fri, 9 Oct 2020 14:14:53 +0200 Subject: [PATCH 26/40] chore: remove node-fetch from the project --- packages/backend-common/package.json | 1 - .../cli/templates/default-backend-plugin/package.json.hbs | 5 ++--- packages/core-api/package.json | 3 +-- packages/core-api/src/setupTests.ts | 2 -- packages/core/package.json | 3 +-- packages/core/src/setupTests.ts | 2 -- packages/e2e-test/package.json | 2 +- packages/e2e-test/src/e2e-test.ts | 2 +- plugins/catalog/package.json | 1 - plugins/proxy-backend/package.json | 2 -- plugins/techdocs-backend/package.json | 1 + plugins/techdocs-backend/src/default-branch.ts | 2 +- plugins/techdocs-backend/src/service/metadata.ts | 3 ++- plugins/techdocs-backend/src/service/router.ts | 2 +- yarn.lock | 2 +- 15 files changed, 12 insertions(+), 21 deletions(-) diff --git a/packages/backend-common/package.json b/packages/backend-common/package.json index eb74546f23..ad2af992bd 100644 --- a/packages/backend-common/package.json +++ b/packages/backend-common/package.json @@ -65,7 +65,6 @@ "@types/compression": "^1.7.0", "@types/http-errors": "^1.6.3", "@types/morgan": "^1.9.0", - "@types/node-fetch": "^2.5.7", "@types/stoppable": "^1.1.0", "@types/supertest": "^2.0.8", "@types/webpack-env": "^1.15.2", diff --git a/packages/cli/templates/default-backend-plugin/package.json.hbs b/packages/cli/templates/default-backend-plugin/package.json.hbs index c9c8488721..96ceb9784d 100644 --- a/packages/cli/templates/default-backend-plugin/package.json.hbs +++ b/packages/cli/templates/default-backend-plugin/package.json.hbs @@ -29,15 +29,14 @@ "express": "^4.17.1", "express-promise-router": "^3.0.3", "winston": "^3.2.1", - "node-fetch": "^2.6.1", + "cross-fetch": "^3.0.6", "yn": "^4.0.0" }, "devDependencies": { "@backstage/cli": "^{{version}}", "@types/supertest": "^2.0.8", "supertest": "^4.0.2", - "msw": "^0.21.2", - "cross-fetch": "^3.0.6" + "msw": "^0.21.2" }, "files": [ "dist" diff --git a/packages/core-api/package.json b/packages/core-api/package.json index c925471695..d6dd492906 100644 --- a/packages/core-api/package.json +++ b/packages/core-api/package.json @@ -48,8 +48,7 @@ "@testing-library/user-event": "^12.0.7", "@types/jest": "^26.0.7", "@types/node": "^12.0.0", - "@types/zen-observable": "^0.8.0", - "jest-fetch-mock": "^3.0.3" + "@types/zen-observable": "^0.8.0" }, "files": [ "dist" diff --git a/packages/core-api/src/setupTests.ts b/packages/core-api/src/setupTests.ts index 8553642152..825bcd4115 100644 --- a/packages/core-api/src/setupTests.ts +++ b/packages/core-api/src/setupTests.ts @@ -15,5 +15,3 @@ */ import '@testing-library/jest-dom'; - -require('jest-fetch-mock').enableMocks(); diff --git a/packages/core/package.json b/packages/core/package.json index 0a0dc7576c..f125c9d67e 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -64,8 +64,7 @@ "@types/jest": "^26.0.7", "@types/node": "^12.0.0", "@types/react-helmet": "^6.1.0", - "@types/zen-observable": "^0.8.0", - "jest-fetch-mock": "^3.0.3" + "@types/zen-observable": "^0.8.0" }, "files": [ "dist" diff --git a/packages/core/src/setupTests.ts b/packages/core/src/setupTests.ts index 8553642152..825bcd4115 100644 --- a/packages/core/src/setupTests.ts +++ b/packages/core/src/setupTests.ts @@ -15,5 +15,3 @@ */ import '@testing-library/jest-dom'; - -require('jest-fetch-mock').enableMocks(); diff --git a/packages/e2e-test/package.json b/packages/e2e-test/package.json index 8dcfd98ab5..6f8a952547 100644 --- a/packages/e2e-test/package.json +++ b/packages/e2e-test/package.json @@ -26,7 +26,7 @@ "@types/node": "^13.7.2", "fs-extra": "^9.0.0", "handlebars": "^4.7.3", - "node-fetch": "^2.6.0", + "cross-fetch": "^3.0.6", "pgtools": "^0.3.0", "tree-kill": "^1.2.2", "ts-node": "^8.6.2", diff --git a/packages/e2e-test/src/e2e-test.ts b/packages/e2e-test/src/e2e-test.ts index c7f6137ff1..d1529d3af2 100644 --- a/packages/e2e-test/src/e2e-test.ts +++ b/packages/e2e-test/src/e2e-test.ts @@ -16,7 +16,7 @@ import os from 'os'; import fs from 'fs-extra'; -import fetch from 'node-fetch'; +import fetch from 'cross-fetch'; import handlebars from 'handlebars'; import killTree from 'tree-kill'; import { resolve as resolvePath, join as joinPath } from 'path'; diff --git a/plugins/catalog/package.json b/plugins/catalog/package.json index b57136b7db..23eeb7c8a1 100644 --- a/plugins/catalog/package.json +++ b/plugins/catalog/package.json @@ -51,7 +51,6 @@ "@types/jest": "^26.0.7", "@types/node": "^12.0.0", "msw": "^0.21.2", - "node-fetch": "^2.6.1", "react-test-renderer": "^16.13.1", "cross-fetch": "^3.0.6" }, diff --git a/plugins/proxy-backend/package.json b/plugins/proxy-backend/package.json index 0e6b8a3458..248c3a4014 100644 --- a/plugins/proxy-backend/package.json +++ b/plugins/proxy-backend/package.json @@ -35,8 +35,6 @@ }, "devDependencies": { "@backstage/cli": "^0.1.1-alpha.24", - "@types/node-fetch": "^2.5.7", - "@types/supertest": "^2.0.8", "@types/uuid": "^8.0.0", "@types/yup": "^0.28.2", "supertest": "^4.0.2" diff --git a/plugins/techdocs-backend/package.json b/plugins/techdocs-backend/package.json index de50bea910..ed2b952f16 100644 --- a/plugins/techdocs-backend/package.json +++ b/plugins/techdocs-backend/package.json @@ -34,6 +34,7 @@ "git-url-parse": "^11.2.0", "knex": "^0.21.1", "nodegit": "^0.27.0", + "cross-fetch": "^3.0.6", "winston": "^3.2.1" }, "devDependencies": { diff --git a/plugins/techdocs-backend/src/default-branch.ts b/plugins/techdocs-backend/src/default-branch.ts index 05a8f666ce..bbf40c17fc 100644 --- a/plugins/techdocs-backend/src/default-branch.ts +++ b/plugins/techdocs-backend/src/default-branch.ts @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import fetch, { RequestInit } from 'node-fetch'; +import fetch from 'cross-fetch'; import parseGitUrl from 'git-url-parse'; import { ConfigReader, Config } from '@backstage/config'; import { loadBackendConfig } from '@backstage/backend-common'; diff --git a/plugins/techdocs-backend/src/service/metadata.ts b/plugins/techdocs-backend/src/service/metadata.ts index 671fcdda17..760180f8d2 100644 --- a/plugins/techdocs-backend/src/service/metadata.ts +++ b/plugins/techdocs-backend/src/service/metadata.ts @@ -1,4 +1,3 @@ -import fetch from 'node-fetch'; /* * Copyright 2020 Spotify AB * @@ -15,6 +14,8 @@ import fetch from 'node-fetch'; * limitations under the License. */ +import fetch from 'cross-fetch'; + export class TechDocsMetadata { private async getMetadataFile(docsUrl: String) { const metadataURL = `${docsUrl}/techdocs_metadata.json`; diff --git a/plugins/techdocs-backend/src/service/router.ts b/plugins/techdocs-backend/src/service/router.ts index 365534b9d0..ca0dbd45b4 100644 --- a/plugins/techdocs-backend/src/service/router.ts +++ b/plugins/techdocs-backend/src/service/router.ts @@ -17,7 +17,7 @@ import { Logger } from 'winston'; import Router from 'express-promise-router'; import express from 'express'; import Knex from 'knex'; -import fetch from 'node-fetch'; +import fetch from 'cross-fetch'; import { Config } from '@backstage/config'; import Docker from 'dockerode'; import { diff --git a/yarn.lock b/yarn.lock index 9afd4e6e4f..0f81798230 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5180,7 +5180,7 @@ dependencies: "@types/node" "*" -"@types/node-fetch@2.5.7", "@types/node-fetch@^2.5.4", "@types/node-fetch@^2.5.7": +"@types/node-fetch@2.5.7", "@types/node-fetch@^2.5.4": version "2.5.7" resolved "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.5.7.tgz#20a2afffa882ab04d44ca786449a276f9f6bbf3c" integrity sha512-o2WVNf5UhWRkxlf6eq+jMZDu7kjgpgJfl4xVNlvryc95O/6F2ld8ztKX+qu+Rjyet93WAWm5LjeX9H5FGkODvw== From 3857bd85de11b7215b122c665212bc29b77f91ac Mon Sep 17 00:00:00 2001 From: blam Date: Tue, 13 Oct 2020 04:03:16 +0200 Subject: [PATCH 27/40] chore(auth-backend): fixing dep order --- plugins/auth-backend/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/auth-backend/package.json b/plugins/auth-backend/package.json index bace524383..25129f33f7 100644 --- a/plugins/auth-backend/package.json +++ b/plugins/auth-backend/package.json @@ -47,6 +47,7 @@ "passport-saml": "^1.3.3", "uuid": "^8.0.0", "winston": "^3.2.1", + "cross-fetch": "^3.0.6", "yn": "^4.0.0" }, "devDependencies": { @@ -59,8 +60,7 @@ "@types/passport-google-oauth20": "^2.0.3", "@types/passport-microsoft": "^0.0.0", "@types/passport-saml": "^1.1.2", - "msw": "^0.21.2", - "cross-fetch": "^3.0.6" + "msw": "^0.21.2" }, "files": [ "dist", From d694fd5feef0439bfa723036659082ca41e486d4 Mon Sep 17 00:00:00 2001 From: blam Date: Tue, 13 Oct 2020 13:49:30 +0200 Subject: [PATCH 28/40] chore(lighthouse): need to rewrite some of these tests to remove the jest-fetch-mock dependency --- .../src/components/ProfileCatalog/ProfileCatalog.test.tsx | 2 -- .../src/components/AuditList/AuditListForEntity.test.tsx | 3 +-- .../src/components/AuditList/AuditListTable.test.tsx | 8 +++++--- .../lighthouse/src/components/AuditList/index.test.tsx | 7 +++---- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/plugins/gitops-profiles/src/components/ProfileCatalog/ProfileCatalog.test.tsx b/plugins/gitops-profiles/src/components/ProfileCatalog/ProfileCatalog.test.tsx index 06074ff84d..f01ac70e64 100644 --- a/plugins/gitops-profiles/src/components/ProfileCatalog/ProfileCatalog.test.tsx +++ b/plugins/gitops-profiles/src/components/ProfileCatalog/ProfileCatalog.test.tsx @@ -16,7 +16,6 @@ import React from 'react'; import { render } from '@testing-library/react'; -import mockFetch from 'jest-fetch-mock'; import ProfileCatalog from './ProfileCatalog'; import { ThemeProvider } from '@material-ui/core'; import { lightTheme } from '@backstage/theme'; @@ -45,7 +44,6 @@ describe('ProfileCatalog', () => { }), ], ]); - mockFetch.mockResponse(() => new Promise(() => {})); const rendered = render( diff --git a/plugins/lighthouse/src/components/AuditList/AuditListForEntity.test.tsx b/plugins/lighthouse/src/components/AuditList/AuditListForEntity.test.tsx index 7f10914d9c..15a4ba3255 100644 --- a/plugins/lighthouse/src/components/AuditList/AuditListForEntity.test.tsx +++ b/plugins/lighthouse/src/components/AuditList/AuditListForEntity.test.tsx @@ -22,7 +22,6 @@ import { LighthouseRestApi, WebsiteListResponse, } from '../../api'; -import mockFetch from 'jest-fetch-mock'; import * as data from '../../__fixtures__/website-list-response.json'; import { EntityContext } from '@backstage/plugin-catalog'; @@ -53,7 +52,7 @@ describe('', () => { [lighthouseApiRef, new LighthouseRestApi('http://lighthouse')], [errorApiRef, mockErrorApi], ]); - mockFetch.mockResponse(JSON.stringify(entityWebsite)); + (useWebsiteForEntity as jest.Mock).mockReturnValue({ value: entityWebsite, loading: false, diff --git a/plugins/lighthouse/src/components/AuditList/AuditListTable.test.tsx b/plugins/lighthouse/src/components/AuditList/AuditListTable.test.tsx index e67f939ba1..5c67fec10a 100644 --- a/plugins/lighthouse/src/components/AuditList/AuditListTable.test.tsx +++ b/plugins/lighthouse/src/components/AuditList/AuditListTable.test.tsx @@ -16,7 +16,7 @@ import React from 'react'; import { render } from '@testing-library/react'; -import { wrapInTestApp } from '@backstage/test-utils'; +import { wrapInTestApp, msw } from '@backstage/test-utils'; import { ApiRegistry, ApiProvider } from '@backstage/core'; import AuditListTable from './AuditListTable'; @@ -26,7 +26,7 @@ import { LighthouseRestApi, } from '../../api'; import { formatTime } from '../../utils'; -import mockFetch from 'jest-fetch-mock'; +import { setupServer } from 'msw/node'; import * as data from '../../__fixtures__/website-list-response.json'; @@ -35,11 +35,13 @@ const websiteListResponse = data as WebsiteListResponse; describe('AuditListTable', () => { let apis: ApiRegistry; + const server = setupServer(); + msw.setupDefaultHandlers(server); + beforeEach(() => { apis = ApiRegistry.from([ [lighthouseApiRef, new LighthouseRestApi('http://lighthouse')], ]); - mockFetch.mockResponse(JSON.stringify(websiteListResponse)); }); const auditList = (websiteList: WebsiteListResponse) => { diff --git a/plugins/lighthouse/src/components/AuditList/index.test.tsx b/plugins/lighthouse/src/components/AuditList/index.test.tsx index 34fd760801..bc75cc5d98 100644 --- a/plugins/lighthouse/src/components/AuditList/index.test.tsx +++ b/plugins/lighthouse/src/components/AuditList/index.test.tsx @@ -24,7 +24,6 @@ jest.mock('react-router-dom', () => { }); import React from 'react'; -import mockFetch from 'jest-fetch-mock'; import { render, fireEvent } from '@testing-library/react'; import { ApiRegistry, ApiProvider } from '@backstage/core'; import { wrapInTestApp } from '@backstage/test-utils'; @@ -48,7 +47,6 @@ describe('AuditList', () => { apis = ApiRegistry.from([ [lighthouseApiRef, new LighthouseRestApi('http://lighthouse')], ]); - mockFetch.mockResponse(JSON.stringify(websiteListResponse)); }); it('should render the table', async () => { @@ -74,10 +72,10 @@ describe('AuditList', () => { const button = await rendered.findByText('Create Audit'); expect(button).toBeInTheDocument(); }); - + /* need to rewrite these tests */ + /* describe('pagination', () => { it('requests the correct limit and offset from the api based on the query', () => { - mockFetch.mockClear(); render( wrapInTestApp( @@ -173,4 +171,5 @@ describe('AuditList', () => { expect(element).toBeInTheDocument(); }); }); + */ }); From 23eaaa7019ef0292c15be20d9bc7471947d934f1 Mon Sep 17 00:00:00 2001 From: blam Date: Mon, 19 Oct 2020 23:58:07 +0200 Subject: [PATCH 29/40] chore: remove superfluous file --- plugins/linkerd-backend/src/service/helpers.ts | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 plugins/linkerd-backend/src/service/helpers.ts diff --git a/plugins/linkerd-backend/src/service/helpers.ts b/plugins/linkerd-backend/src/service/helpers.ts deleted file mode 100644 index e69de29bb2..0000000000 From a8d7e4cfe36a64f27d3957e859ca244c176ef370 Mon Sep 17 00:00:00 2001 From: blam Date: Tue, 20 Oct 2020 00:59:50 +0200 Subject: [PATCH 30/40] chore: fixing remaining tests and merge conflicts --- packages/test-utils/package.json | 1 + .../test-utils/src/testUtils/msw/index.ts | 7 ++- .../src/components/AuditList/index.test.tsx | 38 +++++++-------- .../src/components/AuditView/index.test.tsx | 48 ++++++++----------- .../src/components/CreateAudit/index.test.tsx | 38 ++++++++------- plugins/lighthouse/src/setupTests.ts | 1 + yarn.lock | 33 +++++++------ 7 files changed, 83 insertions(+), 83 deletions(-) diff --git a/packages/test-utils/package.json b/packages/test-utils/package.json index 1b7d35a197..2a290802d3 100644 --- a/packages/test-utils/package.json +++ b/packages/test-utils/package.json @@ -38,6 +38,7 @@ "@testing-library/react": "^10.4.1", "@testing-library/user-event": "^12.0.7", "@types/react": "^16.9", + "msw": "^0.21.3", "react": "^16.12.0", "react-dom": "^16.12.0", "react-router": "6.0.0-beta.0", diff --git a/packages/test-utils/src/testUtils/msw/index.ts b/packages/test-utils/src/testUtils/msw/index.ts index 5bae182cb1..0deaac0986 100644 --- a/packages/test-utils/src/testUtils/msw/index.ts +++ b/packages/test-utils/src/testUtils/msw/index.ts @@ -13,8 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + export const msw = { - setupDefaultHandlers: (worker: any) => { + setupDefaultHandlers: (worker: { + listen: (t: any) => void; + close: () => void; + resetHandlers: () => void; + }) => { beforeAll(() => worker.listen({ onUnhandledRequest: 'error' })); afterAll(() => worker.close()); afterEach(() => worker.resetHandlers()); diff --git a/plugins/lighthouse/src/components/AuditList/index.test.tsx b/plugins/lighthouse/src/components/AuditList/index.test.tsx index bc75cc5d98..5fdc4781ce 100644 --- a/plugins/lighthouse/src/components/AuditList/index.test.tsx +++ b/plugins/lighthouse/src/components/AuditList/index.test.tsx @@ -26,7 +26,7 @@ jest.mock('react-router-dom', () => { import React from 'react'; import { render, fireEvent } from '@testing-library/react'; import { ApiRegistry, ApiProvider } from '@backstage/core'; -import { wrapInTestApp } from '@backstage/test-utils'; +import { wrapInTestApp, msw } from '@backstage/test-utils'; import { lighthouseApiRef, @@ -39,10 +39,15 @@ import * as data from '../../__fixtures__/website-list-response.json'; const { useNavigate } = jest.requireMock('react-router-dom'); const websiteListResponse = data as WebsiteListResponse; +import { rest } from 'msw'; +import { setupServer } from 'msw/node'; describe('AuditList', () => { let apis: ApiRegistry; + const server = setupServer(); + msw.setupDefaultHandlers(server); + beforeEach(() => { apis = ApiRegistry.from([ [lighthouseApiRef, new LighthouseRestApi('http://lighthouse')], @@ -50,6 +55,7 @@ describe('AuditList', () => { }); it('should render the table', async () => { + server.use(rest.get('*', (_req, res, ctx) => res(ctx.json(data)))); const rendered = render( wrapInTestApp( @@ -72,24 +78,8 @@ describe('AuditList', () => { const button = await rendered.findByText('Create Audit'); expect(button).toBeInTheDocument(); }); - /* need to rewrite these tests */ - /* - describe('pagination', () => { - it('requests the correct limit and offset from the api based on the query', () => { - render( - wrapInTestApp( - - - , - { routeEntries: ['?page=2'] }, - ), - ); - expect(mockFetch).toHaveBeenLastCalledWith( - 'http://lighthouse/v1/websites?limit=10&offset=10', - undefined, - ); - }); + describe('pagination', () => { describe('when only one page is needed', () => { it('hides pagination elements', () => { const rendered = render( @@ -109,7 +99,8 @@ describe('AuditList', () => { response.limit = 5; response.offset = 5; response.total = 7; - mockFetch.mockResponseOnce(JSON.stringify(response)); + server.use(rest.get('*', (_req, res, ctx) => res(ctx.json(response)))); + server.use(rest.post('*', (_req, res, ctx) => res(ctx.json(response)))); }); it('shows pagination elements', async () => { @@ -144,7 +135,7 @@ describe('AuditList', () => { describe('when waiting on the request', () => { it('should render the loader', async () => { - mockFetch.mockResponseOnce(() => new Promise(() => {})); + server.use(rest.get('*', (_req, res, ctx) => res(ctx.delay(20000)))); const rendered = render( wrapInTestApp( @@ -159,7 +150,11 @@ describe('AuditList', () => { describe('when the audits fail', () => { it('should render an error', async () => { - mockFetch.mockRejectOnce(new Error('failed to fetch')); + server.use( + rest.get('*', (_req, res, ctx) => + res(ctx.status(500, 'something broke')), + ), + ); const rendered = render( wrapInTestApp( @@ -171,5 +166,4 @@ describe('AuditList', () => { expect(element).toBeInTheDocument(); }); }); - */ }); diff --git a/plugins/lighthouse/src/components/AuditView/index.test.tsx b/plugins/lighthouse/src/components/AuditView/index.test.tsx index ca292a133d..8bfa8ce073 100644 --- a/plugins/lighthouse/src/components/AuditView/index.test.tsx +++ b/plugins/lighthouse/src/components/AuditView/index.test.tsx @@ -27,17 +27,18 @@ jest.mock('react-router-dom', () => { }); import React from 'react'; -import mockFetch from 'jest-fetch-mock'; import { render, fireEvent } from '@testing-library/react'; -import { wrapInTestApp } from '@backstage/test-utils'; +import { wrapInTestApp, msw } from '@backstage/test-utils'; import { ApiRegistry, ApiProvider } from '@backstage/core'; - import AuditView from '.'; import { lighthouseApiRef, LighthouseRestApi, Audit, Website } from '../../api'; import { formatTime } from '../../utils'; import * as data from '../../__fixtures__/website-response.json'; import { act } from 'react-dom/test-utils'; +import { setupServer } from 'msw/node'; +import { rest } from 'msw'; + const { useParams }: { useParams: jest.Mock } = jest.requireMock( 'react-router-dom', ); @@ -48,8 +49,16 @@ describe('AuditView', () => { let apis: ApiRegistry; let id: string; + const server = setupServer(); + msw.setupDefaultHandlers(server); + beforeEach(() => { - mockFetch.mockResponse(JSON.stringify(websiteResponse)); + server.use( + rest.get('https://lighthouse/*', async (_req, res, ctx) => + res(ctx.json(websiteResponse)), + ), + ); + apis = ApiRegistry.from([ [lighthouseApiRef, new LighthouseRestApi('https://lighthouse')], ]); @@ -74,27 +83,6 @@ describe('AuditView', () => { expect(iframe).toHaveAttribute('src', `https://lighthouse/v1/audits/${id}`); }); - it('renders a button to click to create a new audit for this website', async () => { - const rendered = render( - wrapInTestApp( - - - , - ), - ); - - const button = await rendered.findByText('Create New Audit'); - expect(button).toBeInTheDocument(); - - act(() => { - fireEvent.click(button); - }); - - expect(useNavigate()).toHaveBeenCalledWith( - `../../create-audit?url=${encodeURIComponent('https://spotify.com')}`, - ); - }); - describe('sidebar', () => { it('renders a list of all audits for the website', async () => { const rendered = render( @@ -164,7 +152,7 @@ describe('AuditView', () => { describe('when the request for the website by id is pending', () => { it('shows the loading', async () => { - mockFetch.mockImplementationOnce(() => new Promise(() => {})); + server.use(rest.get('*', (_req, res, ctx) => res(ctx.delay(20000)))); const rendered = render( wrapInTestApp( @@ -178,7 +166,11 @@ describe('AuditView', () => { describe('when the request for the website by id fails', () => { it('shows an error', async () => { - mockFetch.mockRejectOnce(new Error('failed to fetch')); + server.use( + rest.get('*', (_req, res, ctx) => + res(ctx.status(500), ctx.body('failed to fetch')), + ), + ); const rendered = render( wrapInTestApp( @@ -186,7 +178,7 @@ describe('AuditView', () => { , ), ); - expect(await rendered.findByText('failed to fetch')).toBeInTheDocument(); + expect(await rendered.findByText(/failed to fetch/)).toBeInTheDocument(); }); }); diff --git a/plugins/lighthouse/src/components/CreateAudit/index.test.tsx b/plugins/lighthouse/src/components/CreateAudit/index.test.tsx index b2348bf5ff..96829926b5 100644 --- a/plugins/lighthouse/src/components/CreateAudit/index.test.tsx +++ b/plugins/lighthouse/src/components/CreateAudit/index.test.tsx @@ -24,20 +24,22 @@ jest.mock('react-router-dom', () => { }); import React from 'react'; -import mockFetch from 'jest-fetch-mock'; -import { wait, render, fireEvent } from '@testing-library/react'; +import { waitFor, render, fireEvent } from '@testing-library/react'; import { ApiRegistry, ApiProvider, ErrorApi, errorApiRef, } from '@backstage/core'; -import { wrapInTestApp } from '@backstage/test-utils'; +import { wrapInTestApp, msw } from '@backstage/test-utils'; import { lighthouseApiRef, LighthouseRestApi, Audit } from '../../api'; import CreateAudit from '.'; import * as data from '../../__fixtures__/create-audit-response.json'; +import { setupServer } from 'msw/node'; +import { rest } from 'msw'; + const { useNavigate }: { useNavigate: jest.Mock } = jest.requireMock( 'react-router-dom', ); @@ -47,6 +49,8 @@ const createAuditResponse = data as Audit; describe('CreateAudit', () => { let apis: ApiRegistry; let errorApi: ErrorApi; + const server = setupServer(); + msw.setupDefaultHandlers(server); beforeEach(() => { errorApi = { post: jest.fn(), error$: jest.fn() }; @@ -88,7 +92,7 @@ describe('CreateAudit', () => { describe('when waiting on the request', () => { it('disables the form fields', () => { - mockFetch.mockResponseOnce(() => new Promise(() => {})); + server.use(rest.get('*', (_req, res, ctx) => res(ctx.delay(20000)))); const rendered = render( wrapInTestApp( @@ -111,7 +115,11 @@ describe('CreateAudit', () => { describe('when the audit is successfully created', () => { it('triggers a location change to the table', async () => { useNavigate.mockClear(); - mockFetch.mockResponseOnce(JSON.stringify(createAuditResponse)); + server.use( + rest.post('http://lighthouse/v1/audits', (_req, res, ctx) => + res(ctx.json(createAuditResponse)), + ), + ); const rendered = render( wrapInTestApp( @@ -126,14 +134,7 @@ describe('CreateAudit', () => { }); fireEvent.click(rendered.getByText(/Create Audit/)); - expect(mockFetch).toHaveBeenCalledWith( - 'http://lighthouse/v1/audits', - expect.objectContaining({ - method: 'POST', - }), - ); - - await wait(() => expect(rendered.getByLabelText(/URL/)).toBeEnabled()); + await waitFor(() => expect(rendered.getByLabelText(/URL/)).toBeEnabled()); expect(useNavigate()).toHaveBeenCalledWith('..'); }); @@ -141,9 +142,11 @@ describe('CreateAudit', () => { describe('when the audits fail', () => { it('should render an error', async () => { - (errorApi.post as jest.Mock).mockClear(); - mockFetch.mockRejectOnce(new Error('failed to post')); - + server.use( + rest.post('http://lighthouse/v1/audits', (_req, res, ctx) => + res(ctx.status(500, 'failed to post')), + ), + ); const rendered = render( wrapInTestApp( @@ -157,8 +160,7 @@ describe('CreateAudit', () => { }); fireEvent.click(rendered.getByText(/Create Audit/)); - await wait(() => expect(rendered.getByLabelText(/URL/)).toBeEnabled()); - await new Promise(r => setTimeout(r, 0)); + await waitFor(() => expect(rendered.getByLabelText(/URL/)).toBeEnabled()); expect(errorApi.post).toHaveBeenCalledWith(expect.any(Error)); }); diff --git a/plugins/lighthouse/src/setupTests.ts b/plugins/lighthouse/src/setupTests.ts index 825bcd4115..aea2220869 100644 --- a/plugins/lighthouse/src/setupTests.ts +++ b/plugins/lighthouse/src/setupTests.ts @@ -15,3 +15,4 @@ */ import '@testing-library/jest-dom'; +import 'cross-fetch/polyfill'; diff --git a/yarn.lock b/yarn.lock index 6e48747b66..9f1bfaa3b7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9061,7 +9061,7 @@ cross-env@^7.0.0: dependencies: cross-spawn "^7.0.1" -cross-fetch@3.0.6, cross-fetch@^3.0.4, cross-fetch@^3.0.5, cross-fetch@^3.0.6: +cross-fetch@3.0.6, cross-fetch@^3.0.5, cross-fetch@^3.0.6: version "3.0.6" resolved "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.0.6.tgz#3a4040bc8941e653e0e9cf17f29ebcd177d3365c" integrity sha512-KBPUbqgFjzWlVcURG+Svp9TlhA5uliYtiNx/0r8nv0pdypeQCRJ9IaSIc3q/x3q8t3F75cHuwxVql1HFGHCNJQ== @@ -14229,14 +14229,6 @@ jest-esm-transformer@^1.0.0: "@babel/core" "^7.4.4" "@babel/plugin-transform-modules-commonjs" "^7.4.4" -jest-fetch-mock@^3.0.3: - version "3.0.3" - resolved "https://registry.npmjs.org/jest-fetch-mock/-/jest-fetch-mock-3.0.3.tgz#31749c456ae27b8919d69824f1c2bd85fe0a1f3b" - integrity sha512-Ux1nWprtLrdrH4XwE7O7InRY6psIi3GOsqNESJgMJ+M5cv4A8Lh7SN9d2V2kKRZ8ebAfcd1LNyZguAOb6JiDqw== - dependencies: - cross-fetch "^3.0.4" - promise-polyfill "^8.1.3" - jest-get-type@^25.2.6: version "25.2.6" resolved "https://registry.npmjs.org/jest-get-type/-/jest-get-type-25.2.6.tgz#0b0a32fab8908b44d508be81681487dbabb8d877" @@ -16399,6 +16391,24 @@ msw@^0.21.2: statuses "^2.0.0" yargs "^16.0.3" +msw@^0.21.3: + version "0.21.3" + resolved "https://registry.npmjs.org/msw/-/msw-0.21.3.tgz#d073842f9570a08f4041806a2c7303a9b8494602" + integrity sha512-voPc/EJsjarvi454vSEuozZQQqLG4AUHT6qQL5Ah47lq7sGCpc7icByeUlfvEj5+MvaugN0c7JwXyCa2rxu8cA== + dependencies: + "@open-draft/until" "^1.0.3" + "@types/cookie" "^0.4.0" + chalk "^4.1.0" + chokidar "^3.4.2" + cookie "^0.4.1" + graphql "^15.3.0" + headers-utils "^1.2.0" + node-fetch "^2.6.1" + node-match-path "^0.4.4" + node-request-interceptor "^0.5.1" + statuses "^2.0.0" + yargs "^16.0.3" + multicast-dns-service-types@^1.1.0: version "1.1.0" resolved "https://registry.npmjs.org/multicast-dns-service-types/-/multicast-dns-service-types-1.1.0.tgz#899f11d9686e5e05cb91b35d5f0e63b773cfc901" @@ -18692,11 +18702,6 @@ promise-inflight@^1.0.1: resolved "https://registry.npmjs.org/promise-inflight/-/promise-inflight-1.0.1.tgz#98472870bf228132fcbdd868129bad12c3c029e3" integrity sha1-mEcocL8igTL8vdhoEputEsPAKeM= -promise-polyfill@^8.1.3: - version "8.1.3" - resolved "https://registry.npmjs.org/promise-polyfill/-/promise-polyfill-8.1.3.tgz#8c99b3cf53f3a91c68226ffde7bde81d7f904116" - integrity sha512-MG5r82wBzh7pSKDRa9y+vllNHz3e3d4CNj1PQE4BQYxLme0gKYYBm9YENq+UkEikyZ0XbiGWxYlVw3Rl9O/U8g== - promise-retry@^1.1.1: version "1.1.1" resolved "https://registry.npmjs.org/promise-retry/-/promise-retry-1.1.1.tgz#6739e968e3051da20ce6497fb2b50f6911df3d6d" From 2ef3e1f1619e6689a74b3ab7fafeb43a35a3f197 Mon Sep 17 00:00:00 2001 From: blam Date: Tue, 20 Oct 2020 09:51:32 +0200 Subject: [PATCH 31/40] chore: fixing linting --- plugins/lighthouse/src/components/AuditView/index.test.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/plugins/lighthouse/src/components/AuditView/index.test.tsx b/plugins/lighthouse/src/components/AuditView/index.test.tsx index 8bfa8ce073..df223150bc 100644 --- a/plugins/lighthouse/src/components/AuditView/index.test.tsx +++ b/plugins/lighthouse/src/components/AuditView/index.test.tsx @@ -27,14 +27,13 @@ jest.mock('react-router-dom', () => { }); import React from 'react'; -import { render, fireEvent } from '@testing-library/react'; +import { render } from '@testing-library/react'; import { wrapInTestApp, msw } from '@backstage/test-utils'; import { ApiRegistry, ApiProvider } from '@backstage/core'; import AuditView from '.'; import { lighthouseApiRef, LighthouseRestApi, Audit, Website } from '../../api'; import { formatTime } from '../../utils'; import * as data from '../../__fixtures__/website-response.json'; -import { act } from 'react-dom/test-utils'; import { setupServer } from 'msw/node'; import { rest } from 'msw'; @@ -43,7 +42,6 @@ const { useParams }: { useParams: jest.Mock } = jest.requireMock( 'react-router-dom', ); const websiteResponse = data as Website; -const { useNavigate } = jest.requireMock('react-router-dom'); describe('AuditView', () => { let apis: ApiRegistry; From 0f76b11669fe3bb0218c1e599868dd4cd08c4b1a Mon Sep 17 00:00:00 2001 From: blam Date: Tue, 20 Oct 2020 10:17:31 +0200 Subject: [PATCH 32/40] chore: fixing typescript issues with using the new fetch --- plugins/sentry/package.json | 5 +++-- .../SentryPluginPage/SentryPluginPage.test.tsx | 10 ++++++++-- plugins/techdocs-backend/src/service/router.ts | 4 +++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/plugins/sentry/package.json b/plugins/sentry/package.json index b06a165215..0060777491 100644 --- a/plugins/sentry/package.json +++ b/plugins/sentry/package.json @@ -38,13 +38,14 @@ "devDependencies": { "@backstage/cli": "^0.1.1-alpha.25", "@backstage/dev-utils": "^0.1.1-alpha.25", + "@backstage/test-utils": "^0.1.1-alpha.25", "@testing-library/jest-dom": "^5.10.1", "@testing-library/react": "^10.4.1", "@testing-library/user-event": "^12.0.7", "@types/jest": "^26.0.7", "@types/node": "^12.0.0", - "msw": "^0.21.2", - "cross-fetch": "^3.0.6" + "cross-fetch": "^3.0.6", + "msw": "^0.21.2" }, "files": [ "dist" diff --git a/plugins/sentry/src/components/SentryPluginPage/SentryPluginPage.test.tsx b/plugins/sentry/src/components/SentryPluginPage/SentryPluginPage.test.tsx index d508ddf7c2..21c21ce385 100644 --- a/plugins/sentry/src/components/SentryPluginPage/SentryPluginPage.test.tsx +++ b/plugins/sentry/src/components/SentryPluginPage/SentryPluginPage.test.tsx @@ -16,10 +16,13 @@ import React from 'react'; import { render } from '@testing-library/react'; -import mockFetch from 'jest-fetch-mock'; import SentryPluginPage from './SentryPluginPage'; import { ThemeProvider } from '@material-ui/core'; import { lightTheme } from '@backstage/theme'; +import { msw } from '@backstage/test-utils'; +import { setupServer } from 'msw/node'; +import { rest } from 'msw'; + import { ApiProvider, ApiRegistry, @@ -31,8 +34,11 @@ const errorApi = { post: () => {} }; const ConfigApi = { getString: () => 'test' }; describe('SentryPluginPage', () => { + const server = setupServer(); + msw.setupDefaultHandlers(server); + it('should render header and time switched', () => { - mockFetch.mockResponse('{}'); + server.use(rest.get('/', (_req, res, ctx) => res(ctx.json({})))); const rendered = render( Date: Tue, 20 Oct 2020 10:36:30 +0200 Subject: [PATCH 33/40] chore: need to run install part of the package creation --- packages/cli/templates/default-plugin/package.json.hbs | 1 + packages/e2e-test/src/commands/run.ts | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/cli/templates/default-plugin/package.json.hbs b/packages/cli/templates/default-plugin/package.json.hbs index cf07851f31..41f942fb79 100644 --- a/packages/cli/templates/default-plugin/package.json.hbs +++ b/packages/cli/templates/default-plugin/package.json.hbs @@ -36,6 +36,7 @@ "devDependencies": { "@backstage/cli": "^{{backstageVersion}}", "@backstage/dev-utils": "^{{backstageVersion}}", + "@backstage/test-utils": "^{{backstageVersion}}", "@testing-library/jest-dom": "^5.10.1", "@testing-library/react": "^10.4.1", "@testing-library/user-event": "^12.0.7", diff --git a/packages/e2e-test/src/commands/run.ts b/packages/e2e-test/src/commands/run.ts index 905cb20d52..5f27176fa8 100644 --- a/packages/e2e-test/src/commands/run.ts +++ b/packages/e2e-test/src/commands/run.ts @@ -271,7 +271,12 @@ async function createPlugin( const pluginDir = resolvePath(appDir, 'plugins', canonicalName); - for (const cmd of [['tsc'], ['lint'], ['test', '--no-watch']]) { + for (const cmd of [ + ['install'], + ['tsc'], + ['lint'], + ['test', '--no-watch'], + ]) { print(`Running 'yarn ${cmd.join(' ')}' in newly created plugin`); await runPlain(['yarn', ...cmd], { cwd: pluginDir }); } From 193652e5a3049060b20557b8f4484d44f6c0f11a Mon Sep 17 00:00:00 2001 From: blam Date: Tue, 20 Oct 2020 10:53:47 +0200 Subject: [PATCH 34/40] chore: fixing some more e2e tests by actually polyfill the correct thing --- .../default-backend-plugin/src/setupTests.ts | 3 +-- .../ExampleComponent/ExampleComponent.test.tsx.hbs | 11 +++-------- .../ExampleFetchComponent.test.tsx.hbs | 13 ++++--------- .../cli/templates/default-plugin/src/setupTests.ts | 2 +- 4 files changed, 9 insertions(+), 20 deletions(-) diff --git a/packages/cli/templates/default-backend-plugin/src/setupTests.ts b/packages/cli/templates/default-backend-plugin/src/setupTests.ts index a5907fd52f..1c7ba6c7e1 100644 --- a/packages/cli/templates/default-backend-plugin/src/setupTests.ts +++ b/packages/cli/templates/default-backend-plugin/src/setupTests.ts @@ -13,6 +13,5 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - +import 'cross-fetch/polyfill'; export {}; -global.fetch = require('node-fetch'); diff --git a/packages/cli/templates/default-plugin/src/components/ExampleComponent/ExampleComponent.test.tsx.hbs b/packages/cli/templates/default-plugin/src/components/ExampleComponent/ExampleComponent.test.tsx.hbs index fdb39444d8..e805900f36 100644 --- a/packages/cli/templates/default-plugin/src/components/ExampleComponent/ExampleComponent.test.tsx.hbs +++ b/packages/cli/templates/default-plugin/src/components/ExampleComponent/ExampleComponent.test.tsx.hbs @@ -5,18 +5,13 @@ import { ThemeProvider } from '@material-ui/core'; import { lightTheme } from '@backstage/theme'; import { rest } from 'msw'; import { setupServer } from 'msw/node'; +import { msw } from '@backstage/test-utils'; describe('ExampleComponent', () => { const server = setupServer(); - // Enable API mocking before tests. - beforeAll(() => server.listen({ onUnhandledRequest: 'error' })) - - // Reset any runtime request handlers we may add during the tests. - afterEach(() => server.resetHandlers()) - - // Disable API mocking after the tests are done. - afterAll(() => server.close()) + // Enable sane handlers for network requests + msw.setupDefaultHandlers(server); // setup mock response beforeEach(() => { diff --git a/packages/cli/templates/default-plugin/src/components/ExampleFetchComponent/ExampleFetchComponent.test.tsx.hbs b/packages/cli/templates/default-plugin/src/components/ExampleFetchComponent/ExampleFetchComponent.test.tsx.hbs index ca1990b4bc..81e1b4be09 100644 --- a/packages/cli/templates/default-plugin/src/components/ExampleFetchComponent/ExampleFetchComponent.test.tsx.hbs +++ b/packages/cli/templates/default-plugin/src/components/ExampleFetchComponent/ExampleFetchComponent.test.tsx.hbs @@ -3,18 +3,13 @@ import { render } from '@testing-library/react'; import ExampleFetchComponent from './ExampleFetchComponent'; import { rest } from 'msw'; import { setupServer } from 'msw/node'; +import { msw } from '@backstage/test-utils'; describe('ExampleFetchComponent', () => { const server = setupServer(); - // Enable API mocking before tests. - beforeAll(() => server.listen({ onUnhandledRequest: 'error' })) - - // Reset any runtime request handlers we may add during the tests. - afterEach(() => server.resetHandlers()) - - // Disable API mocking after the tests are done. - afterAll(() => server.close()) - + // Enable sane handlers for network requests + msw.setupDefaultHandlers(server); + // setup mock response beforeEach(() => { server.use(rest.get('https://randomuser.me/*', (_, res, ctx) => res(ctx.status(200), ctx.delay(2000), ctx.json({})))) diff --git a/packages/cli/templates/default-plugin/src/setupTests.ts b/packages/cli/templates/default-plugin/src/setupTests.ts index ddc061ad7e..292b0cc471 100644 --- a/packages/cli/templates/default-plugin/src/setupTests.ts +++ b/packages/cli/templates/default-plugin/src/setupTests.ts @@ -1,2 +1,2 @@ import '@testing-library/jest-dom'; -import 'cross-fetch/register' +import 'cross-fetch/polyfill' From 37628a03f07a0de35c88f36309e5532c07d5a5ba Mon Sep 17 00:00:00 2001 From: blam Date: Tue, 20 Oct 2020 11:11:17 +0200 Subject: [PATCH 35/40] chore(cli): fixing isome more tests --- packages/core-api/package.json | 3 ++- packages/core-api/src/setupTests.ts | 1 + packages/e2e-test/src/commands/run.ts | 7 +------ 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/packages/core-api/package.json b/packages/core-api/package.json index de6a14bb2b..43e721683d 100644 --- a/packages/core-api/package.json +++ b/packages/core-api/package.json @@ -48,7 +48,8 @@ "@testing-library/user-event": "^12.0.7", "@types/jest": "^26.0.7", "@types/node": "^12.0.0", - "@types/zen-observable": "^0.8.0" + "@types/zen-observable": "^0.8.0", + "cross-fetch": "^3.0.6" }, "files": [ "dist" diff --git a/packages/core-api/src/setupTests.ts b/packages/core-api/src/setupTests.ts index 825bcd4115..aea2220869 100644 --- a/packages/core-api/src/setupTests.ts +++ b/packages/core-api/src/setupTests.ts @@ -15,3 +15,4 @@ */ import '@testing-library/jest-dom'; +import 'cross-fetch/polyfill'; diff --git a/packages/e2e-test/src/commands/run.ts b/packages/e2e-test/src/commands/run.ts index 5f27176fa8..905cb20d52 100644 --- a/packages/e2e-test/src/commands/run.ts +++ b/packages/e2e-test/src/commands/run.ts @@ -271,12 +271,7 @@ async function createPlugin( const pluginDir = resolvePath(appDir, 'plugins', canonicalName); - for (const cmd of [ - ['install'], - ['tsc'], - ['lint'], - ['test', '--no-watch'], - ]) { + for (const cmd of [['tsc'], ['lint'], ['test', '--no-watch']]) { print(`Running 'yarn ${cmd.join(' ')}' in newly created plugin`); await runPlain(['yarn', ...cmd], { cwd: pluginDir }); } From 3238651f8a7eac63574ec7ad38ce493c04182f8c Mon Sep 17 00:00:00 2001 From: blam Date: Tue, 20 Oct 2020 18:21:42 +0200 Subject: [PATCH 36/40] =?UTF-8?q?chore:=20maybe=20fixed=20the=20last=20of?= =?UTF-8?q?=20the=20broken=20tests=20=F0=9F=A4=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core-api/package.json | 4 ++- .../DefaultAuthConnector.test.ts | 35 ++++++++++++------- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/packages/core-api/package.json b/packages/core-api/package.json index 43e721683d..5b1456d1ba 100644 --- a/packages/core-api/package.json +++ b/packages/core-api/package.json @@ -30,6 +30,7 @@ }, "dependencies": { "@backstage/config": "^0.1.1-alpha.25", + "@backstage/test-utils": "^0.1.1-alpha.25", "@backstage/theme": "^0.1.1-alpha.25", "@material-ui/core": "^4.11.0", "@material-ui/icons": "^4.9.1", @@ -49,7 +50,8 @@ "@types/jest": "^26.0.7", "@types/node": "^12.0.0", "@types/zen-observable": "^0.8.0", - "cross-fetch": "^3.0.6" + "cross-fetch": "^3.0.6", + "msw": "^0.21.3" }, "files": [ "dist" diff --git a/packages/core-api/src/lib/AuthConnector/DefaultAuthConnector.test.ts b/packages/core-api/src/lib/AuthConnector/DefaultAuthConnector.test.ts index 5781130799..391b86952d 100644 --- a/packages/core-api/src/lib/AuthConnector/DefaultAuthConnector.test.ts +++ b/packages/core-api/src/lib/AuthConnector/DefaultAuthConnector.test.ts @@ -19,8 +19,9 @@ import { DefaultAuthConnector } from './DefaultAuthConnector'; import MockOAuthApi from '../../apis/implementations/OAuthRequestApi/MockOAuthApi'; import * as loginPopup from '../loginPopup'; import { UrlPatternDiscovery } from '../../apis'; - -const anyFetch = fetch as any; +import { msw } from '@backstage/test-utils'; +import { setupServer } from 'msw/node'; +import { rest } from 'msw'; const defaultOptions = { discoveryApi: UrlPatternDiscovery.compile('http://my-host/api/{{pluginId}}'), @@ -39,19 +40,25 @@ const defaultOptions = { }; describe('DefaultAuthConnector', () => { + const server = setupServer(); + msw.setupDefaultHandlers(server); + afterEach(() => { jest.resetAllMocks(); - anyFetch.resetMocks(); }); it('should refresh a session', async () => { - anyFetch.mockResponseOnce( - JSON.stringify({ - idToken: 'mock-id-token', - accessToken: 'mock-access-token', - scopes: 'a b c', - expiresInSeconds: '60', - }), + server.use( + rest.get('*', (_req, res, ctx) => + res( + ctx.json({ + idToken: 'mock-id-token', + accessToken: 'mock-access-token', + scopes: 'a b c', + expiresInSeconds: '60', + }), + ), + ), ); const helper = new DefaultAuthConnector(defaultOptions); @@ -64,7 +71,11 @@ describe('DefaultAuthConnector', () => { }); it('should handle failure to refresh session', async () => { - anyFetch.mockRejectOnce(new Error('Network NOPE')); + server.use( + rest.get('*', (_req, res, ctx) => + res(ctx.status(500, 'Error: Network NOPE')), + ), + ); const helper = new DefaultAuthConnector(defaultOptions); await expect(helper.refreshSession()).rejects.toThrow( @@ -73,7 +84,7 @@ describe('DefaultAuthConnector', () => { }); it('should handle failure response when refreshing session', async () => { - anyFetch.mockResponseOnce({}, { status: 401, statusText: 'NOPE' }); + server.use(rest.get('*', (_req, res, ctx) => res(ctx.status(401, 'NOPE')))); const helper = new DefaultAuthConnector(defaultOptions); await expect(helper.refreshSession()).rejects.toThrow( From 3825cb8d043ebe8b9f08ba57441a20526548e8d0 Mon Sep 17 00:00:00 2001 From: blam Date: Wed, 21 Oct 2020 10:09:36 +0200 Subject: [PATCH 37/40] chore(fetchReader): actually return the response of the reader --- packages/backend-common/src/reading/FetchUrlReader.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/backend-common/src/reading/FetchUrlReader.ts b/packages/backend-common/src/reading/FetchUrlReader.ts index 46db3e73ee..d2e5c45620 100644 --- a/packages/backend-common/src/reading/FetchUrlReader.ts +++ b/packages/backend-common/src/reading/FetchUrlReader.ts @@ -31,7 +31,7 @@ export class FetchUrlReader implements UrlReader { } if (response.ok) { - return Buffer.from(''); + return Buffer.from(await response.text()); } const message = `could not read ${url}, ${response.status} ${response.statusText}`; From 84c64329eae132145f834e0b6a4eff065c6fa11e Mon Sep 17 00:00:00 2001 From: blam Date: Wed, 21 Oct 2020 10:36:36 +0200 Subject: [PATCH 38/40] chore: fixing dependencies list --- plugins/circleci/package.json | 3 ++- plugins/cloudbuild/package.json | 3 ++- plugins/cost-insights/package.json | 3 ++- plugins/gcp-projects/package.json | 3 ++- plugins/github-actions/package.json | 3 ++- plugins/gitops-profiles/package.json | 3 ++- plugins/jenkins/package.json | 3 ++- plugins/newrelic/package.json | 3 ++- plugins/register-component/package.json | 3 ++- plugins/tech-radar/package.json | 3 ++- plugins/techdocs/package.json | 3 ++- plugins/user-settings/package.json | 5 +++-- plugins/welcome/package.json | 4 +++- 13 files changed, 28 insertions(+), 14 deletions(-) diff --git a/plugins/circleci/package.json b/plugins/circleci/package.json index 06c1dee340..464bb41441 100644 --- a/plugins/circleci/package.json +++ b/plugins/circleci/package.json @@ -47,7 +47,8 @@ "@types/node": "^12.0.0", "@types/react-lazylog": "^4.5.0", "msw": "^0.21.2", - "cross-fetch": "^3.0.6" + "cross-fetch": "^3.0.6", + "@backstage/test-utils": "^0.1.1-alpha.25" }, "files": [ "dist" diff --git a/plugins/cloudbuild/package.json b/plugins/cloudbuild/package.json index b27b6f83d6..f8bf338dd1 100644 --- a/plugins/cloudbuild/package.json +++ b/plugins/cloudbuild/package.json @@ -47,7 +47,8 @@ "@types/jest": "^26.0.7", "@types/node": "^12.0.0", "msw": "^0.21.2", - "cross-fetch": "^3.0.6" + "cross-fetch": "^3.0.6", + "@backstage/test-utils": "^0.1.1-alpha.25" }, "files": [ "dist" diff --git a/plugins/cost-insights/package.json b/plugins/cost-insights/package.json index 7bf4cc99c2..3d548402be 100644 --- a/plugins/cost-insights/package.json +++ b/plugins/cost-insights/package.json @@ -52,7 +52,8 @@ "@types/node": "^12.0.0", "@types/recharts": "^1.8.14", "msw": "^0.21.2", - "cross-fetch": "^3.0.6" + "cross-fetch": "^3.0.6", + "@backstage/test-utils": "^0.1.1-alpha.25" }, "files": [ "dist" diff --git a/plugins/gcp-projects/package.json b/plugins/gcp-projects/package.json index 4044d4467d..783504a2cf 100644 --- a/plugins/gcp-projects/package.json +++ b/plugins/gcp-projects/package.json @@ -39,7 +39,8 @@ "@types/jest": "^26.0.7", "@types/node": "^12.0.0", "msw": "^0.21.2", - "cross-fetch": "^3.0.6" + "cross-fetch": "^3.0.6", + "@backstage/test-utils": "^0.1.1-alpha.25" }, "files": [ "dist" diff --git a/plugins/github-actions/package.json b/plugins/github-actions/package.json index 191f7d475b..63390fdcc0 100644 --- a/plugins/github-actions/package.json +++ b/plugins/github-actions/package.json @@ -48,7 +48,8 @@ "@types/jest": "^26.0.7", "@types/node": "^12.0.0", "msw": "^0.21.2", - "cross-fetch": "^3.0.6" + "cross-fetch": "^3.0.6", + "@backstage/test-utils": "^0.1.1-alpha.25" }, "files": [ "dist" diff --git a/plugins/gitops-profiles/package.json b/plugins/gitops-profiles/package.json index 75f011b259..2daa8b103e 100644 --- a/plugins/gitops-profiles/package.json +++ b/plugins/gitops-profiles/package.json @@ -40,7 +40,8 @@ "@types/jest": "^26.0.7", "@types/node": "^12.0.0", "msw": "^0.21.2", - "cross-fetch": "^3.0.6" + "cross-fetch": "^3.0.6", + "@backstage/test-utils": "^0.1.1-alpha.25" }, "files": [ "dist" diff --git a/plugins/jenkins/package.json b/plugins/jenkins/package.json index c77ea45075..b3f19b2b16 100644 --- a/plugins/jenkins/package.json +++ b/plugins/jenkins/package.json @@ -45,7 +45,8 @@ "@types/node": "^12.0.0", "@types/testing-library__jest-dom": "^5.9.1", "msw": "^0.21.2", - "cross-fetch": "^3.0.6" + "cross-fetch": "^3.0.6", + "@backstage/test-utils": "^0.1.1-alpha.25" }, "files": [ "dist" diff --git a/plugins/newrelic/package.json b/plugins/newrelic/package.json index 5116f99353..3372562ca2 100644 --- a/plugins/newrelic/package.json +++ b/plugins/newrelic/package.json @@ -39,7 +39,8 @@ "@types/jest": "^26.0.7", "@types/node": "^12.0.0", "msw": "^0.21.2", - "cross-fetch": "^3.0.6" + "cross-fetch": "^3.0.6", + "@backstage/test-utils": "^0.1.1-alpha.25" }, "files": [ "dist" diff --git a/plugins/register-component/package.json b/plugins/register-component/package.json index de7c741225..9729a78d80 100644 --- a/plugins/register-component/package.json +++ b/plugins/register-component/package.json @@ -44,7 +44,8 @@ "@types/jest": "^26.0.7", "@types/node": "^12.0.0", "msw": "^0.21.2", - "cross-fetch": "^3.0.6" + "cross-fetch": "^3.0.6", + "@backstage/test-utils": "^0.1.1-alpha.25" }, "files": [ "dist" diff --git a/plugins/tech-radar/package.json b/plugins/tech-radar/package.json index 92c24d7758..19ac41fa8d 100644 --- a/plugins/tech-radar/package.json +++ b/plugins/tech-radar/package.json @@ -46,7 +46,8 @@ "@types/node": "^12.0.0", "@types/react": "^16.9", "msw": "^0.21.2", - "cross-fetch": "^3.0.6" + "cross-fetch": "^3.0.6", + "@backstage/test-utils": "^0.1.1-alpha.25" }, "files": [ "dist" diff --git a/plugins/techdocs/package.json b/plugins/techdocs/package.json index ec3ac408ad..eb6bb597d9 100644 --- a/plugins/techdocs/package.json +++ b/plugins/techdocs/package.json @@ -49,7 +49,8 @@ "@types/node": "^12.0.0", "canvas": "^2.6.1", "msw": "^0.21.2", - "cross-fetch": "^3.0.6" + "cross-fetch": "^3.0.6", + "@backstage/test-utils": "^0.1.1-alpha.25" }, "files": [ "dist" diff --git a/plugins/user-settings/package.json b/plugins/user-settings/package.json index 029ff99222..f80911f980 100644 --- a/plugins/user-settings/package.json +++ b/plugins/user-settings/package.json @@ -40,8 +40,9 @@ "@testing-library/user-event": "^12.0.7", "@types/jest": "^26.0.7", "@types/node": "^12.0.0", - "msw": "^0.20.5", - "node-fetch": "^2.6.1" + "msw": "^0.21.2", + "node-fetch": "^2.6.1", + "cross-fetch": "^3.0.6" }, "files": [ "dist" diff --git a/plugins/welcome/package.json b/plugins/welcome/package.json index c12d477181..653678f1f3 100644 --- a/plugins/welcome/package.json +++ b/plugins/welcome/package.json @@ -39,7 +39,9 @@ "@testing-library/user-event": "^12.0.7", "@types/jest": "^26.0.7", "msw": "^0.21.2", - "cross-fetch": "^3.0.6" + "cross-fetch": "^3.0.6", + "@backstage/test-utils": "^0.1.1-alpha.25", + "@types/node": "^12.0.0" }, "files": [ "dist" From e10480b5ea4e42467da573e911347c6f480bbc9a Mon Sep 17 00:00:00 2001 From: blam Date: Wed, 21 Oct 2020 10:38:17 +0200 Subject: [PATCH 39/40] chore(user-settings): removing last occurrence of node-fetch --- plugins/user-settings/package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/user-settings/package.json b/plugins/user-settings/package.json index f80911f980..9748bb1a9e 100644 --- a/plugins/user-settings/package.json +++ b/plugins/user-settings/package.json @@ -41,7 +41,6 @@ "@types/jest": "^26.0.7", "@types/node": "^12.0.0", "msw": "^0.21.2", - "node-fetch": "^2.6.1", "cross-fetch": "^3.0.6" }, "files": [ From 7721192dc14002c6faf17e9353cd1d442431cb0c Mon Sep 17 00:00:00 2001 From: blam Date: Wed, 21 Oct 2020 14:06:45 +0200 Subject: [PATCH 40/40] chore(create-plugin): removing the polyfill for backend components --- packages/cli/templates/default-backend-plugin/src/setupTests.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli/templates/default-backend-plugin/src/setupTests.ts b/packages/cli/templates/default-backend-plugin/src/setupTests.ts index 1c7ba6c7e1..ba33cf996b 100644 --- a/packages/cli/templates/default-backend-plugin/src/setupTests.ts +++ b/packages/cli/templates/default-backend-plugin/src/setupTests.ts @@ -13,5 +13,5 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import 'cross-fetch/polyfill'; + export {};