1+ /**
2+ * Express Route Detection
3+ *
4+ * This approach checks routes without making HTTP requests by
5+ * directly inspecting the Express app's routing table.
6+ */
7+
18import request from "supertest"
29import { jest } from "@jest/globals"
310import app from "../../app.js"
@@ -17,14 +24,13 @@ afterEach(() => {
1724} )
1825
1926/**
20- * Helper function to check if a route is registered in Express 5.
21- * In Express 5, app._router was replaced with app.router.
27+ * Check if a route exists in the Express app
2228 * Routes are checked by testing the matcher functions on each layer.
2329 *
2430 * @param {Array<string> } routes - Array of route paths to check
2531 * @returns {boolean } - True if all routes are found
2632 */
27- function checkRoutesExist ( routes ) {
33+ function routeExists ( routes ) {
2834 const stack = app . router . stack
2935 const foundRoutes = new Set ( )
3036
@@ -53,7 +59,7 @@ function checkRoutesExist(routes) {
5359describe ( "Check that the expected TinyNode create route patterns are registered." , ( ) => {
5460 it ( "'/app/create' and '/create' are registered routes in the app. __exists __core" , ( ) => {
5561 const routes = [ "/create" , "/app/create" ]
56- const exists = checkRoutesExist ( routes )
62+ const exists = routeExists ( routes )
5763 expect ( exists ) . toBe ( true )
5864 } )
5965} )
@@ -66,7 +72,7 @@ describe("Check that the expected TinyNode create route patterns are registered.
6672describe ( "Check that the expected TinyNode query route patterns are registered." , ( ) => {
6773 it ( "'/app/query' and '/query' are registered routes in the app. __exists __core" , ( ) => {
6874 const routes = [ "/query" , "/app/query" ]
69- const exists = checkRoutesExist ( routes )
75+ const exists = routeExists ( routes )
7076 expect ( exists ) . toBe ( true )
7177 } )
7278} )
@@ -79,7 +85,7 @@ describe("Check that the expected TinyNode query route patterns are registered."
7985describe ( "Check that the expected TinyNode update route patterns are registered." , ( ) => {
8086 it ( "'/app/update' and '/update' are registered routes in the app. __exists __core" , ( ) => {
8187 const routes = [ "/update" , "/app/update" ]
82- const exists = checkRoutesExist ( routes )
88+ const exists = routeExists ( routes )
8389 expect ( exists ) . toBe ( true )
8490 } )
8591} )
@@ -93,7 +99,7 @@ describe("Check that the expected TinyNode update route patterns are registered.
9399describe ( "Check that the expected TinyNode overwrite route patterns are registered." , ( ) => {
94100 it ( "'/app/overwrite' and '/overwrite' are registered routes in the app. __exists __core" , ( ) => {
95101 const routes = [ "/overwrite" , "/app/overwrite" ]
96- const exists = checkRoutesExist ( routes )
102+ const exists = routeExists ( routes )
97103 expect ( exists ) . toBe ( true )
98104 } )
99105} )
@@ -106,7 +112,7 @@ describe("Check that the expected TinyNode overwrite route patterns are register
106112describe ( "Combined unit tests for the '/delete' route." , ( ) => {
107113 it ( "'/app/delete' and '/delete' are registered routes in the app. __exists __core" , ( ) => {
108114 const routes = [ "/delete" , "/app/delete" ]
109- const exists = checkRoutesExist ( routes )
115+ const exists = routeExists ( routes )
110116 expect ( exists ) . toBe ( true )
111117 } )
112118} )
0 commit comments