port proxy tests to msw2 to try to get rid of spurious build errors
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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,
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
@@ -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 },
|
||||
});
|
||||
}),
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user