test: add initial testing and linting (#18)

This commit is contained in:
Morten Olsen
2025-05-19 21:04:32 +02:00
committed by GitHub
parent 9d04cf0414
commit c01dce4998
33 changed files with 4159 additions and 299 deletions

25
tests/mocks/handlers.ts Normal file
View 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
View File

@@ -0,0 +1,5 @@
import { setupServer } from 'msw/node';
import { handlers } from './handlers.js';
export const server = setupServer(...handlers);