@prairielearn/express-list-endpoints 1.0.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/.mocharc.cjs +3 -0
- package/.turbo/turbo-build.log +0 -0
- package/LICENSE +22 -0
- package/README.md +9 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +160 -0
- package/dist/index.js.map +1 -0
- package/dist/index.test.d.ts +1 -0
- package/dist/index.test.js +491 -0
- package/dist/index.test.js.map +1 -0
- package/package.json +38 -0
- package/src/index.test.ts +638 -0
- package/src/index.ts +219 -0
- package/tsconfig.json +8 -0
|
@@ -0,0 +1,491 @@
|
|
|
1
|
+
import { assert } from 'chai';
|
|
2
|
+
import express from 'express';
|
|
3
|
+
import listEndpoints from '../src/index.js';
|
|
4
|
+
function assertResult(endpoints) {
|
|
5
|
+
assert.isArray(endpoints);
|
|
6
|
+
assert.lengthOf(endpoints, 2);
|
|
7
|
+
endpoints.forEach((endpoint) => {
|
|
8
|
+
assert.typeOf(endpoint, 'object');
|
|
9
|
+
assert.typeOf(endpoint.path, 'string');
|
|
10
|
+
assert.include(endpoint.path, '/');
|
|
11
|
+
assert.isArray(endpoint.methods);
|
|
12
|
+
endpoint.methods.forEach((method) => {
|
|
13
|
+
assert.typeOf(method, 'string');
|
|
14
|
+
assert.equal(method, method.toUpperCase());
|
|
15
|
+
assert.notEqual(method, '_ALL');
|
|
16
|
+
});
|
|
17
|
+
assert.isArray(endpoint.middlewares);
|
|
18
|
+
endpoint.middlewares.forEach((middleware) => {
|
|
19
|
+
assert.typeOf(middleware, 'string');
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
describe('listEndpoints', () => {
|
|
24
|
+
describe('when called with non configured app', () => {
|
|
25
|
+
let endpoints;
|
|
26
|
+
before(() => {
|
|
27
|
+
const app = express();
|
|
28
|
+
endpoints = listEndpoints(app);
|
|
29
|
+
});
|
|
30
|
+
it('should return an empty array', () => {
|
|
31
|
+
assert.isArray(endpoints);
|
|
32
|
+
assert.lengthOf(endpoints, 0);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
describe('when called over an app', () => {
|
|
36
|
+
let endpoints;
|
|
37
|
+
before(() => {
|
|
38
|
+
const app = express();
|
|
39
|
+
app
|
|
40
|
+
.route('/')
|
|
41
|
+
.get((_req, res) => {
|
|
42
|
+
res.end();
|
|
43
|
+
})
|
|
44
|
+
.all((_req, res) => {
|
|
45
|
+
res.end();
|
|
46
|
+
})
|
|
47
|
+
.post((_req, res) => {
|
|
48
|
+
res.end();
|
|
49
|
+
});
|
|
50
|
+
app
|
|
51
|
+
.route('/testing')
|
|
52
|
+
.all((_req, res) => {
|
|
53
|
+
res.end();
|
|
54
|
+
})
|
|
55
|
+
.delete((_req, res) => {
|
|
56
|
+
res.end();
|
|
57
|
+
});
|
|
58
|
+
endpoints = listEndpoints(app);
|
|
59
|
+
});
|
|
60
|
+
it('should return an array of well formed objects', () => {
|
|
61
|
+
assertResult(endpoints);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
describe('when called over a router', () => {
|
|
65
|
+
let endpoints;
|
|
66
|
+
before(() => {
|
|
67
|
+
const router = express.Router();
|
|
68
|
+
router
|
|
69
|
+
.route('/')
|
|
70
|
+
.get((_req, res) => {
|
|
71
|
+
res.end();
|
|
72
|
+
})
|
|
73
|
+
.all((_req, res) => {
|
|
74
|
+
res.end();
|
|
75
|
+
})
|
|
76
|
+
.post((_req, res) => {
|
|
77
|
+
res.end();
|
|
78
|
+
});
|
|
79
|
+
router
|
|
80
|
+
.route('/testing')
|
|
81
|
+
.all((_req, res) => {
|
|
82
|
+
res.end();
|
|
83
|
+
})
|
|
84
|
+
.delete((_req, res) => {
|
|
85
|
+
res.end();
|
|
86
|
+
});
|
|
87
|
+
endpoints = listEndpoints(router);
|
|
88
|
+
});
|
|
89
|
+
it('should return an array of well formed objects', () => {
|
|
90
|
+
assertResult(endpoints);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
describe('when called over an app with mounted routers', () => {
|
|
94
|
+
let endpoints;
|
|
95
|
+
before(() => {
|
|
96
|
+
const app = express();
|
|
97
|
+
const router = express.Router();
|
|
98
|
+
app
|
|
99
|
+
.route('/testing')
|
|
100
|
+
.all((_req, res) => {
|
|
101
|
+
res.end();
|
|
102
|
+
})
|
|
103
|
+
.delete((_req, res) => {
|
|
104
|
+
res.end();
|
|
105
|
+
});
|
|
106
|
+
router
|
|
107
|
+
.route('/')
|
|
108
|
+
.get((_req, res) => {
|
|
109
|
+
res.end();
|
|
110
|
+
})
|
|
111
|
+
.all((_req, res) => {
|
|
112
|
+
res.end();
|
|
113
|
+
})
|
|
114
|
+
.post((_req, res) => {
|
|
115
|
+
res.end();
|
|
116
|
+
});
|
|
117
|
+
app.use('/router', router);
|
|
118
|
+
endpoints = listEndpoints(app);
|
|
119
|
+
});
|
|
120
|
+
it('should return an array of well formed objects', () => {
|
|
121
|
+
assertResult(endpoints);
|
|
122
|
+
});
|
|
123
|
+
describe('and some of the routers has the option `mergeParams`', () => {
|
|
124
|
+
let endpoints;
|
|
125
|
+
before(() => {
|
|
126
|
+
const app = express();
|
|
127
|
+
const router = express.Router({ mergeParams: true });
|
|
128
|
+
router.get('/:id/friends', (_req, res) => {
|
|
129
|
+
res.end();
|
|
130
|
+
});
|
|
131
|
+
app.use('/router', router);
|
|
132
|
+
endpoints = listEndpoints(app);
|
|
133
|
+
});
|
|
134
|
+
it('should parse the endpoints correctly', () => {
|
|
135
|
+
assert.lengthOf(endpoints, 1);
|
|
136
|
+
assert.equal(endpoints[0].path, '/router/:id/friends');
|
|
137
|
+
});
|
|
138
|
+
describe('and also has a sub-router on the router', () => {
|
|
139
|
+
let endpoints;
|
|
140
|
+
before(() => {
|
|
141
|
+
const app = express();
|
|
142
|
+
const router = express.Router({ mergeParams: true });
|
|
143
|
+
const subRouter = express.Router();
|
|
144
|
+
subRouter.get('/', (_req, res) => {
|
|
145
|
+
res.end();
|
|
146
|
+
});
|
|
147
|
+
app.use('/router', router);
|
|
148
|
+
router.use('/:postId/sub-router', subRouter);
|
|
149
|
+
endpoints = listEndpoints(app);
|
|
150
|
+
});
|
|
151
|
+
it('should parse the endpoints correctly', () => {
|
|
152
|
+
assert.lengthOf(endpoints, 1);
|
|
153
|
+
assert.equal(endpoints[0].path, '/router/:postId/sub-router');
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
describe('when the defined routes', () => {
|
|
159
|
+
describe('contains underscores', () => {
|
|
160
|
+
let endpoints;
|
|
161
|
+
before(() => {
|
|
162
|
+
const router = express.Router();
|
|
163
|
+
router.get('/some_route', (_req, res) => {
|
|
164
|
+
res.end();
|
|
165
|
+
});
|
|
166
|
+
router.get('/some_other_router', (_req, res) => {
|
|
167
|
+
res.end();
|
|
168
|
+
});
|
|
169
|
+
router.get('/__last_route__', (_req, res) => {
|
|
170
|
+
res.end();
|
|
171
|
+
});
|
|
172
|
+
endpoints = listEndpoints(router);
|
|
173
|
+
});
|
|
174
|
+
it('should parse the endpoint correctly', () => {
|
|
175
|
+
assert.lengthOf(endpoints, 3);
|
|
176
|
+
assert.equal(endpoints[0].path, '/some_route');
|
|
177
|
+
assert.equal(endpoints[1].path, '/some_other_router');
|
|
178
|
+
assert.equal(endpoints[2].path, '/__last_route__');
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
describe('contains hyphens', () => {
|
|
182
|
+
let endpoints;
|
|
183
|
+
before(() => {
|
|
184
|
+
const router = express.Router();
|
|
185
|
+
router.get('/some-route', (_req, res) => {
|
|
186
|
+
res.end();
|
|
187
|
+
});
|
|
188
|
+
router.get('/some-other-router', (_req, res) => {
|
|
189
|
+
res.end();
|
|
190
|
+
});
|
|
191
|
+
router.get('/--last-route--', (_req, res) => {
|
|
192
|
+
res.end();
|
|
193
|
+
});
|
|
194
|
+
endpoints = listEndpoints(router);
|
|
195
|
+
});
|
|
196
|
+
it('should parse the endpoint correctly', () => {
|
|
197
|
+
assert.lengthOf(endpoints, 3);
|
|
198
|
+
assert.equal(endpoints[0].path, '/some-route');
|
|
199
|
+
assert.equal(endpoints[1].path, '/some-other-router');
|
|
200
|
+
assert.equal(endpoints[2].path, '/--last-route--');
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
describe('contains dots', () => {
|
|
204
|
+
let endpoints;
|
|
205
|
+
before(() => {
|
|
206
|
+
const router = express.Router();
|
|
207
|
+
router.get('/some.route', (_req, res) => {
|
|
208
|
+
res.end();
|
|
209
|
+
});
|
|
210
|
+
router.get('/some.other.router', (_req, res) => {
|
|
211
|
+
res.end();
|
|
212
|
+
});
|
|
213
|
+
router.get('/..last.route..', (_req, res) => {
|
|
214
|
+
res.end();
|
|
215
|
+
});
|
|
216
|
+
endpoints = listEndpoints(router);
|
|
217
|
+
});
|
|
218
|
+
it('should parse the endpoint correctly', () => {
|
|
219
|
+
assert.lengthOf(endpoints, 3);
|
|
220
|
+
assert.equal(endpoints[0].path, '/some.route');
|
|
221
|
+
assert.equal(endpoints[1].path, '/some.other.router');
|
|
222
|
+
assert.equal(endpoints[2].path, '/..last.route..');
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
describe('contains multiple different chars', () => {
|
|
226
|
+
let endpoints;
|
|
227
|
+
before(() => {
|
|
228
|
+
const router = express.Router();
|
|
229
|
+
router.get('/s0m3_r.oute', (_req, res) => {
|
|
230
|
+
res.end();
|
|
231
|
+
});
|
|
232
|
+
router.get('/v1.0.0', (_req, res) => {
|
|
233
|
+
res.end();
|
|
234
|
+
});
|
|
235
|
+
router.get('/not_sure.what-1m.d01ng', (_req, res) => {
|
|
236
|
+
res.end();
|
|
237
|
+
});
|
|
238
|
+
endpoints = listEndpoints(router);
|
|
239
|
+
});
|
|
240
|
+
it('should parse the endpoint correctly', () => {
|
|
241
|
+
assert.lengthOf(endpoints, 3);
|
|
242
|
+
assert.equal(endpoints[0].path, '/s0m3_r.oute');
|
|
243
|
+
assert.equal(endpoints[1].path, '/v1.0.0');
|
|
244
|
+
assert.equal(endpoints[2].path, '/not_sure.what-1m.d01ng');
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
describe('when called over a mounted router with only root path', () => {
|
|
249
|
+
let endpoints;
|
|
250
|
+
before(() => {
|
|
251
|
+
const app = express();
|
|
252
|
+
const router = express.Router();
|
|
253
|
+
router.get('/', (_req, res) => {
|
|
254
|
+
res.end();
|
|
255
|
+
});
|
|
256
|
+
app.use('/', router);
|
|
257
|
+
endpoints = listEndpoints(app);
|
|
258
|
+
});
|
|
259
|
+
it('should retrieve the list of endpoints and its methods', () => {
|
|
260
|
+
assert.lengthOf(endpoints, 1);
|
|
261
|
+
assert.equal(endpoints[0].path, '/');
|
|
262
|
+
assert.lengthOf(endpoints[0].methods, 1);
|
|
263
|
+
assert.equal(endpoints[0].methods[0], 'GET');
|
|
264
|
+
});
|
|
265
|
+
});
|
|
266
|
+
describe('when called over a multi-level base route', () => {
|
|
267
|
+
let endpoints;
|
|
268
|
+
before(() => {
|
|
269
|
+
const app = express();
|
|
270
|
+
const router = express.Router();
|
|
271
|
+
router.get('/my/path', (_req, res) => {
|
|
272
|
+
res.end();
|
|
273
|
+
});
|
|
274
|
+
app.use('/multi/level', router);
|
|
275
|
+
app.use('/super/duper/multi/level', router);
|
|
276
|
+
endpoints = listEndpoints(app);
|
|
277
|
+
});
|
|
278
|
+
it('should retrieve the correct built path', () => {
|
|
279
|
+
assert.lengthOf(endpoints, 2);
|
|
280
|
+
assert.equal(endpoints[0].path, '/multi/level/my/path');
|
|
281
|
+
assert.equal(endpoints[1].path, '/super/duper/multi/level/my/path');
|
|
282
|
+
});
|
|
283
|
+
describe('with params', () => {
|
|
284
|
+
let endpoints;
|
|
285
|
+
before(() => {
|
|
286
|
+
const app = express();
|
|
287
|
+
const router = express.Router();
|
|
288
|
+
router.get('/users/:id', (_req, res) => {
|
|
289
|
+
res.end();
|
|
290
|
+
});
|
|
291
|
+
router.get('/super/users/:id', (_req, res) => {
|
|
292
|
+
res.end();
|
|
293
|
+
});
|
|
294
|
+
app.use('/multi/:multiId/level/:levelId', router);
|
|
295
|
+
endpoints = listEndpoints(app);
|
|
296
|
+
});
|
|
297
|
+
it('should retrieve the correct built path', () => {
|
|
298
|
+
assert.lengthOf(endpoints, 2);
|
|
299
|
+
assert.equal(endpoints[0].path, '/multi/:multiId/level/:levelId/users/:id');
|
|
300
|
+
assert.equal(endpoints[1].path, '/multi/:multiId/level/:levelId/super/users/:id');
|
|
301
|
+
});
|
|
302
|
+
});
|
|
303
|
+
describe('with params in middle of the pattern', () => {
|
|
304
|
+
let endpoints;
|
|
305
|
+
before(() => {
|
|
306
|
+
const app = express();
|
|
307
|
+
const router = express.Router();
|
|
308
|
+
router.get('/super/users/:id/friends', (_req, res) => {
|
|
309
|
+
res.end();
|
|
310
|
+
});
|
|
311
|
+
app.use('/multi/level', router);
|
|
312
|
+
endpoints = listEndpoints(app);
|
|
313
|
+
});
|
|
314
|
+
it('should retrieve the correct built path', () => {
|
|
315
|
+
assert.lengthOf(endpoints, 1);
|
|
316
|
+
assert.equal(endpoints[0].path, '/multi/level/super/users/:id/friends');
|
|
317
|
+
});
|
|
318
|
+
});
|
|
319
|
+
});
|
|
320
|
+
describe('when called over a route with params', () => {
|
|
321
|
+
let endpoints;
|
|
322
|
+
before(() => {
|
|
323
|
+
const app = express();
|
|
324
|
+
app.get('/users/:id', (_req, res) => {
|
|
325
|
+
res.end();
|
|
326
|
+
});
|
|
327
|
+
endpoints = listEndpoints(app);
|
|
328
|
+
});
|
|
329
|
+
it('should retrieve the correct built path', () => {
|
|
330
|
+
assert.lengthOf(endpoints, 1);
|
|
331
|
+
assert.equal(endpoints[0].path, '/users/:id');
|
|
332
|
+
});
|
|
333
|
+
});
|
|
334
|
+
describe('when called over a route with params in middle of the pattern', () => {
|
|
335
|
+
let endpoints;
|
|
336
|
+
before(() => {
|
|
337
|
+
const app = express();
|
|
338
|
+
app.get('/users/:id/friends', (_req, res) => {
|
|
339
|
+
res.end();
|
|
340
|
+
});
|
|
341
|
+
endpoints = listEndpoints(app);
|
|
342
|
+
});
|
|
343
|
+
it('should retrieve the correct built path', () => {
|
|
344
|
+
assert.lengthOf(endpoints, 1);
|
|
345
|
+
assert.equal(endpoints[0].path, '/users/:id/friends');
|
|
346
|
+
});
|
|
347
|
+
});
|
|
348
|
+
describe('when called over a route with multiple methods with "/" path defined', () => {
|
|
349
|
+
let endpoints;
|
|
350
|
+
before(() => {
|
|
351
|
+
const router = express.Router();
|
|
352
|
+
router
|
|
353
|
+
.post('/test', (_req, res) => {
|
|
354
|
+
res.end();
|
|
355
|
+
})
|
|
356
|
+
.delete('/test', (_req, res) => {
|
|
357
|
+
res.end();
|
|
358
|
+
});
|
|
359
|
+
endpoints = listEndpoints(router);
|
|
360
|
+
});
|
|
361
|
+
it('should retrieve the correct built path', () => {
|
|
362
|
+
assert.lengthOf(endpoints, 1);
|
|
363
|
+
assert.equal(endpoints[0].path, '/test');
|
|
364
|
+
});
|
|
365
|
+
it('should retrieve the correct built methods', () => {
|
|
366
|
+
assert.lengthOf(endpoints[0].methods, 2);
|
|
367
|
+
assert.equal(endpoints[0].methods[0], 'POST');
|
|
368
|
+
assert.equal(endpoints[0].methods[1], 'DELETE');
|
|
369
|
+
});
|
|
370
|
+
});
|
|
371
|
+
describe('when called with middlewares', () => {
|
|
372
|
+
let endpoints;
|
|
373
|
+
before(() => {
|
|
374
|
+
const router = express.Router();
|
|
375
|
+
const exampleMiddleware = () => { };
|
|
376
|
+
router.post('/test', [
|
|
377
|
+
exampleMiddleware,
|
|
378
|
+
() => { }, // Anonymous middleware
|
|
379
|
+
]);
|
|
380
|
+
endpoints = listEndpoints(router);
|
|
381
|
+
});
|
|
382
|
+
it('should retrieve the correct built path', () => {
|
|
383
|
+
assert.lengthOf(endpoints, 1);
|
|
384
|
+
assert.equal(endpoints[0].path, '/test');
|
|
385
|
+
assert.lengthOf(endpoints[0].methods, 1);
|
|
386
|
+
assert.equal(endpoints[0].methods[0], 'POST');
|
|
387
|
+
});
|
|
388
|
+
it('should retrieve the correct middlewares', () => {
|
|
389
|
+
assert.lengthOf(endpoints[0].middlewares, 2);
|
|
390
|
+
assert.equal(endpoints[0].middlewares[0], 'exampleMiddleware');
|
|
391
|
+
assert.equal(endpoints[0].middlewares[1], 'anonymous');
|
|
392
|
+
});
|
|
393
|
+
});
|
|
394
|
+
describe('when called with an array of paths', () => {
|
|
395
|
+
let endpoints;
|
|
396
|
+
before(() => {
|
|
397
|
+
const app = express();
|
|
398
|
+
const router = express.Router();
|
|
399
|
+
app.get(['/one', '/two'], (_req, res) => {
|
|
400
|
+
res.end();
|
|
401
|
+
});
|
|
402
|
+
router.get(['/one', '/two'], (_req, res) => {
|
|
403
|
+
res.end();
|
|
404
|
+
});
|
|
405
|
+
app.use(['/router', '/sub-path'], router);
|
|
406
|
+
endpoints = listEndpoints(app);
|
|
407
|
+
});
|
|
408
|
+
it('should list routes correctly', () => {
|
|
409
|
+
assert.lengthOf(endpoints, 4);
|
|
410
|
+
assert.equal(endpoints[0].path, '/one');
|
|
411
|
+
assert.equal(endpoints[0].methods[0], 'GET');
|
|
412
|
+
assert.equal(endpoints[1].path, '/two');
|
|
413
|
+
assert.equal(endpoints[1].methods[0], 'GET');
|
|
414
|
+
});
|
|
415
|
+
});
|
|
416
|
+
describe('when called with an app with a mounted sub-app', () => {
|
|
417
|
+
let endpoints;
|
|
418
|
+
before(() => {
|
|
419
|
+
const app = express();
|
|
420
|
+
const subApp = express();
|
|
421
|
+
app.get('/', (_req, res) => {
|
|
422
|
+
res.end();
|
|
423
|
+
});
|
|
424
|
+
subApp.get('/', (_req, res) => {
|
|
425
|
+
res.end();
|
|
426
|
+
});
|
|
427
|
+
app.use('/sub-app', subApp);
|
|
428
|
+
endpoints = listEndpoints(app);
|
|
429
|
+
});
|
|
430
|
+
it('should list routes correctly', () => {
|
|
431
|
+
assert.lengthOf(endpoints, 2);
|
|
432
|
+
assert.equal(endpoints[0].path, '/');
|
|
433
|
+
assert.equal(endpoints[0].methods[0], 'GET');
|
|
434
|
+
assert.equal(endpoints[0].middlewares[0], 'anonymous');
|
|
435
|
+
assert.equal(endpoints[1].path, '/sub-app');
|
|
436
|
+
assert.lengthOf(endpoints[1].methods, 0);
|
|
437
|
+
assert.lengthOf(endpoints[1].middlewares, 0);
|
|
438
|
+
});
|
|
439
|
+
});
|
|
440
|
+
describe('when called with route params with regexp', () => {
|
|
441
|
+
let endpoints;
|
|
442
|
+
before(() => {
|
|
443
|
+
const app = express();
|
|
444
|
+
app.get('/foo/:item_id(\\d+)/bar', (_req, res) => {
|
|
445
|
+
res.end();
|
|
446
|
+
});
|
|
447
|
+
endpoints = listEndpoints(app);
|
|
448
|
+
});
|
|
449
|
+
it('should list routes correctly', () => {
|
|
450
|
+
assert.lengthOf(endpoints, 1);
|
|
451
|
+
assert.equal(endpoints[0].path, '/foo/:item_id/bar');
|
|
452
|
+
assert.equal(endpoints[0].methods[0], 'GET');
|
|
453
|
+
assert.equal(endpoints[0].middlewares[0], 'anonymous');
|
|
454
|
+
});
|
|
455
|
+
});
|
|
456
|
+
describe('when called with a route with multiple params with regexp', () => {
|
|
457
|
+
let endpoints;
|
|
458
|
+
before(() => {
|
|
459
|
+
const app = express();
|
|
460
|
+
app.get('/foo/bar/:baz_id(\\d+)/:biz_id(\\d+)', (_req, res) => {
|
|
461
|
+
res.end();
|
|
462
|
+
});
|
|
463
|
+
endpoints = listEndpoints(app);
|
|
464
|
+
});
|
|
465
|
+
it('should list routes correctly', () => {
|
|
466
|
+
assert.lengthOf(endpoints, 1);
|
|
467
|
+
assert.equal(endpoints[0].path, '/foo/bar/:baz_id/:biz_id');
|
|
468
|
+
assert.equal(endpoints[0].methods[0], 'GET');
|
|
469
|
+
assert.equal(endpoints[0].middlewares[0], 'anonymous');
|
|
470
|
+
});
|
|
471
|
+
});
|
|
472
|
+
describe('supports regexp validators for params in subapp', () => {
|
|
473
|
+
let endpoints;
|
|
474
|
+
before(() => {
|
|
475
|
+
const app = express();
|
|
476
|
+
const subApp = express.Router();
|
|
477
|
+
subApp.get('/baz/:biz_id(\\d+)', (_req, res) => {
|
|
478
|
+
res.end();
|
|
479
|
+
});
|
|
480
|
+
app.use('/foo/bar', subApp);
|
|
481
|
+
endpoints = listEndpoints(app);
|
|
482
|
+
});
|
|
483
|
+
it('should list routes correctly', () => {
|
|
484
|
+
assert.lengthOf(endpoints, 1);
|
|
485
|
+
assert.equal(endpoints[0].path, '/foo/bar/baz/:biz_id');
|
|
486
|
+
assert.equal(endpoints[0].methods[0], 'GET');
|
|
487
|
+
assert.equal(endpoints[0].middlewares[0], 'anonymous');
|
|
488
|
+
});
|
|
489
|
+
});
|
|
490
|
+
});
|
|
491
|
+
//# sourceMappingURL=index.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.test.js","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,OAAO,aAAgC,MAAM,iBAAiB,CAAC;AAE/D,SAAS,YAAY,CAAC,SAAqB;IACzC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAC1B,MAAM,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;IAE9B,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;QAC7B,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAElC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QACvC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;QAEnC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QACjC,QAAQ,CAAC,OAA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K,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;YAC7C,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC;QACzD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { assert } from 'chai';\nimport express from 'express';\n\nimport listEndpoints, { type Endpoint } from '../src/index.js';\n\nfunction assertResult(endpoints: Endpoint[]) {\n assert.isArray(endpoints);\n assert.lengthOf(endpoints, 2);\n\n endpoints.forEach((endpoint) => {\n assert.typeOf(endpoint, 'object');\n\n assert.typeOf(endpoint.path, 'string');\n assert.include(endpoint.path, '/');\n\n assert.isArray(endpoint.methods);\n endpoint.methods.forEach((method) => {\n assert.typeOf(method, 'string');\n assert.equal(method, method.toUpperCase());\n assert.notEqual(method, '_ALL');\n });\n\n assert.isArray(endpoint.middlewares);\n endpoint.middlewares.forEach((middleware) => {\n assert.typeOf(middleware, 'string');\n });\n });\n}\n\ndescribe('listEndpoints', () => {\n describe('when called with non configured app', () => {\n let endpoints: Endpoint[];\n\n before(() => {\n const app = express();\n\n endpoints = listEndpoints(app);\n });\n\n it('should return an empty array', () => {\n assert.isArray(endpoints);\n assert.lengthOf(endpoints, 0);\n });\n });\n\n describe('when called over an app', () => {\n let endpoints: Endpoint[];\n\n before(() => {\n const app = express();\n\n app\n .route('/')\n .get((_req, res) => {\n res.end();\n })\n .all((_req, res) => {\n res.end();\n })\n .post((_req, res) => {\n res.end();\n });\n\n app\n .route('/testing')\n .all((_req, res) => {\n res.end();\n })\n .delete((_req, res) => {\n res.end();\n });\n\n endpoints = listEndpoints(app);\n });\n\n it('should return an array of well formed objects', () => {\n assertResult(endpoints);\n });\n });\n\n describe('when called over a router', () => {\n let endpoints: Endpoint[];\n\n before(() => {\n const router = express.Router();\n\n router\n .route('/')\n .get((_req, res) => {\n res.end();\n })\n .all((_req, res) => {\n res.end();\n })\n .post((_req, res) => {\n res.end();\n });\n\n router\n .route('/testing')\n .all((_req, res) => {\n res.end();\n })\n .delete((_req, res) => {\n res.end();\n });\n\n endpoints = listEndpoints(router);\n });\n\n it('should return an array of well formed objects', () => {\n assertResult(endpoints);\n });\n });\n\n describe('when called over an app with mounted routers', () => {\n let endpoints: Endpoint[];\n\n before(() => {\n const app = express();\n const router = express.Router();\n\n app\n .route('/testing')\n .all((_req, res) => {\n res.end();\n })\n .delete((_req, res) => {\n res.end();\n });\n\n router\n .route('/')\n .get((_req, res) => {\n res.end();\n })\n .all((_req, res) => {\n res.end();\n })\n .post((_req, res) => {\n res.end();\n });\n\n app.use('/router', router);\n\n endpoints = listEndpoints(app);\n });\n\n it('should return an array of well formed objects', () => {\n assertResult(endpoints);\n });\n\n describe('and some of the routers has the option `mergeParams`', () => {\n let endpoints: Endpoint[];\n\n before(() => {\n const app = express();\n const router = express.Router({ mergeParams: true });\n\n router.get('/:id/friends', (_req, res) => {\n res.end();\n });\n\n app.use('/router', router);\n\n endpoints = listEndpoints(app);\n });\n\n it('should parse the endpoints correctly', () => {\n assert.lengthOf(endpoints, 1);\n assert.equal(endpoints[0].path, '/router/:id/friends');\n });\n\n describe('and also has a sub-router on the router', () => {\n let endpoints: Endpoint[];\n\n before(() => {\n const app = express();\n const router = express.Router({ mergeParams: true });\n const subRouter = express.Router();\n\n subRouter.get('/', (_req, res) => {\n res.end();\n });\n\n app.use('/router', router);\n\n router.use('/:postId/sub-router', subRouter);\n\n endpoints = listEndpoints(app);\n });\n\n it('should parse the endpoints correctly', () => {\n assert.lengthOf(endpoints, 1);\n assert.equal(endpoints[0].path, '/router/:postId/sub-router');\n });\n });\n });\n });\n\n describe('when the defined routes', () => {\n describe('contains underscores', () => {\n let endpoints: Endpoint[];\n\n before(() => {\n const router = express.Router();\n\n router.get('/some_route', (_req, res) => {\n res.end();\n });\n\n router.get('/some_other_router', (_req, res) => {\n res.end();\n });\n\n router.get('/__last_route__', (_req, res) => {\n res.end();\n });\n\n endpoints = listEndpoints(router);\n });\n\n it('should parse the endpoint correctly', () => {\n assert.lengthOf(endpoints, 3);\n assert.equal(endpoints[0].path, '/some_route');\n assert.equal(endpoints[1].path, '/some_other_router');\n assert.equal(endpoints[2].path, '/__last_route__');\n });\n });\n\n describe('contains hyphens', () => {\n let endpoints: Endpoint[];\n\n before(() => {\n const router = express.Router();\n\n router.get('/some-route', (_req, res) => {\n res.end();\n });\n\n router.get('/some-other-router', (_req, res) => {\n res.end();\n });\n\n router.get('/--last-route--', (_req, res) => {\n res.end();\n });\n\n endpoints = listEndpoints(router);\n });\n\n it('should parse the endpoint correctly', () => {\n assert.lengthOf(endpoints, 3);\n assert.equal(endpoints[0].path, '/some-route');\n assert.equal(endpoints[1].path, '/some-other-router');\n assert.equal(endpoints[2].path, '/--last-route--');\n });\n });\n\n describe('contains dots', () => {\n let endpoints: Endpoint[];\n\n before(() => {\n const router = express.Router();\n\n router.get('/some.route', (_req, res) => {\n res.end();\n });\n\n router.get('/some.other.router', (_req, res) => {\n res.end();\n });\n\n router.get('/..last.route..', (_req, res) => {\n res.end();\n });\n\n endpoints = listEndpoints(router);\n });\n\n it('should parse the endpoint correctly', () => {\n assert.lengthOf(endpoints, 3);\n assert.equal(endpoints[0].path, '/some.route');\n assert.equal(endpoints[1].path, '/some.other.router');\n assert.equal(endpoints[2].path, '/..last.route..');\n });\n });\n\n describe('contains multiple different chars', () => {\n let endpoints: Endpoint[];\n\n before(() => {\n const router = express.Router();\n\n router.get('/s0m3_r.oute', (_req, res) => {\n res.end();\n });\n\n router.get('/v1.0.0', (_req, res) => {\n res.end();\n });\n\n router.get('/not_sure.what-1m.d01ng', (_req, res) => {\n res.end();\n });\n\n endpoints = listEndpoints(router);\n });\n\n it('should parse the endpoint correctly', () => {\n assert.lengthOf(endpoints, 3);\n assert.equal(endpoints[0].path, '/s0m3_r.oute');\n assert.equal(endpoints[1].path, '/v1.0.0');\n assert.equal(endpoints[2].path, '/not_sure.what-1m.d01ng');\n });\n });\n });\n\n describe('when called over a mounted router with only root path', () => {\n let endpoints: Endpoint[];\n\n before(() => {\n const app = express();\n const router = express.Router();\n\n router.get('/', (_req, res) => {\n res.end();\n });\n\n app.use('/', router);\n\n endpoints = listEndpoints(app);\n });\n\n it('should retrieve the list of endpoints and its methods', () => {\n assert.lengthOf(endpoints, 1);\n assert.equal(endpoints[0].path, '/');\n assert.lengthOf(endpoints[0].methods, 1);\n assert.equal(endpoints[0].methods[0], 'GET');\n });\n });\n\n describe('when called over a multi-level base route', () => {\n let endpoints: Endpoint[];\n\n before(() => {\n const app = express();\n const router = express.Router();\n\n router.get('/my/path', (_req, res) => {\n res.end();\n });\n\n app.use('/multi/level', router);\n app.use('/super/duper/multi/level', router);\n\n endpoints = listEndpoints(app);\n });\n\n it('should retrieve the correct built path', () => {\n assert.lengthOf(endpoints, 2);\n assert.equal(endpoints[0].path, '/multi/level/my/path');\n assert.equal(endpoints[1].path, '/super/duper/multi/level/my/path');\n });\n\n describe('with params', () => {\n let endpoints: Endpoint[];\n\n before(() => {\n const app = express();\n const router = express.Router();\n\n router.get('/users/:id', (_req, res) => {\n res.end();\n });\n\n router.get('/super/users/:id', (_req, res) => {\n res.end();\n });\n\n app.use('/multi/:multiId/level/:levelId', router);\n\n endpoints = listEndpoints(app);\n });\n\n it('should retrieve the correct built path', () => {\n assert.lengthOf(endpoints, 2);\n assert.equal(endpoints[0].path, '/multi/:multiId/level/:levelId/users/:id');\n assert.equal(endpoints[1].path, '/multi/:multiId/level/:levelId/super/users/:id');\n });\n });\n\n describe('with params in middle of the pattern', () => {\n let endpoints: Endpoint[];\n\n before(() => {\n const app = express();\n const router = express.Router();\n\n router.get('/super/users/:id/friends', (_req, res) => {\n res.end();\n });\n\n app.use('/multi/level', router);\n\n endpoints = listEndpoints(app);\n });\n\n it('should retrieve the correct built path', () => {\n assert.lengthOf(endpoints, 1);\n assert.equal(endpoints[0].path, '/multi/level/super/users/:id/friends');\n });\n });\n });\n\n describe('when called over a route with params', () => {\n let endpoints: Endpoint[];\n\n before(() => {\n const app = express();\n\n app.get('/users/:id', (_req, res) => {\n res.end();\n });\n\n endpoints = listEndpoints(app);\n });\n\n it('should retrieve the correct built path', () => {\n assert.lengthOf(endpoints, 1);\n assert.equal(endpoints[0].path, '/users/:id');\n });\n });\n\n describe('when called over a route with params in middle of the pattern', () => {\n let endpoints: Endpoint[];\n\n before(() => {\n const app = express();\n\n app.get('/users/:id/friends', (_req, res) => {\n res.end();\n });\n\n endpoints = listEndpoints(app);\n });\n\n it('should retrieve the correct built path', () => {\n assert.lengthOf(endpoints, 1);\n assert.equal(endpoints[0].path, '/users/:id/friends');\n });\n });\n\n describe('when called over a route with multiple methods with \"/\" path defined', () => {\n let endpoints: Endpoint[];\n\n before(() => {\n const router = express.Router();\n\n router\n .post('/test', (_req, res) => {\n res.end();\n })\n .delete('/test', (_req, res) => {\n res.end();\n });\n\n endpoints = listEndpoints(router);\n });\n\n it('should retrieve the correct built path', () => {\n assert.lengthOf(endpoints, 1);\n assert.equal(endpoints[0].path, '/test');\n });\n\n it('should retrieve the correct built methods', () => {\n assert.lengthOf(endpoints[0].methods, 2);\n assert.equal(endpoints[0].methods[0], 'POST');\n assert.equal(endpoints[0].methods[1], 'DELETE');\n });\n });\n\n describe('when called with middlewares', () => {\n let endpoints: Endpoint[];\n\n before(() => {\n const router = express.Router();\n\n const exampleMiddleware = () => {};\n\n router.post('/test', [\n exampleMiddleware,\n () => {}, // Anonymous middleware\n ]);\n\n endpoints = listEndpoints(router);\n });\n\n it('should retrieve the correct built path', () => {\n assert.lengthOf(endpoints, 1);\n assert.equal(endpoints[0].path, '/test');\n assert.lengthOf(endpoints[0].methods, 1);\n assert.equal(endpoints[0].methods[0], 'POST');\n });\n\n it('should retrieve the correct middlewares', () => {\n assert.lengthOf(endpoints[0].middlewares, 2);\n assert.equal(endpoints[0].middlewares[0], 'exampleMiddleware');\n assert.equal(endpoints[0].middlewares[1], 'anonymous');\n });\n });\n\n describe('when called with an array of paths', () => {\n let endpoints: Endpoint[];\n\n before(() => {\n const app = express();\n const router = express.Router();\n\n app.get(['/one', '/two'], (_req, res) => {\n res.end();\n });\n\n router.get(['/one', '/two'], (_req, res) => {\n res.end();\n });\n\n app.use(['/router', '/sub-path'], router);\n\n endpoints = listEndpoints(app);\n });\n\n it('should list routes correctly', () => {\n assert.lengthOf(endpoints, 4);\n assert.equal(endpoints[0].path, '/one');\n assert.equal(endpoints[0].methods[0], 'GET');\n assert.equal(endpoints[1].path, '/two');\n assert.equal(endpoints[1].methods[0], 'GET');\n });\n });\n\n describe('when called with an app with a mounted sub-app', () => {\n let endpoints: Endpoint[];\n\n before(() => {\n const app = express();\n const subApp = express();\n\n app.get('/', (_req, res) => {\n res.end();\n });\n\n subApp.get('/', (_req, res) => {\n res.end();\n });\n\n app.use('/sub-app', subApp);\n\n endpoints = listEndpoints(app);\n });\n\n it('should list routes correctly', () => {\n assert.lengthOf(endpoints, 2);\n assert.equal(endpoints[0].path, '/');\n assert.equal(endpoints[0].methods[0], 'GET');\n assert.equal(endpoints[0].middlewares[0], 'anonymous');\n assert.equal(endpoints[1].path, '/sub-app');\n assert.lengthOf(endpoints[1].methods, 0);\n assert.lengthOf(endpoints[1].middlewares, 0);\n });\n });\n\n describe('when called with route params with regexp', () => {\n let endpoints: Endpoint[];\n\n before(() => {\n const app = express();\n\n app.get('/foo/:item_id(\\\\d+)/bar', (_req, res) => {\n res.end();\n });\n\n endpoints = listEndpoints(app);\n });\n\n it('should list routes correctly', () => {\n assert.lengthOf(endpoints, 1);\n assert.equal(endpoints[0].path, '/foo/:item_id/bar');\n assert.equal(endpoints[0].methods[0], 'GET');\n assert.equal(endpoints[0].middlewares[0], 'anonymous');\n });\n });\n\n describe('when called with a route with multiple params with regexp', () => {\n let endpoints: Endpoint[];\n\n before(() => {\n const app = express();\n\n app.get('/foo/bar/:baz_id(\\\\d+)/:biz_id(\\\\d+)', (_req, res) => {\n res.end();\n });\n\n endpoints = listEndpoints(app);\n });\n\n it('should list routes correctly', () => {\n assert.lengthOf(endpoints, 1);\n assert.equal(endpoints[0].path, '/foo/bar/:baz_id/:biz_id');\n assert.equal(endpoints[0].methods[0], 'GET');\n assert.equal(endpoints[0].middlewares[0], 'anonymous');\n });\n });\n\n describe('supports regexp validators for params in subapp', () => {\n let endpoints: Endpoint[];\n\n before(() => {\n const app = express();\n const subApp = express.Router();\n\n subApp.get('/baz/:biz_id(\\\\d+)', (_req, res) => {\n res.end();\n });\n\n app.use('/foo/bar', subApp);\n\n endpoints = listEndpoints(app);\n });\n\n it('should list routes correctly', () => {\n assert.lengthOf(endpoints, 1);\n assert.equal(endpoints[0].path, '/foo/bar/baz/:biz_id');\n assert.equal(endpoints[0].methods[0], 'GET');\n assert.equal(endpoints[0].middlewares[0], 'anonymous');\n });\n });\n});\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@prairielearn/express-list-endpoints",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/PrairieLearn/PrairieLearn.git",
|
|
10
|
+
"directory": "packages/express-list-endpoints"
|
|
11
|
+
},
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tsc",
|
|
14
|
+
"dev": "tsc --watch --preserveWatchOutput",
|
|
15
|
+
"test": "c8 mocha src/**/*.test.ts"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@prairielearn/tsconfig": "^0.0.0",
|
|
19
|
+
"@types/node": "^20.16.2",
|
|
20
|
+
"c8": "^10.1.2",
|
|
21
|
+
"chai": "^5.1.1",
|
|
22
|
+
"express": "^4.21.0",
|
|
23
|
+
"mocha": "^10.7.3",
|
|
24
|
+
"tsx": "^4.19.0",
|
|
25
|
+
"typescript": "^5.5.4"
|
|
26
|
+
},
|
|
27
|
+
"c8": {
|
|
28
|
+
"reporter": [
|
|
29
|
+
"html",
|
|
30
|
+
"text-summary",
|
|
31
|
+
"cobertura"
|
|
32
|
+
],
|
|
33
|
+
"all": true,
|
|
34
|
+
"include": [
|
|
35
|
+
"src/**"
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
}
|