MCPcopy Create free account
hub / github.com/avoidwork/tenso / createTestServer

Function createTestServer

benchmarks/load-test.js:13–94  ·  view source on GitHub ↗

* Creates a test server with various endpoints

(config = {})

Source from the content-addressed store, hash-verified

11 * Creates a test server with various endpoints
12 */
13function createTestServer (config = {}) {
14 const server = tenso({
15 port: 0, // Use random available port
16 silent: true,
17 logging: { enabled: false },
18 auth: { protect: [] },
19 rate: { enabled: false },
20 security: { csrf: false },
21 ...config
22 });
23
24 // Simple endpoints
25 server.get("/ping", (req, res) => {
26 res.send({ message: "pong", timestamp: Date.now() });
27 });
28
29 server.get("/hello", (req, res) => {
30 res.send({ message: "Hello World!" });
31 });
32
33 // JSON endpoint with data
34 server.get("/users", (req, res) => {
35 const users = Array.from({ length: 100 }, (_, i) => ({
36 id: i + 1,
37 name: `User ${i + 1}`,
38 email: `user${i + 1}@example.com`,
39 active: i % 2 === 0
40 }));
41 res.send({ users, total: users.length });
42 });
43
44 // Large JSON response
45 server.get("/large", (req, res) => {
46 const items = Array.from({ length: 1000 }, (_, i) => ({
47 id: i + 1,
48 title: `Item ${i + 1}`,
49 description: `This is a longer description for item ${i + 1}`,
50 metadata: {
51 created: new Date().toISOString(),
52 tags: [`tag${i % 10}`, "general"],
53 score: Math.random() * 100
54 }
55 }));
56 res.send({ items, total: items.length, generated: Date.now() });
57 });
58
59 // POST endpoint for testing request body handling
60 server.post("/echo", (req, res) => {
61 res.send({
62 received: req.body,
63 method: req.method,
64 timestamp: Date.now()
65 });
66 });
67
68 // Error endpoint for testing error handling
69 server.get("/error", (req, res) => {
70 res.error(500, "Intentional error for testing");

Callers 4

rateLimitLoadTestsFunction · 0.70
hypermediaEnabledTestsFunction · 0.70
hypermediaDisabledTestsFunction · 0.70
mainFunction · 0.70

Calls 1

tensoFunction · 0.90

Tested by

no test coverage detected