From e187e99b4702d7acf02dad9e84cca217b1b7982c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Wed, 22 May 2024 15:21:24 +0200 Subject: [PATCH] port proxy tests to msw2 to try to get rid of spurious build errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fredrik Adelöw --- plugins/proxy-backend/package.json | 2 +- .../src/service/router.config.test.ts | 15 ++++++--------- .../src/service/router.credentials.test.ts | 15 +++++++-------- yarn.lock | 2 +- 4 files changed, 15 insertions(+), 19 deletions(-) diff --git a/plugins/proxy-backend/package.json b/plugins/proxy-backend/package.json index d92dba9069..1ca6cbe5f5 100644 --- a/plugins/proxy-backend/package.json +++ b/plugins/proxy-backend/package.json @@ -74,7 +74,7 @@ "@types/supertest": "^2.0.8", "@types/uuid": "^9.0.0", "@types/yup": "^0.32.0", - "msw": "^1.0.0", + "msw": "^2.0.0", "node-fetch": "^2.6.7", "portfinder": "^1.0.32", "supertest": "^6.1.3" diff --git a/plugins/proxy-backend/src/service/router.config.test.ts b/plugins/proxy-backend/src/service/router.config.test.ts index 0de4787658..20aed5452a 100644 --- a/plugins/proxy-backend/src/service/router.config.test.ts +++ b/plugins/proxy-backend/src/service/router.config.test.ts @@ -24,7 +24,7 @@ import { StaticConfigSource, } from '@backstage/config-loader'; import express from 'express'; -import { rest } from 'msw'; +import { http, HttpResponse } from 'msw'; import { setupServer } from 'msw/node'; import request from 'supertest'; import { createRouter } from './router'; @@ -35,14 +35,11 @@ import { mockServices } from '@backstage/backend-test-utils'; describe('createRouter reloadable configuration', () => { const server = setupServer( - rest.get('https://non-existing-example.com/', (req, res, ctx) => - res( - ctx.status(200), - ctx.json({ - url: req.url.toString(), - headers: req.headers.all(), - }), - ), + http.get('https://non-existing-example.com/', req => + HttpResponse.json({ + url: req.request.url.toString(), + headers: req.request.headers, + }), ), ); diff --git a/plugins/proxy-backend/src/service/router.credentials.test.ts b/plugins/proxy-backend/src/service/router.credentials.test.ts index 1496b6ffb6..85fad9f038 100644 --- a/plugins/proxy-backend/src/service/router.credentials.test.ts +++ b/plugins/proxy-backend/src/service/router.credentials.test.ts @@ -21,7 +21,7 @@ import { } from '@backstage/backend-test-utils'; import { ResponseError } from '@backstage/errors'; import { JsonObject } from '@backstage/types'; -import { rest } from 'msw'; +import { http, HttpResponse, passthrough } from 'msw'; import { setupServer } from 'msw/node'; import fetch from 'node-fetch'; import portFinder from 'portfinder'; @@ -82,13 +82,12 @@ describe('credentials', () => { }; worker.use( - rest.all(`${baseUrl}/*`, req => req.passthrough()), - rest.get('http://target.com/*', (req, res, ctx) => { - const auth = req.headers.get('authorization'); - return res( - ctx.status(200), - ctx.json({ payload: { forwardedAuthorization: auth ?? false } }), - ); + http.all(`${baseUrl}/*`, () => passthrough()), + http.get('http://target.com/*', req => { + const auth = req.request.headers.get('authorization'); + return HttpResponse.json({ + payload: { forwardedAuthorization: auth ?? false }, + }); }), ); diff --git a/yarn.lock b/yarn.lock index d006daa23c..a823457dce 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6471,7 +6471,7 @@ __metadata: express-promise-router: ^4.1.0 http-proxy-middleware: ^2.0.0 morgan: ^1.10.0 - msw: ^1.0.0 + msw: ^2.0.0 node-fetch: ^2.6.7 portfinder: ^1.0.32 supertest: ^6.1.3