-
Notifications
You must be signed in to change notification settings - Fork 4
RERUM Server NPM Package Updates #220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a022670
b4a222d
432a0fa
ccc9812
f4757f8
accbc81
52ef1c5
1055aaa
5a845a5
b028f0f
1792832
af6addb
2b6d73c
822cab6
44ae06f
7be8dc7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,201 +1,108 @@ | ||
| /** | ||
| * Express Route Detection | ||
| * | ||
| * This approach checks routes without making HTTP requests by | ||
| * directly inspecting the Express app's routing table. | ||
| */ | ||
|
|
||
| import request from "supertest" | ||
| import { jest } from "@jest/globals" | ||
| import api_routes from "../routes/api-routes.js" | ||
| import app from "../app.js" | ||
| import fs from 'fs' | ||
| import fs from "fs" | ||
|
|
||
| let app_stack = app._router.stack | ||
| let app_stack = app.router.stack | ||
| let api_stack = api_routes.stack | ||
|
|
||
| /** | ||
| * Check if a route exists in the Express app | ||
| * @param {Array} stack - The router stack to search | ||
| * @param {string} testPath - The path to test for | ||
| * @returns {boolean} - True if the route exists | ||
| */ | ||
| function routeExists(stack, testPath) { | ||
| for (const layer of stack) { | ||
| // Check if layer has matchers (Express 5) | ||
| if (layer.matchers && layer.matchers.length > 0) { | ||
| const matcher = layer.matchers[0] | ||
| const match = matcher(testPath) | ||
| if (match && match.path) return true | ||
| } | ||
| // Also check route.path directly if it exists | ||
| if (layer.route && layer.route.path) { | ||
| if (layer.route.path === testPath || layer.route.path.includes(testPath)) return true | ||
| } | ||
| } | ||
| return false | ||
| } | ||
|
Comment on lines
+22
to
+36
|
||
|
|
||
| describe('Check to see that all expected top level route patterns exist.', () => { | ||
|
|
||
| it('/v1 -- mounted ', () => { | ||
| let exists = false | ||
| for (const middleware of app_stack) { | ||
| if (middleware.regexp && middleware.regexp.toString().includes("/v1")){ | ||
| exists = true | ||
| break | ||
| } | ||
| } | ||
| expect(exists).toBe(true) | ||
| expect(routeExists(app_stack, '/v1')).toBe(true) | ||
| }) | ||
|
|
||
| it('/client -- mounted ', () => { | ||
| let exists = false | ||
| for (const middleware of app_stack) { | ||
| if (middleware.regexp && middleware.regexp.toString().includes("/client")){ | ||
| exists = true | ||
| break | ||
| } | ||
| } | ||
| expect(exists).toBe(true) | ||
| expect(routeExists(app_stack, '/client')).toBe(true) | ||
| }) | ||
|
|
||
| it('/v1/id/{_id} -- mounted', () => { | ||
| let exists = false | ||
| for (const middleware of api_stack) { | ||
| if (middleware.regexp && middleware.regexp.toString().includes("/id")){ | ||
| exists = true | ||
| break | ||
| } | ||
| } | ||
| expect(exists).toBe(true) | ||
| expect(routeExists(api_stack, '/id')).toBe(true) | ||
| }) | ||
|
|
||
| it('/v1/since/{_id} -- mounted', () => { | ||
| let exists = false | ||
| for (const middleware of api_stack) { | ||
| if (middleware.regexp && middleware.regexp.toString().includes("/since")){ | ||
| exists = true | ||
| break | ||
| } | ||
| } | ||
| expect(exists).toBe(true) | ||
| expect(routeExists(api_stack, '/since')).toBe(true) | ||
| }) | ||
|
|
||
| it('/v1/history/{_id} -- mounted', () => { | ||
| let exists = false | ||
| for (const middleware of api_stack) { | ||
| if (middleware.regexp && middleware.regexp.toString().includes("/history")){ | ||
| exists = true | ||
| break | ||
| } | ||
| } | ||
| expect(exists).toBe(true) | ||
| expect(routeExists(api_stack, '/history')).toBe(true) | ||
| }) | ||
|
|
||
| }) | ||
|
|
||
| describe('Check to see that all /v1/api/ route patterns exist.', () => { | ||
|
|
||
| it('/v1/api/query -- mounted ', () => { | ||
| let exists = false | ||
| for (const middleware of api_stack) { | ||
| if (middleware.regexp | ||
| && middleware.regexp.toString().includes("/api") | ||
| && middleware.regexp.toString().includes("/query")){ | ||
| exists = true | ||
| break | ||
| } | ||
| } | ||
| expect(exists).toBe(true) | ||
| expect(routeExists(api_stack, '/api/query')).toBe(true) | ||
| }) | ||
|
|
||
| it('/v1/api/create -- mounted ', () => { | ||
| let exists = false | ||
| for (const middleware of api_stack) { | ||
| if (middleware.regexp | ||
| && middleware.regexp.toString().includes("/api") | ||
| && middleware.regexp.toString().includes("/create")){ | ||
| exists = true | ||
| break | ||
| } | ||
| } | ||
| expect(exists).toBe(true) | ||
| expect(routeExists(api_stack, '/api/create')).toBe(true) | ||
| }) | ||
|
|
||
| it('/v1/api/bulkCreate -- mounted ', () => { | ||
| let exists = false | ||
| for (const middleware of api_stack) { | ||
| if (middleware.regexp | ||
| && middleware.regexp.toString().includes("/api") | ||
| && middleware.regexp.toString().includes("/bulkCreate")){ | ||
| exists = true | ||
| break | ||
| } | ||
| } | ||
| expect(exists).toBe(true) | ||
| expect(routeExists(api_stack, '/api/bulkCreate')).toBe(true) | ||
| }) | ||
|
|
||
| it('/v1/api/update -- mounted ', () => { | ||
| let exists = false | ||
| for (const middleware of api_stack) { | ||
| if (middleware.regexp | ||
| && middleware.regexp.toString().includes("/api") | ||
| && middleware.regexp.toString().includes("/update")){ | ||
| exists = true | ||
| break | ||
| } | ||
| } | ||
| expect(exists).toBe(true) | ||
| expect(routeExists(api_stack, '/api/update')).toBe(true) | ||
| }) | ||
|
|
||
| it('/v1/api/bulkUpdate -- mounted ', () => { | ||
| let exists = false | ||
| for (const middleware of api_stack) { | ||
| if (middleware.regexp | ||
| && middleware.regexp.toString().includes("/api") | ||
| && middleware.regexp.toString().includes("/bulkUpdate")){ | ||
| exists = true | ||
| break | ||
| } | ||
| } | ||
| expect(exists).toBe(true) | ||
| expect(routeExists(api_stack, '/api/bulkUpdate')).toBe(true) | ||
| }) | ||
|
|
||
| it('/v1/api/overwrite -- mounted ', () => { | ||
| expect(routeExists(api_stack, '/api/overwrite')).toBe(true) | ||
| }) | ||
|
|
||
| it('/v1/api/patch -- mounted ', () => { | ||
| let exists = false | ||
| for (const middleware of api_stack) { | ||
| if (middleware.regexp | ||
| && middleware.regexp.toString().includes("/api") | ||
| && middleware.regexp.toString().includes("/patch")){ | ||
| exists = true | ||
| break | ||
| } | ||
| } | ||
| expect(exists).toBe(true) | ||
| expect(routeExists(api_stack, '/api/patch')).toBe(true) | ||
| }) | ||
|
|
||
| it('/v1/api/set -- mounted ', () => { | ||
| let exists = false | ||
| for (const middleware of api_stack) { | ||
| if (middleware.regexp | ||
| && middleware.regexp.toString().includes("/api") | ||
| && middleware.regexp.toString().includes("/set")){ | ||
| exists = true | ||
| break | ||
| } | ||
| } | ||
| expect(exists).toBe(true) | ||
| expect(routeExists(api_stack, '/api/set')).toBe(true) | ||
| }) | ||
|
|
||
| it('/v1/api/unset -- mounted ', () => { | ||
| let exists = false | ||
| for (const middleware of api_stack) { | ||
| if (middleware.regexp | ||
| && middleware.regexp.toString().includes("/api") | ||
| && middleware.regexp.toString().includes("/unset")){ | ||
| exists = true | ||
| break | ||
| } | ||
| } | ||
| expect(exists).toBe(true) | ||
| expect(routeExists(api_stack, '/api/unset')).toBe(true) | ||
| }) | ||
|
|
||
| it('/v1/api/delete/{id} -- mounted ', () => { | ||
| let exists = false | ||
| for (const middleware of api_stack) { | ||
| if (middleware.regexp | ||
| && middleware.regexp.toString().includes("/api") | ||
| && middleware.regexp.toString().includes("/delete")){ | ||
| exists = true | ||
| break | ||
| } | ||
| } | ||
| expect(exists).toBe(true) | ||
| expect(routeExists(api_stack, '/api/delete')).toBe(true) | ||
| }) | ||
|
|
||
| it('/v1/api/release/{id} -- mounted ', () => { | ||
| let exists = false | ||
| for (const middleware of api_stack) { | ||
| if (middleware.regexp | ||
| && middleware.regexp.toString().includes("/api") | ||
| && middleware.regexp.toString().includes("/release")){ | ||
| exists = true | ||
| break | ||
| } | ||
| } | ||
| expect(exists).toBe(true) | ||
| expect(routeExists(api_stack, '/api/release')).toBe(true) | ||
| }) | ||
|
|
||
| }) | ||
|
|
@@ -223,5 +130,8 @@ describe('Check to see that critical repo files are present', () => { | |
| expect(fs.existsSync(filePath+"CONTRIBUTING.md")).toBeTruthy() | ||
| expect(fs.existsSync(filePath+"README.md")).toBeTruthy() | ||
| expect(fs.existsSync(filePath+"LICENSE")).toBeTruthy() | ||
| expect(fs.existsSync(filePath+".gitignore")).toBeTruthy() | ||
| expect(fs.existsSync(filePath+"jest.config.js")).toBeTruthy() | ||
| expect(fs.existsSync(filePath+"package.json")).toBeTruthy() | ||
| }) | ||
| }) | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -69,7 +69,7 @@ app.use(express.static(path.join(__dirname, 'public'))) | |||||
| * If we are, then show the sad puppy. Otherwise, continue on. | ||||||
| * This is without middleware | ||||||
| */ | ||||||
| app.all('*', (req, res, next) => { | ||||||
| app.all('*_', (req, res, next) => { | ||||||
|
||||||
| app.all('*_', (req, res, next) => { | |
| app.all('*', (req, res, next) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NOT ANYMORE BECAUSE EXPRESS 5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Express exposes the router stack on app._router, not app.router. app.router is undefined in Express 4 and 5, which will cause a TypeError when accessing .stack. Use app._router.stack instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NOT ANYMORE BECAUSE EXPRESS 5