mirror of
https://github.com/morten-olsen/http.md.git
synced 2026-02-08 00:46:28 +01:00
test: add initial testing and linting (#18)
This commit is contained in:
25
tests/mocks/handlers.ts
Normal file
25
tests/mocks/handlers.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { http, HttpResponse } from 'msw';
|
||||
|
||||
export const handlers = [
|
||||
http.all('https://httpbin.org/*', async (req) => {
|
||||
const bodyRaw = await req.request.text();
|
||||
let bodyJson: unknown = undefined;
|
||||
try {
|
||||
bodyJson = JSON.parse(bodyRaw);
|
||||
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
|
||||
} catch (e) {
|
||||
// Ignore error
|
||||
}
|
||||
return HttpResponse.text(
|
||||
JSON.stringify(
|
||||
{
|
||||
headers: Object.fromEntries(req.request.headers.entries()),
|
||||
data: bodyRaw,
|
||||
json: bodyJson,
|
||||
},
|
||||
null,
|
||||
2,
|
||||
),
|
||||
);
|
||||
}),
|
||||
];
|
||||
5
tests/mocks/node.ts
Normal file
5
tests/mocks/node.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { setupServer } from 'msw/node';
|
||||
|
||||
import { handlers } from './handlers.js';
|
||||
|
||||
export const server = setupServer(...handlers);
|
||||
Reference in New Issue
Block a user