chore: migrate three packages to MSW v2

Migrates test files in config-loader, events-node and kubernetes-react
packages from MSW 1.x to MSW 2.x API to fix compatibility issues with
Jest 30 and JSDOM v26.

Changes:
- Updated msw dependency from ^1.0.0 to ^2.0.0
- Changed imports from `rest` to `http` and `HttpResponse`
- Converted handler syntax from `res(ctx.*)` to `HttpResponse.*`
- Changed `toStrictEqual` to `toEqual` for response assertions

Affected packages:
- @backstage/config-loader
- @backstage/plugin-events-node
- @backstage/plugin-kubernetes-react

Signed-off-by: Johan Persson <johanopersson@gmail.com>
This commit is contained in:
Johan Persson
2025-12-02 15:52:05 +01:00
parent cd0b8a11a3
commit e70ff47db3
8 changed files with 182 additions and 214 deletions
+1 -1
View File
@@ -57,7 +57,7 @@
"@backstage/cli": "workspace:^",
"@types/json-schema-merge-allof": "^0.6.0",
"@types/minimist": "^1.2.5",
"msw": "^1.0.0",
"msw": "^2.0.0",
"zen-observable": "^0.10.0"
}
}
+9 -13
View File
@@ -17,7 +17,7 @@
import { AppConfig } from '@backstage/config';
import { loadConfig } from './loader';
import fs from 'fs-extra';
import { rest } from 'msw';
import { http, HttpResponse } from 'msw';
import { setupServer } from 'msw/node';
import { createMockDirectory } from '@backstage/backend-test-utils';
import { createDeferred } from '@backstage/types';
@@ -74,32 +74,28 @@ describe('loadConfig', () => {
});
const server = setupServer();
const initialLoaderHandler = rest.get(
const initialLoaderHandler = http.get(
`https://some.domain.io/app-config.yaml`,
(_req, res, ctx) => {
return res(
ctx.body(
`app:
() => {
return new HttpResponse(
`app:
title: Remote Example App
sessionKey: 'abc123'
escaped: \$\${Escaped}
`,
),
);
},
);
const reloadHandler = rest.get(
const reloadHandler = http.get(
`https://some.domain.io/app-config.yaml`,
(_req, res, ctx) => {
return res(
ctx.body(
`app:
() => {
return new HttpResponse(
`app:
title: NEW ReMOTe ExaMPLe App
sessionKey: 'abc123'
escaped: \$\${Escaped}
`,
),
);
},
);
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { rest } from 'msw';
import { http, HttpResponse } from 'msw';
import { registerMswTestHooks } from '@backstage/backend-test-utils';
import { setupServer } from 'msw/node';
import { RemoteConfigSource } from './RemoteConfigSource';
@@ -26,15 +26,15 @@ describe('RemoteConfigSource', () => {
it('should load config from a remote URL', async () => {
worker.use(
rest.get('http://localhost/config.yaml', (_req, res, ctx) =>
res(
ctx.body(`
http.get(
'http://localhost/config.yaml',
() =>
new HttpResponse(`
app:
title: Example App
substituted: \${VALUE}
escaped: \$\${VALUE}
`),
),
),
);
@@ -61,9 +61,10 @@ app:
it('should load and parse config from a remote URL', async () => {
worker.use(
rest.get('http://localhost/config.json', (_req, res, ctx) =>
res(
ctx.body(
http.get(
'http://localhost/config.json',
() =>
new HttpResponse(
JSON.stringify({
app: {
title: 'Example App',
@@ -72,7 +73,6 @@ app:
},
}),
),
),
),
);
@@ -102,12 +102,12 @@ app:
let fetched = false;
worker.use(
rest.get('http://localhost/config.yaml', (_req, res, ctx) => {
http.get('http://localhost/config.yaml', () => {
if (!fetched) {
fetched = true;
return res(ctx.body('x: 1'));
return new HttpResponse('x: 1');
}
return res(ctx.body('x: 2'));
return new HttpResponse('x: 2');
}),
);