Skip to content

Commit

Permalink
chore(deps-dev): bump msw from 1.3.2 to 2.0.2 (#938)
Browse files Browse the repository at this point in the history
* chore(deps-dev): bump msw from 1.3.2 to 2.0.2

Bumps [msw](https://github.com/mswjs/msw) from 1.3.2 to 2.0.2.
- [Release notes](https://github.com/mswjs/msw/releases)
- [Changelog](https://github.com/mswjs/msw/blob/main/CHANGELOG.md)
- [Commits](mswjs/msw@v1.3.2...v2.0.2)

---
updated-dependencies:
- dependency-name: msw
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>

* chore: bump msw to latest

* refactor: use newest msw api in openapi tests

* refactor: use latest msw api in single-threaded tests

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Kanad Gupta <[email protected]>
Co-authored-by: Kanad Gupta <[email protected]>
  • Loading branch information
3 people authored Nov 6, 2023
1 parent b159da1 commit 8149de6
Show file tree
Hide file tree
Showing 5 changed files with 178 additions and 191 deletions.
28 changes: 14 additions & 14 deletions __tests__/cmds/openapi/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import fs from 'node:fs';

import chalk from 'chalk';
import { rest } from 'msw';
import { http } from 'msw';
import { setupServer } from 'msw/node';
import nock from 'nock';
import prompts from 'prompts';
Expand Down Expand Up @@ -1361,23 +1361,23 @@ describe('rdme openapi', () => {

server.use(
...[
rest.post(`${config.host}/api/v1/api-registry`, async (req, res, ctx) => {
const body = await req.text();
http.post(`${config.host}/api/v1/api-registry`, async ({ request }) => {
const body = await request.text();
expect(body).toMatch('form-data; name="spec"');
return res(ctx.status(201), ctx.json({ registryUUID }));
return Response.json({ registryUUID }, { status: 201 });
}),
rest.get(spec, (req, res, ctx) => {
return res(ctx.status(200), ctx.json(petstoreWeird));
http.get(spec, () => {
return Response.json(petstoreWeird, { status: 200 });
}),
rest.put(`${config.host}/api/v1/api-specification/${id}`, async (req, res, ctx) => {
expect(req.headers.get('authorization')).toBeBasicAuthApiKey(key);
expect(req.headers.get('x-rdme-ci')).toBe('GitHub Actions (test)');
expect(req.headers.get('x-readme-source')).toBe('cli-gh');
expect(req.headers.get('x-readme-source-url')).toBe(spec);
expect(req.headers.get('x-readme-version')).toBe(version);
const body = await req.json();
http.put(`${config.host}/api/v1/api-specification/${id}`, async ({ request }) => {
expect(request.headers.get('authorization')).toBeBasicAuthApiKey(key);
expect(request.headers.get('x-rdme-ci')).toBe('GitHub Actions (test)');
expect(request.headers.get('x-readme-source')).toBe('cli-gh');
expect(request.headers.get('x-readme-source-url')).toBe(spec);
expect(request.headers.get('x-readme-version')).toBe(version);
const body = await request.json();
expect(body).toStrictEqual({ registryUUID });
return res(ctx.status(201), ctx.set('location', exampleRefLocation), ctx.json({ _id: 1 }));
return Response.json({ _id: 1 }, { status: 201, headers: { location: exampleRefLocation } });
}),
],
);
Expand Down
15 changes: 7 additions & 8 deletions __tests__/helpers/get-api-mock.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { ResponseTransformer } from 'msw';
import type { Headers } from 'node-fetch';

import { rest } from 'msw';
import { http } from 'msw';
import nock from 'nock';

import config from '../../src/lib/config.js';
Expand Down Expand Up @@ -76,17 +75,17 @@ export function getAPIMockMSW(
expectedReqHeaders: ReqHeaders = {},
proxy = '',
) {
return rest.get(`${proxy}${config.host}${path}`, (req, res, ctx) => {
return http.get(`${proxy}${config.host}${path}`, ({ request }) => {
try {
// @ts-expect-error once we move off node-fetch, we can make these types consistent
validateHeaders(req.headers, basicAuthUser, expectedReqHeaders);
let responseTransformer: ResponseTransformer;
validateHeaders(request.headers, basicAuthUser, expectedReqHeaders);
let httpResponse = new Response(null, { status });
if (response?.json) {
responseTransformer = ctx.json(response.json);
httpResponse = Response.json(response.json, { status });
} else if (response?.text) {
responseTransformer = ctx.text(response.text);
httpResponse = new Response(response.text, { status });
}
return res(ctx.status(status), responseTransformer);
return httpResponse;
} catch (e) {
throw new Error(`Error mocking GET request to https://dash.readme.com${path}: ${e.message}`);
}
Expand Down
72 changes: 36 additions & 36 deletions __tests__/single-threaded/openapi/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import fs from 'node:fs';

import chalk from 'chalk';
import { rest } from 'msw';
import { http } from 'msw';
import { setupServer } from 'msw/node';
import prompts from 'prompts';
import { describe, beforeAll, beforeEach, afterEach, it, expect, vi, afterAll } from 'vitest';
Expand Down Expand Up @@ -73,17 +73,17 @@ describe('rdme openapi (single-threaded)', () => {
server.use(
...[
getAPIMockMSW(`/api/v1/version/${version}`, 200, { json: { version } }, key),
rest.post(`${config.host}/api/v1/api-registry`, async (req, res, ctx) => {
const body = await req.text();
http.post(`${config.host}/api/v1/api-registry`, async ({ request }) => {
const body = await request.text();
expect(body).toMatch('form-data; name="spec"');
return res(ctx.status(201), ctx.json({ registryUUID, spec: { openapi: '3.0.0' } }));
return Response.json({ registryUUID, spec: { openapi: '3.0.0' } }, { status: 201 });
}),
getAPIMockMSW('/api/v1/api-specification', 200, { json: [] }, key, { 'x-readme-version': version }),
rest.post(`${config.host}/api/v1/api-specification`, async (req, res, ctx) => {
const body = await req.json();
http.post(`${config.host}/api/v1/api-specification`, async ({ request }) => {
const body = await request.json();
expect(body).toStrictEqual({ registryUUID });
expect(req.headers.get('authorization')).toBeBasicAuthApiKey(key);
return res(ctx.status(201), ctx.set('location', exampleRefLocation), ctx.json({ _id: 1 }));
expect(request.headers.get('authorization')).toBeBasicAuthApiKey(key);
return Response.json({ _id: 1 }, { status: 201, headers: { location: exampleRefLocation } });
}),
],
);
Expand Down Expand Up @@ -112,19 +112,19 @@ describe('rdme openapi (single-threaded)', () => {
server.use(
...[
getAPIMockMSW(`/api/v1/version/${version}`, 200, { json: { version } }, key),
rest.post(`${config.host}/api/v1/api-registry`, async (req, res, ctx) => {
const body = await req.text();
http.post(`${config.host}/api/v1/api-registry`, async ({ request }) => {
const body = await request.text();
requestBody = body.substring(body.indexOf('{'), body.lastIndexOf('}') + 1);
requestBody = JSON.parse(requestBody);
expect(body).toMatch('form-data; name="spec"');
return res(ctx.status(201), ctx.json({ registryUUID, spec: { openapi: '3.0.0' } }));
return Response.json({ registryUUID, spec: { openapi: '3.0.0' } }, { status: 201 });
}),
getAPIMockMSW('/api/v1/api-specification', 200, { json: [] }, key, { 'x-readme-version': version }),
rest.post(`${config.host}/api/v1/api-specification`, async (req, res, ctx) => {
const body = await req.json();
http.post(`${config.host}/api/v1/api-specification`, async ({ request }) => {
const body = await request.json();
expect(body).toStrictEqual({ registryUUID });
expect(req.headers.get('authorization')).toBeBasicAuthApiKey(key);
return res(ctx.status(201), ctx.set('location', exampleRefLocation), ctx.json({ _id: 1 }));
expect(request.headers.get('authorization')).toBeBasicAuthApiKey(key);
return Response.json({ _id: 1 }, { status: 201, headers: { location: exampleRefLocation } });
}),
],
);
Expand Down Expand Up @@ -152,10 +152,10 @@ describe('rdme openapi (single-threaded)', () => {
server.use(
...[
getAPIMockMSW(`/api/v1/version/${version}`, 200, { json: { version } }, key),
rest.post(`${config.host}/api/v1/api-registry`, async (req, res, ctx) => {
const body = await req.text();
http.post(`${config.host}/api/v1/api-registry`, async ({ request }) => {
const body = await request.text();
expect(body).toMatch('form-data; name="spec"');
return res(ctx.status(201), ctx.json({ registryUUID, spec: { openapi: '3.0.0' } }));
return Response.json({ registryUUID, spec: { openapi: '3.0.0' } }, { status: 201 });
}),
getAPIMockMSW('/api/v1/api-specification', 200, { json: [] }, key, { 'x-readme-version': version }),
],
Expand Down Expand Up @@ -211,17 +211,17 @@ describe('rdme openapi (single-threaded)', () => {
server.use(
...[
getAPIMockMSW(`/api/v1/version/${version}`, 200, { json: { version } }, key),
rest.post(`${config.host}/api/v1/api-registry`, async (req, res, ctx) => {
const body = await req.text();
http.post(`${config.host}/api/v1/api-registry`, async ({ request }) => {
const body = await request.text();
expect(body).toMatch('form-data; name="spec"');
return res(ctx.status(201), ctx.json({ registryUUID, spec: { openapi: '3.0.0' } }));
return Response.json({ registryUUID, spec: { openapi: '3.0.0' } }, { status: 201 });
}),
getAPIMockMSW('/api/v1/api-specification', 200, { json: [] }, key, { 'x-readme-version': version }),
rest.post(`${config.host}/api/v1/api-specification`, async (req, res, ctx) => {
expect(req.headers.get('authorization')).toBeBasicAuthApiKey(key);
const body = await req.json();
http.post(`${config.host}/api/v1/api-specification`, async ({ request }) => {
expect(request.headers.get('authorization')).toBeBasicAuthApiKey(key);
const body = await request.json();
expect(body).toStrictEqual({ registryUUID });
return res(ctx.status(201), ctx.set('location', exampleRefLocation), ctx.json({ _id: 1 }));
return Response.json({ _id: 1 }, { status: 201, headers: { location: exampleRefLocation } });
}),
],
);
Expand Down Expand Up @@ -260,23 +260,23 @@ describe('rdme openapi (single-threaded)', () => {
server.use(
...[
getAPIMockMSW(`/api/v1/version/${version}`, 200, { json: { version } }, key),
rest.post(`${config.host}/api/v1/api-registry`, async (req, res, ctx) => {
const body = await req.text();
http.post(`${config.host}/api/v1/api-registry`, async ({ request }) => {
const body = await request.text();
expect(body).toMatch('form-data; name="spec"');
return res(ctx.status(201), ctx.json({ registryUUID, spec: { openapi: '3.0.0' } }));
return Response.json({ registryUUID, spec: { openapi: '3.0.0' } }, { status: 201 });
}),
getAPIMockMSW('/api/v1/api-specification', 200, { json: [] }, key, { 'x-readme-version': version }),
rest.post(`${config.host}/api/v1/api-specification`, async (req, res, ctx) => {
expect(req.headers.get('authorization')).toBeBasicAuthApiKey(key);
expect(req.headers.get('x-rdme-ci')).toBe('GitHub Actions (test)');
expect(req.headers.get('x-readme-source')).toBe('cli-gh');
expect(req.headers.get('x-readme-source-url')).toBe(
http.post(`${config.host}/api/v1/api-specification`, async ({ request }) => {
expect(request.headers.get('authorization')).toBeBasicAuthApiKey(key);
expect(request.headers.get('x-rdme-ci')).toBe('GitHub Actions (test)');
expect(request.headers.get('x-readme-source')).toBe('cli-gh');
expect(request.headers.get('x-readme-source-url')).toBe(
'https://github.com/octocat/Hello-World/blob/ffac537e6cbbf934b08745a378932722df287a53/__tests__/__fixtures__/relative-ref-oas/petstore.json',
);
expect(req.headers.get('x-readme-version')).toBe(version);
const body = await req.json();
expect(request.headers.get('x-readme-version')).toBe(version);
const body = await request.json();
expect(body).toStrictEqual({ registryUUID });
return res(ctx.status(201), ctx.set('location', exampleRefLocation), ctx.json({ _id: 1 }));
return Response.json({ _id: 1 }, { status: 201, headers: { location: exampleRefLocation } });
}),
],
);
Expand Down
Loading

0 comments on commit 8149de6

Please sign in to comment.