@jaredwray/mockhttp 0.4.3 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +12 -0
- package/dist/index.js +294 -26
- package/package.json +23 -15
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,8 @@ type HttpBinOptions = {
|
|
|
7
7
|
requestInspection?: boolean;
|
|
8
8
|
responseInspection?: boolean;
|
|
9
9
|
statusCodes?: boolean;
|
|
10
|
+
cookies?: boolean;
|
|
11
|
+
anything?: boolean;
|
|
10
12
|
};
|
|
11
13
|
type MockHttpOptions = {
|
|
12
14
|
/**
|
|
@@ -157,6 +159,16 @@ declare class MockHttp extends Hookified {
|
|
|
157
159
|
* @param fastifyInstance - the server instance to register the routes on.
|
|
158
160
|
*/
|
|
159
161
|
registerRedirectRoutes(fastifyInstance?: FastifyInstance): Promise<void>;
|
|
162
|
+
/**
|
|
163
|
+
* Register the cookie routes.
|
|
164
|
+
* @param fastifyInstance - the server instance to register the routes on.
|
|
165
|
+
*/
|
|
166
|
+
registerCookieRoutes(fastifyInstance?: FastifyInstance): Promise<void>;
|
|
167
|
+
/**
|
|
168
|
+
* Register the anything routes.
|
|
169
|
+
* @param fastifyInstance - the server instance to register the routes on.
|
|
170
|
+
*/
|
|
171
|
+
registerAnythingRoutes(fastifyInstance?: FastifyInstance): Promise<void>;
|
|
160
172
|
}
|
|
161
173
|
|
|
162
174
|
declare const start: () => Promise<MockHttp>;
|
package/dist/index.js
CHANGED
|
@@ -2,13 +2,14 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
3
|
|
|
4
4
|
// src/index.ts
|
|
5
|
-
import process from "
|
|
5
|
+
import process from "process";
|
|
6
6
|
|
|
7
7
|
// src/mock-http.ts
|
|
8
|
-
import path from "
|
|
8
|
+
import path from "path";
|
|
9
9
|
import fastifyStatic from "@fastify/static";
|
|
10
10
|
import fastifyHelmet from "@fastify/helmet";
|
|
11
11
|
import { fastifySwagger } from "@fastify/swagger";
|
|
12
|
+
import fastifyCookie from "@fastify/cookie";
|
|
12
13
|
import Fastify from "fastify";
|
|
13
14
|
import { Hookified } from "hookified";
|
|
14
15
|
import { detect } from "detect-port";
|
|
@@ -19,7 +20,7 @@ import { fastifySwaggerUi } from "@fastify/swagger-ui";
|
|
|
19
20
|
// package.json
|
|
20
21
|
var package_default = {
|
|
21
22
|
name: "@jaredwray/mockhttp",
|
|
22
|
-
version: "0.
|
|
23
|
+
version: "0.6.0",
|
|
23
24
|
description: "Mock Http - Easy way to mock http with httpbin replacement",
|
|
24
25
|
type: "module",
|
|
25
26
|
main: "dist/index.js",
|
|
@@ -37,7 +38,7 @@ var package_default = {
|
|
|
37
38
|
"docker:readme": "tsx ./scripts/create-docker-readme.ts",
|
|
38
39
|
"docker:compose:up": "docker-compose up -d",
|
|
39
40
|
"docker:compose:down": "docker-compose down",
|
|
40
|
-
prepare: "
|
|
41
|
+
prepare: "pnpm run build",
|
|
41
42
|
start: "node dist/index.js"
|
|
42
43
|
},
|
|
43
44
|
repository: {
|
|
@@ -57,27 +58,28 @@ var package_default = {
|
|
|
57
58
|
},
|
|
58
59
|
homepage: "https://github.com/jaredwray/mockhttp#readme",
|
|
59
60
|
devDependencies: {
|
|
60
|
-
"@swc/core": "^1.
|
|
61
|
+
"@swc/core": "^1.12.1",
|
|
61
62
|
"@types/html-escaper": "^3.0.4",
|
|
62
|
-
"@vitest/coverage-v8": "^3.
|
|
63
|
+
"@vitest/coverage-v8": "^3.2.3",
|
|
63
64
|
rimraf: "^6.0.1",
|
|
64
|
-
tsup: "^8.
|
|
65
|
-
tsx: "^4.
|
|
65
|
+
tsup: "^8.5.0",
|
|
66
|
+
tsx: "^4.20.3",
|
|
66
67
|
typescript: "^5.8.3",
|
|
67
|
-
vitest: "^3.
|
|
68
|
-
xo: "^
|
|
68
|
+
vitest: "^3.2.3",
|
|
69
|
+
xo: "^1.1.0"
|
|
69
70
|
},
|
|
70
71
|
dependencies: {
|
|
72
|
+
"@fastify/cookie": "^11.0.2",
|
|
71
73
|
"@fastify/helmet": "^13.0.1",
|
|
72
|
-
"@fastify/static": "^8.
|
|
73
|
-
"@fastify/swagger": "^9.
|
|
74
|
-
"@fastify/swagger-ui": "^5.2.
|
|
75
|
-
"@scalar/api-reference": "^1.
|
|
74
|
+
"@fastify/static": "^8.2.0",
|
|
75
|
+
"@fastify/swagger": "^9.5.1",
|
|
76
|
+
"@fastify/swagger-ui": "^5.2.3",
|
|
77
|
+
"@scalar/api-reference": "^1.31.11",
|
|
76
78
|
"detect-port": "^2.1.0",
|
|
77
|
-
fastify: "^5.
|
|
78
|
-
hookified: "^1.
|
|
79
|
+
fastify: "^5.4.0",
|
|
80
|
+
hookified: "^1.9.1",
|
|
79
81
|
"html-escaper": "^3.0.3",
|
|
80
|
-
pino: "^9.
|
|
82
|
+
pino: "^9.7.0",
|
|
81
83
|
"pino-pretty": "^13.0.0"
|
|
82
84
|
},
|
|
83
85
|
files: [
|
|
@@ -89,8 +91,15 @@ var package_default = {
|
|
|
89
91
|
onlyBuiltDependencies: [
|
|
90
92
|
"@swc/core",
|
|
91
93
|
"esbuild",
|
|
94
|
+
"unrs-resolver",
|
|
92
95
|
"vue-demi"
|
|
93
96
|
]
|
|
97
|
+
},
|
|
98
|
+
xo: {
|
|
99
|
+
rules: {
|
|
100
|
+
"@typescript-eslint/no-unsafe-call": "off",
|
|
101
|
+
"@typescript-eslint/no-unsafe-assignment": "off"
|
|
102
|
+
}
|
|
94
103
|
}
|
|
95
104
|
};
|
|
96
105
|
|
|
@@ -217,7 +226,10 @@ var indexRoute = /* @__PURE__ */ __name((fastify) => {
|
|
|
217
226
|
<header class="custom-header scalar-app">
|
|
218
227
|
<a href="/"><img src="/logo.svg" alt="{ mockhttp }" /></a>
|
|
219
228
|
<a href="https://github.com/jaredwray/mockhttp" class="github-corner" aria-label="View source on GitHub">
|
|
220
|
-
<svg width="70" height="70" viewBox="0 0 250 250" style="color:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"
|
|
229
|
+
<svg width="70" height="70" viewBox="0 0 250 250" style="color:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true">
|
|
230
|
+
<path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path>
|
|
231
|
+
<path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path>
|
|
232
|
+
<path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style>
|
|
221
233
|
</header>
|
|
222
234
|
|
|
223
235
|
<script
|
|
@@ -511,7 +523,7 @@ var patchRoute = /* @__PURE__ */ __name((fastify) => {
|
|
|
511
523
|
}, "patchRoute");
|
|
512
524
|
|
|
513
525
|
// src/routes/status-codes/index.ts
|
|
514
|
-
import { randomInt } from "
|
|
526
|
+
import { randomInt } from "crypto";
|
|
515
527
|
var statusCodes = [
|
|
516
528
|
{
|
|
517
529
|
code: 100,
|
|
@@ -884,7 +896,7 @@ var headersRoute = /* @__PURE__ */ __name((fastify) => {
|
|
|
884
896
|
fastify.get("/headers", {
|
|
885
897
|
schema: headersSchema
|
|
886
898
|
}, async (request) => {
|
|
887
|
-
const headers = request
|
|
899
|
+
const { headers } = request;
|
|
888
900
|
return {
|
|
889
901
|
headers
|
|
890
902
|
};
|
|
@@ -1140,9 +1152,9 @@ var absoluteRedirectRoute = /* @__PURE__ */ __name((fastify) => {
|
|
|
1140
1152
|
fastify.get("/absolute-redirect/:value", {
|
|
1141
1153
|
schema: absoluteRedirectSchema
|
|
1142
1154
|
}, async (request, reply) => {
|
|
1143
|
-
const value = request.params
|
|
1155
|
+
const { value } = request.params;
|
|
1144
1156
|
const { host } = request.headers;
|
|
1145
|
-
const protocol = request
|
|
1157
|
+
const { protocol } = request;
|
|
1146
1158
|
let url = `${protocol}://${host}/get`;
|
|
1147
1159
|
let html = `
|
|
1148
1160
|
<title>Redirecting...</title>
|
|
@@ -1201,7 +1213,7 @@ var relativeRedirectRoute = /* @__PURE__ */ __name((fastify) => {
|
|
|
1201
1213
|
fastify.get("/relative-redirect/:value", {
|
|
1202
1214
|
schema: relativeRedirectSchema
|
|
1203
1215
|
}, async (request, reply) => {
|
|
1204
|
-
const value = request.params
|
|
1216
|
+
const { value } = request.params;
|
|
1205
1217
|
let url = "/get";
|
|
1206
1218
|
let html = `
|
|
1207
1219
|
<title>Redirecting...</title>
|
|
@@ -1270,6 +1282,236 @@ var redirectToRoute = /* @__PURE__ */ __name((fastify) => {
|
|
|
1270
1282
|
}, handler);
|
|
1271
1283
|
}, "redirectToRoute");
|
|
1272
1284
|
|
|
1285
|
+
// src/routes/cookies/get.ts
|
|
1286
|
+
var getCookiesRouteSchema = {
|
|
1287
|
+
description: "Return cookies from the request",
|
|
1288
|
+
tags: [
|
|
1289
|
+
"Cookies"
|
|
1290
|
+
],
|
|
1291
|
+
response: {
|
|
1292
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1293
|
+
200: {
|
|
1294
|
+
type: "object",
|
|
1295
|
+
properties: {
|
|
1296
|
+
cookies: {
|
|
1297
|
+
type: "object",
|
|
1298
|
+
additionalProperties: {
|
|
1299
|
+
type: "string"
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
},
|
|
1303
|
+
required: [
|
|
1304
|
+
"cookies"
|
|
1305
|
+
]
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1308
|
+
};
|
|
1309
|
+
var getCookiesRoute = /* @__PURE__ */ __name((fastify) => {
|
|
1310
|
+
fastify.get("/cookies", {
|
|
1311
|
+
schema: getCookiesRouteSchema
|
|
1312
|
+
}, async (request, reply) => {
|
|
1313
|
+
reply.type("application/json");
|
|
1314
|
+
await reply.send({
|
|
1315
|
+
cookies: request.cookies
|
|
1316
|
+
});
|
|
1317
|
+
});
|
|
1318
|
+
}, "getCookiesRoute");
|
|
1319
|
+
|
|
1320
|
+
// src/routes/cookies/post.ts
|
|
1321
|
+
var postCookieRouteSchema = {
|
|
1322
|
+
description: "Set a cookie",
|
|
1323
|
+
tags: [
|
|
1324
|
+
"Cookies"
|
|
1325
|
+
],
|
|
1326
|
+
body: {
|
|
1327
|
+
type: "object",
|
|
1328
|
+
properties: {
|
|
1329
|
+
name: {
|
|
1330
|
+
type: "string"
|
|
1331
|
+
},
|
|
1332
|
+
value: {
|
|
1333
|
+
type: "string"
|
|
1334
|
+
},
|
|
1335
|
+
expires: {
|
|
1336
|
+
type: "string",
|
|
1337
|
+
format: "date-time"
|
|
1338
|
+
}
|
|
1339
|
+
},
|
|
1340
|
+
required: [
|
|
1341
|
+
"name",
|
|
1342
|
+
"value"
|
|
1343
|
+
],
|
|
1344
|
+
additionalProperties: false
|
|
1345
|
+
},
|
|
1346
|
+
response: {
|
|
1347
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1348
|
+
200: {
|
|
1349
|
+
type: "object",
|
|
1350
|
+
properties: {
|
|
1351
|
+
cookies: {
|
|
1352
|
+
type: "object",
|
|
1353
|
+
additionalProperties: {
|
|
1354
|
+
type: "string"
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
},
|
|
1358
|
+
required: [
|
|
1359
|
+
"cookies"
|
|
1360
|
+
]
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
};
|
|
1364
|
+
var postCookieRoute = /* @__PURE__ */ __name((fastify) => {
|
|
1365
|
+
fastify.post("/cookies", {
|
|
1366
|
+
schema: postCookieRouteSchema
|
|
1367
|
+
}, async (request, reply) => {
|
|
1368
|
+
const { name, value, expires } = request.body;
|
|
1369
|
+
if (expires) {
|
|
1370
|
+
const date = new Date(expires);
|
|
1371
|
+
reply.setCookie(name, value, {
|
|
1372
|
+
path: "/",
|
|
1373
|
+
expires: date
|
|
1374
|
+
});
|
|
1375
|
+
} else {
|
|
1376
|
+
reply.setCookie(name, value, {
|
|
1377
|
+
path: "/"
|
|
1378
|
+
});
|
|
1379
|
+
}
|
|
1380
|
+
return reply.status(200).send();
|
|
1381
|
+
});
|
|
1382
|
+
}, "postCookieRoute");
|
|
1383
|
+
|
|
1384
|
+
// src/routes/cookies/delete.ts
|
|
1385
|
+
var cookiesDeleteSchema = {
|
|
1386
|
+
description: "Delete a cookie",
|
|
1387
|
+
tags: [
|
|
1388
|
+
"Cookies"
|
|
1389
|
+
],
|
|
1390
|
+
querystring: {
|
|
1391
|
+
type: "object",
|
|
1392
|
+
properties: {
|
|
1393
|
+
name: {
|
|
1394
|
+
type: "string"
|
|
1395
|
+
}
|
|
1396
|
+
},
|
|
1397
|
+
required: [
|
|
1398
|
+
"name"
|
|
1399
|
+
],
|
|
1400
|
+
additionalProperties: false
|
|
1401
|
+
},
|
|
1402
|
+
response: {
|
|
1403
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1404
|
+
204: {
|
|
1405
|
+
type: "null"
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
};
|
|
1409
|
+
var deleteCookieRoute = /* @__PURE__ */ __name((fastify) => {
|
|
1410
|
+
fastify.delete("/cookies", {
|
|
1411
|
+
schema: cookiesDeleteSchema
|
|
1412
|
+
}, async (request, reply) => {
|
|
1413
|
+
const { name } = request.query;
|
|
1414
|
+
reply.clearCookie(name, {
|
|
1415
|
+
path: "/"
|
|
1416
|
+
});
|
|
1417
|
+
return reply.status(204).send();
|
|
1418
|
+
});
|
|
1419
|
+
}, "deleteCookieRoute");
|
|
1420
|
+
|
|
1421
|
+
// src/routes/anything/index.ts
|
|
1422
|
+
var anythingSchema = {
|
|
1423
|
+
description: "Will return anything that you send it",
|
|
1424
|
+
tags: [
|
|
1425
|
+
"Anything"
|
|
1426
|
+
],
|
|
1427
|
+
response: {
|
|
1428
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1429
|
+
200: {
|
|
1430
|
+
type: "object",
|
|
1431
|
+
properties: {
|
|
1432
|
+
// Echo back all your params under `args`
|
|
1433
|
+
args: {
|
|
1434
|
+
type: "object",
|
|
1435
|
+
description: "Route parameters",
|
|
1436
|
+
additionalProperties: true
|
|
1437
|
+
},
|
|
1438
|
+
// Echo back whatever was in the request.body
|
|
1439
|
+
data: {
|
|
1440
|
+
type: "object",
|
|
1441
|
+
description: "Request body data",
|
|
1442
|
+
additionalProperties: true
|
|
1443
|
+
},
|
|
1444
|
+
// If you’re using fastify-multipart, you’ll get
|
|
1445
|
+
// files via request.files(); this just allows
|
|
1446
|
+
// you to mirror them back
|
|
1447
|
+
files: {
|
|
1448
|
+
type: "object",
|
|
1449
|
+
description: "Uploaded files",
|
|
1450
|
+
additionalProperties: true
|
|
1451
|
+
},
|
|
1452
|
+
// If you parse application/x-www-form-urlencoded
|
|
1453
|
+
// these fields land in request.body too, but you can
|
|
1454
|
+
// mirror them separately if you like
|
|
1455
|
+
form: {
|
|
1456
|
+
type: "object",
|
|
1457
|
+
description: "Form data",
|
|
1458
|
+
additionalProperties: true
|
|
1459
|
+
},
|
|
1460
|
+
headers: {
|
|
1461
|
+
type: "object",
|
|
1462
|
+
description: "Request headers",
|
|
1463
|
+
additionalProperties: true
|
|
1464
|
+
},
|
|
1465
|
+
json: {
|
|
1466
|
+
type: "object",
|
|
1467
|
+
description: "Parsed JSON body",
|
|
1468
|
+
additionalProperties: true
|
|
1469
|
+
},
|
|
1470
|
+
method: {
|
|
1471
|
+
type: "string",
|
|
1472
|
+
description: "HTTP method used"
|
|
1473
|
+
},
|
|
1474
|
+
origin: {
|
|
1475
|
+
type: "string",
|
|
1476
|
+
description: "Origin of the request"
|
|
1477
|
+
},
|
|
1478
|
+
url: {
|
|
1479
|
+
type: "string",
|
|
1480
|
+
description: "Request URL"
|
|
1481
|
+
}
|
|
1482
|
+
},
|
|
1483
|
+
// Don’t allow any other top-level keys in your response
|
|
1484
|
+
additionalProperties: false
|
|
1485
|
+
}
|
|
1486
|
+
}
|
|
1487
|
+
};
|
|
1488
|
+
var anythingRoute = /* @__PURE__ */ __name((fastify) => {
|
|
1489
|
+
const handler = /* @__PURE__ */ __name(async (request, reply) => {
|
|
1490
|
+
const response = {
|
|
1491
|
+
args: request.query,
|
|
1492
|
+
data: request.body ?? {},
|
|
1493
|
+
files: request.raw?.files ?? {},
|
|
1494
|
+
form: request.body ?? {},
|
|
1495
|
+
headers: request.headers,
|
|
1496
|
+
json: request.body ?? {},
|
|
1497
|
+
method: request.method,
|
|
1498
|
+
origin: request.headers.origin ?? request.headers.host ?? "",
|
|
1499
|
+
url: request.url
|
|
1500
|
+
};
|
|
1501
|
+
await reply.send(response);
|
|
1502
|
+
}, "handler");
|
|
1503
|
+
const noValidation = {
|
|
1504
|
+
schema: anythingSchema,
|
|
1505
|
+
// Skip AJV on *this* route
|
|
1506
|
+
validatorCompiler: /* @__PURE__ */ __name(() => () => true, "validatorCompiler")
|
|
1507
|
+
};
|
|
1508
|
+
fastify.get("/anything", noValidation, handler);
|
|
1509
|
+
fastify.post("/anything", noValidation, handler);
|
|
1510
|
+
fastify.put("/anything", noValidation, handler);
|
|
1511
|
+
fastify.patch("/anything", noValidation, handler);
|
|
1512
|
+
fastify.delete("/anything", noValidation, handler);
|
|
1513
|
+
}, "anythingRoute");
|
|
1514
|
+
|
|
1273
1515
|
// src/mock-http.ts
|
|
1274
1516
|
var MockHttp = class extends Hookified {
|
|
1275
1517
|
static {
|
|
@@ -1285,7 +1527,9 @@ var MockHttp = class extends Hookified {
|
|
|
1285
1527
|
redirects: true,
|
|
1286
1528
|
requestInspection: true,
|
|
1287
1529
|
responseInspection: true,
|
|
1288
|
-
statusCodes: true
|
|
1530
|
+
statusCodes: true,
|
|
1531
|
+
cookies: true,
|
|
1532
|
+
anything: true
|
|
1289
1533
|
};
|
|
1290
1534
|
// eslint-disable-next-line new-cap
|
|
1291
1535
|
_server = Fastify();
|
|
@@ -1374,7 +1618,6 @@ var MockHttp = class extends Hookified {
|
|
|
1374
1618
|
* Whether to use Swagger for API documentation. Defaults to true.
|
|
1375
1619
|
* @default true
|
|
1376
1620
|
*/
|
|
1377
|
-
// eslint-disable-next-line unicorn/prevent-abbreviations
|
|
1378
1621
|
set apiDocs(apiDocs) {
|
|
1379
1622
|
this._apiDocs = apiDocs;
|
|
1380
1623
|
}
|
|
@@ -1426,7 +1669,7 @@ var MockHttp = class extends Hookified {
|
|
|
1426
1669
|
if (this._apiDocs) {
|
|
1427
1670
|
await this.registerApiDocs();
|
|
1428
1671
|
}
|
|
1429
|
-
const { httpMethods, redirects, requestInspection, responseInspection, statusCodes: statusCodes2 } = this._httpBin;
|
|
1672
|
+
const { httpMethods, redirects, requestInspection, responseInspection, statusCodes: statusCodes2, cookies, anything } = this._httpBin;
|
|
1430
1673
|
if (httpMethods) {
|
|
1431
1674
|
await this.registerHttpMethods();
|
|
1432
1675
|
}
|
|
@@ -1442,6 +1685,12 @@ var MockHttp = class extends Hookified {
|
|
|
1442
1685
|
if (redirects) {
|
|
1443
1686
|
await this.registerRedirectRoutes();
|
|
1444
1687
|
}
|
|
1688
|
+
if (cookies) {
|
|
1689
|
+
await this.registerCookieRoutes();
|
|
1690
|
+
}
|
|
1691
|
+
if (anything) {
|
|
1692
|
+
await this.registerAnythingRoutes();
|
|
1693
|
+
}
|
|
1445
1694
|
if (this._autoDetectPort) {
|
|
1446
1695
|
const originalPort = this._port;
|
|
1447
1696
|
this._port = await this.detectPort();
|
|
@@ -1531,6 +1780,25 @@ var MockHttp = class extends Hookified {
|
|
|
1531
1780
|
await fastify.register(relativeRedirectRoute);
|
|
1532
1781
|
await fastify.register(redirectToRoute);
|
|
1533
1782
|
}
|
|
1783
|
+
/**
|
|
1784
|
+
* Register the cookie routes.
|
|
1785
|
+
* @param fastifyInstance - the server instance to register the routes on.
|
|
1786
|
+
*/
|
|
1787
|
+
async registerCookieRoutes(fastifyInstance) {
|
|
1788
|
+
const fastify = fastifyInstance ?? this._server;
|
|
1789
|
+
await fastify.register(fastifyCookie);
|
|
1790
|
+
await fastify.register(getCookiesRoute);
|
|
1791
|
+
await fastify.register(postCookieRoute);
|
|
1792
|
+
await fastify.register(deleteCookieRoute);
|
|
1793
|
+
}
|
|
1794
|
+
/**
|
|
1795
|
+
* Register the anything routes.
|
|
1796
|
+
* @param fastifyInstance - the server instance to register the routes on.
|
|
1797
|
+
*/
|
|
1798
|
+
async registerAnythingRoutes(fastifyInstance) {
|
|
1799
|
+
const fastify = fastifyInstance ?? this._server;
|
|
1800
|
+
await fastify.register(anythingRoute);
|
|
1801
|
+
}
|
|
1534
1802
|
};
|
|
1535
1803
|
|
|
1536
1804
|
// src/index.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jaredwray/mockhttp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Mock Http - Easy way to mock http with httpbin replacement",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"docker:readme": "tsx ./scripts/create-docker-readme.ts",
|
|
19
19
|
"docker:compose:up": "docker-compose up -d",
|
|
20
20
|
"docker:compose:down": "docker-compose down",
|
|
21
|
-
"prepare": "
|
|
21
|
+
"prepare": "pnpm run build",
|
|
22
22
|
"start": "node dist/index.js"
|
|
23
23
|
},
|
|
24
24
|
"repository": {
|
|
@@ -38,27 +38,28 @@
|
|
|
38
38
|
},
|
|
39
39
|
"homepage": "https://github.com/jaredwray/mockhttp#readme",
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@swc/core": "^1.
|
|
41
|
+
"@swc/core": "^1.12.1",
|
|
42
42
|
"@types/html-escaper": "^3.0.4",
|
|
43
|
-
"@vitest/coverage-v8": "^3.
|
|
43
|
+
"@vitest/coverage-v8": "^3.2.3",
|
|
44
44
|
"rimraf": "^6.0.1",
|
|
45
|
-
"tsup": "^8.
|
|
46
|
-
"tsx": "^4.
|
|
45
|
+
"tsup": "^8.5.0",
|
|
46
|
+
"tsx": "^4.20.3",
|
|
47
47
|
"typescript": "^5.8.3",
|
|
48
|
-
"vitest": "^3.
|
|
49
|
-
"xo": "^
|
|
48
|
+
"vitest": "^3.2.3",
|
|
49
|
+
"xo": "^1.1.0"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
+
"@fastify/cookie": "^11.0.2",
|
|
52
53
|
"@fastify/helmet": "^13.0.1",
|
|
53
|
-
"@fastify/static": "^8.
|
|
54
|
-
"@fastify/swagger": "^9.
|
|
55
|
-
"@fastify/swagger-ui": "^5.2.
|
|
56
|
-
"@scalar/api-reference": "^1.
|
|
54
|
+
"@fastify/static": "^8.2.0",
|
|
55
|
+
"@fastify/swagger": "^9.5.1",
|
|
56
|
+
"@fastify/swagger-ui": "^5.2.3",
|
|
57
|
+
"@scalar/api-reference": "^1.31.11",
|
|
57
58
|
"detect-port": "^2.1.0",
|
|
58
|
-
"fastify": "^5.
|
|
59
|
-
"hookified": "^1.
|
|
59
|
+
"fastify": "^5.4.0",
|
|
60
|
+
"hookified": "^1.9.1",
|
|
60
61
|
"html-escaper": "^3.0.3",
|
|
61
|
-
"pino": "^9.
|
|
62
|
+
"pino": "^9.7.0",
|
|
62
63
|
"pino-pretty": "^13.0.0"
|
|
63
64
|
},
|
|
64
65
|
"files": [
|
|
@@ -70,7 +71,14 @@
|
|
|
70
71
|
"onlyBuiltDependencies": [
|
|
71
72
|
"@swc/core",
|
|
72
73
|
"esbuild",
|
|
74
|
+
"unrs-resolver",
|
|
73
75
|
"vue-demi"
|
|
74
76
|
]
|
|
77
|
+
},
|
|
78
|
+
"xo": {
|
|
79
|
+
"rules": {
|
|
80
|
+
"@typescript-eslint/no-unsafe-call": "off",
|
|
81
|
+
"@typescript-eslint/no-unsafe-assignment": "off"
|
|
82
|
+
}
|
|
75
83
|
}
|
|
76
84
|
}
|