@jaredwray/mockhttp 0.5.0 → 0.6.1
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 +6 -0
- package/dist/index.js +140 -24
- package/package.json +20 -13
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ type HttpBinOptions = {
|
|
|
8
8
|
responseInspection?: boolean;
|
|
9
9
|
statusCodes?: boolean;
|
|
10
10
|
cookies?: boolean;
|
|
11
|
+
anything?: boolean;
|
|
11
12
|
};
|
|
12
13
|
type MockHttpOptions = {
|
|
13
14
|
/**
|
|
@@ -163,6 +164,11 @@ declare class MockHttp extends Hookified {
|
|
|
163
164
|
* @param fastifyInstance - the server instance to register the routes on.
|
|
164
165
|
*/
|
|
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>;
|
|
166
172
|
}
|
|
167
173
|
|
|
168
174
|
declare const start: () => Promise<MockHttp>;
|
package/dist/index.js
CHANGED
|
@@ -2,10 +2,10 @@ 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";
|
|
@@ -20,7 +20,7 @@ import { fastifySwaggerUi } from "@fastify/swagger-ui";
|
|
|
20
20
|
// package.json
|
|
21
21
|
var package_default = {
|
|
22
22
|
name: "@jaredwray/mockhttp",
|
|
23
|
-
version: "0.
|
|
23
|
+
version: "0.6.1",
|
|
24
24
|
description: "Mock Http - Easy way to mock http with httpbin replacement",
|
|
25
25
|
type: "module",
|
|
26
26
|
main: "dist/index.js",
|
|
@@ -58,28 +58,28 @@ var package_default = {
|
|
|
58
58
|
},
|
|
59
59
|
homepage: "https://github.com/jaredwray/mockhttp#readme",
|
|
60
60
|
devDependencies: {
|
|
61
|
-
"@swc/core": "^1.
|
|
61
|
+
"@swc/core": "^1.13.0",
|
|
62
62
|
"@types/html-escaper": "^3.0.4",
|
|
63
|
-
"@vitest/coverage-v8": "^3.
|
|
63
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
64
64
|
rimraf: "^6.0.1",
|
|
65
|
-
tsup: "^8.
|
|
66
|
-
tsx: "^4.
|
|
65
|
+
tsup: "^8.5.0",
|
|
66
|
+
tsx: "^4.20.3",
|
|
67
67
|
typescript: "^5.8.3",
|
|
68
|
-
vitest: "^3.
|
|
69
|
-
xo: "^
|
|
68
|
+
vitest: "^3.2.4",
|
|
69
|
+
xo: "^1.2.1"
|
|
70
70
|
},
|
|
71
71
|
dependencies: {
|
|
72
72
|
"@fastify/cookie": "^11.0.2",
|
|
73
73
|
"@fastify/helmet": "^13.0.1",
|
|
74
|
-
"@fastify/static": "^8.
|
|
74
|
+
"@fastify/static": "^8.2.0",
|
|
75
75
|
"@fastify/swagger": "^9.5.1",
|
|
76
|
-
"@fastify/swagger-ui": "^5.2.
|
|
77
|
-
"@scalar/api-reference": "^1.
|
|
76
|
+
"@fastify/swagger-ui": "^5.2.3",
|
|
77
|
+
"@scalar/api-reference": "^1.32.9",
|
|
78
78
|
"detect-port": "^2.1.0",
|
|
79
|
-
fastify: "^5.
|
|
80
|
-
hookified: "^1.
|
|
79
|
+
fastify: "^5.4.0",
|
|
80
|
+
hookified: "^1.10.0",
|
|
81
81
|
"html-escaper": "^3.0.3",
|
|
82
|
-
pino: "^9.
|
|
82
|
+
pino: "^9.7.0",
|
|
83
83
|
"pino-pretty": "^13.0.0"
|
|
84
84
|
},
|
|
85
85
|
files: [
|
|
@@ -91,8 +91,15 @@ var package_default = {
|
|
|
91
91
|
onlyBuiltDependencies: [
|
|
92
92
|
"@swc/core",
|
|
93
93
|
"esbuild",
|
|
94
|
+
"unrs-resolver",
|
|
94
95
|
"vue-demi"
|
|
95
96
|
]
|
|
97
|
+
},
|
|
98
|
+
xo: {
|
|
99
|
+
rules: {
|
|
100
|
+
"@typescript-eslint/no-unsafe-call": "off",
|
|
101
|
+
"@typescript-eslint/no-unsafe-assignment": "off"
|
|
102
|
+
}
|
|
96
103
|
}
|
|
97
104
|
};
|
|
98
105
|
|
|
@@ -219,7 +226,10 @@ var indexRoute = /* @__PURE__ */ __name((fastify) => {
|
|
|
219
226
|
<header class="custom-header scalar-app">
|
|
220
227
|
<a href="/"><img src="/logo.svg" alt="{ mockhttp }" /></a>
|
|
221
228
|
<a href="https://github.com/jaredwray/mockhttp" class="github-corner" aria-label="View source on GitHub">
|
|
222
|
-
<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>
|
|
223
233
|
</header>
|
|
224
234
|
|
|
225
235
|
<script
|
|
@@ -513,7 +523,7 @@ var patchRoute = /* @__PURE__ */ __name((fastify) => {
|
|
|
513
523
|
}, "patchRoute");
|
|
514
524
|
|
|
515
525
|
// src/routes/status-codes/index.ts
|
|
516
|
-
import { randomInt } from "
|
|
526
|
+
import { randomInt } from "crypto";
|
|
517
527
|
var statusCodes = [
|
|
518
528
|
{
|
|
519
529
|
code: 100,
|
|
@@ -886,7 +896,7 @@ var headersRoute = /* @__PURE__ */ __name((fastify) => {
|
|
|
886
896
|
fastify.get("/headers", {
|
|
887
897
|
schema: headersSchema
|
|
888
898
|
}, async (request) => {
|
|
889
|
-
const headers = request
|
|
899
|
+
const { headers } = request;
|
|
890
900
|
return {
|
|
891
901
|
headers
|
|
892
902
|
};
|
|
@@ -1142,9 +1152,9 @@ var absoluteRedirectRoute = /* @__PURE__ */ __name((fastify) => {
|
|
|
1142
1152
|
fastify.get("/absolute-redirect/:value", {
|
|
1143
1153
|
schema: absoluteRedirectSchema
|
|
1144
1154
|
}, async (request, reply) => {
|
|
1145
|
-
const value = request.params
|
|
1155
|
+
const { value } = request.params;
|
|
1146
1156
|
const { host } = request.headers;
|
|
1147
|
-
const protocol = request
|
|
1157
|
+
const { protocol } = request;
|
|
1148
1158
|
let url = `${protocol}://${host}/get`;
|
|
1149
1159
|
let html = `
|
|
1150
1160
|
<title>Redirecting...</title>
|
|
@@ -1203,7 +1213,7 @@ var relativeRedirectRoute = /* @__PURE__ */ __name((fastify) => {
|
|
|
1203
1213
|
fastify.get("/relative-redirect/:value", {
|
|
1204
1214
|
schema: relativeRedirectSchema
|
|
1205
1215
|
}, async (request, reply) => {
|
|
1206
|
-
const value = request.params
|
|
1216
|
+
const { value } = request.params;
|
|
1207
1217
|
let url = "/get";
|
|
1208
1218
|
let html = `
|
|
1209
1219
|
<title>Redirecting...</title>
|
|
@@ -1300,6 +1310,7 @@ var getCookiesRoute = /* @__PURE__ */ __name((fastify) => {
|
|
|
1300
1310
|
fastify.get("/cookies", {
|
|
1301
1311
|
schema: getCookiesRouteSchema
|
|
1302
1312
|
}, async (request, reply) => {
|
|
1313
|
+
reply.type("application/json");
|
|
1303
1314
|
await reply.send({
|
|
1304
1315
|
cookies: request.cookies
|
|
1305
1316
|
});
|
|
@@ -1407,6 +1418,100 @@ var deleteCookieRoute = /* @__PURE__ */ __name((fastify) => {
|
|
|
1407
1418
|
});
|
|
1408
1419
|
}, "deleteCookieRoute");
|
|
1409
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
|
+
|
|
1410
1515
|
// src/mock-http.ts
|
|
1411
1516
|
var MockHttp = class extends Hookified {
|
|
1412
1517
|
static {
|
|
@@ -1423,7 +1528,8 @@ var MockHttp = class extends Hookified {
|
|
|
1423
1528
|
requestInspection: true,
|
|
1424
1529
|
responseInspection: true,
|
|
1425
1530
|
statusCodes: true,
|
|
1426
|
-
cookies: true
|
|
1531
|
+
cookies: true,
|
|
1532
|
+
anything: true
|
|
1427
1533
|
};
|
|
1428
1534
|
// eslint-disable-next-line new-cap
|
|
1429
1535
|
_server = Fastify();
|
|
@@ -1512,7 +1618,6 @@ var MockHttp = class extends Hookified {
|
|
|
1512
1618
|
* Whether to use Swagger for API documentation. Defaults to true.
|
|
1513
1619
|
* @default true
|
|
1514
1620
|
*/
|
|
1515
|
-
// eslint-disable-next-line unicorn/prevent-abbreviations
|
|
1516
1621
|
set apiDocs(apiDocs) {
|
|
1517
1622
|
this._apiDocs = apiDocs;
|
|
1518
1623
|
}
|
|
@@ -1564,7 +1669,7 @@ var MockHttp = class extends Hookified {
|
|
|
1564
1669
|
if (this._apiDocs) {
|
|
1565
1670
|
await this.registerApiDocs();
|
|
1566
1671
|
}
|
|
1567
|
-
const { httpMethods, redirects, requestInspection, responseInspection, statusCodes: statusCodes2, cookies } = this._httpBin;
|
|
1672
|
+
const { httpMethods, redirects, requestInspection, responseInspection, statusCodes: statusCodes2, cookies, anything } = this._httpBin;
|
|
1568
1673
|
if (httpMethods) {
|
|
1569
1674
|
await this.registerHttpMethods();
|
|
1570
1675
|
}
|
|
@@ -1583,6 +1688,9 @@ var MockHttp = class extends Hookified {
|
|
|
1583
1688
|
if (cookies) {
|
|
1584
1689
|
await this.registerCookieRoutes();
|
|
1585
1690
|
}
|
|
1691
|
+
if (anything) {
|
|
1692
|
+
await this.registerAnythingRoutes();
|
|
1693
|
+
}
|
|
1586
1694
|
if (this._autoDetectPort) {
|
|
1587
1695
|
const originalPort = this._port;
|
|
1588
1696
|
this._port = await this.detectPort();
|
|
@@ -1683,6 +1791,14 @@ var MockHttp = class extends Hookified {
|
|
|
1683
1791
|
await fastify.register(postCookieRoute);
|
|
1684
1792
|
await fastify.register(deleteCookieRoute);
|
|
1685
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
|
+
}
|
|
1686
1802
|
};
|
|
1687
1803
|
|
|
1688
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.1",
|
|
4
4
|
"description": "Mock Http - Easy way to mock http with httpbin replacement",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -38,28 +38,28 @@
|
|
|
38
38
|
},
|
|
39
39
|
"homepage": "https://github.com/jaredwray/mockhttp#readme",
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@swc/core": "^1.
|
|
41
|
+
"@swc/core": "^1.13.0",
|
|
42
42
|
"@types/html-escaper": "^3.0.4",
|
|
43
|
-
"@vitest/coverage-v8": "^3.
|
|
43
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
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.4",
|
|
49
|
+
"xo": "^1.2.1"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"@fastify/cookie": "^11.0.2",
|
|
53
53
|
"@fastify/helmet": "^13.0.1",
|
|
54
|
-
"@fastify/static": "^8.
|
|
54
|
+
"@fastify/static": "^8.2.0",
|
|
55
55
|
"@fastify/swagger": "^9.5.1",
|
|
56
|
-
"@fastify/swagger-ui": "^5.2.
|
|
57
|
-
"@scalar/api-reference": "^1.
|
|
56
|
+
"@fastify/swagger-ui": "^5.2.3",
|
|
57
|
+
"@scalar/api-reference": "^1.32.9",
|
|
58
58
|
"detect-port": "^2.1.0",
|
|
59
|
-
"fastify": "^5.
|
|
60
|
-
"hookified": "^1.
|
|
59
|
+
"fastify": "^5.4.0",
|
|
60
|
+
"hookified": "^1.10.0",
|
|
61
61
|
"html-escaper": "^3.0.3",
|
|
62
|
-
"pino": "^9.
|
|
62
|
+
"pino": "^9.7.0",
|
|
63
63
|
"pino-pretty": "^13.0.0"
|
|
64
64
|
},
|
|
65
65
|
"files": [
|
|
@@ -71,7 +71,14 @@
|
|
|
71
71
|
"onlyBuiltDependencies": [
|
|
72
72
|
"@swc/core",
|
|
73
73
|
"esbuild",
|
|
74
|
+
"unrs-resolver",
|
|
74
75
|
"vue-demi"
|
|
75
76
|
]
|
|
77
|
+
},
|
|
78
|
+
"xo": {
|
|
79
|
+
"rules": {
|
|
80
|
+
"@typescript-eslint/no-unsafe-call": "off",
|
|
81
|
+
"@typescript-eslint/no-unsafe-assignment": "off"
|
|
82
|
+
}
|
|
76
83
|
}
|
|
77
84
|
}
|