Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/cd_dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
strategy:
matrix:
node-version:
- 22
- 24
machines:
- vlcdhp02
runs-on: ${{ matrix.machines }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cd_prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
strategy:
matrix:
node-version:
- 22
- 24
machines:
- vlcdhprdp01
runs-on: ${{ matrix.machines }}
Expand Down
126 changes: 46 additions & 80 deletions __tests__/mount.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/**
* Express 5 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 app from "../app.js"
Expand All @@ -11,33 +18,48 @@ beforeEach(() => {

afterEach(() => {
/**
* Food for thought: delete data generated by tests?
* Food for thought: delete data generated by tests?
* Make a test.store available that uses the same annotationStoreTesting as RERUM tests?
*/
})

/**
* Check if a route exists in the Express app
* Routes are checked by testing the matcher functions on each layer.
* This is the Express 5.x compatible approach.
*
* @param {Array<string>} routes - Array of route paths to check
* @returns {boolean} - True if all routes are found
*/
function routeExists(routes) {
const stack = app.router.stack
const foundRoutes = new Set()
for (const layer of stack) {
if (layer.matchers && layer.matchers[0]) {
const matcher = layer.matchers[0]
// Test each route against this layer's matcher
for (const route of routes) {
if (matcher(route)) foundRoutes.add(route)
}
}
// Also check route.path directly if it exists
if (layer.route && layer.route.path) {
for (const route of routes) {
if (layer.route.path === route) foundRoutes.add(route)
}
}
}
return routes.every(route => foundRoutes.has(route))
}

/**
* This test suite uses the built app.js app and checks that the expected create endpoints are registered.
* - /create
* - /app/create
*/
describe("Check that the expected TinyNode create route patterns are registered.", () => {
describe("Check that the expected TinyPen create route patterns are registered.", () => {
it("'/app/create' and '/create' are registered routes in the app. __exists __core", () => {
let exists = false
let count = 0
const stack = app._router.stack
for (const middleware of stack) {
if (middleware.regexp && middleware.regexp.toString().includes("/app/create")) {
count++
} else if (middleware.regexp && middleware.regexp.toString().includes("/create")) {
count++
}
if (count === 2) {
exists = true
break
}
}
expect(exists).toBe(true)
expect(routeExists(["/create", "/app/create"])).toBe(true)
})
})

Expand All @@ -46,23 +68,9 @@ describe("Check that the expected TinyNode create route patterns are registered.
* - /query
* - /app/query
*/
describe("Check that the expected TinyNode query route patterns are registered.", () => {
describe("Check that the expected TinyPen query route patterns are registered.", () => {
it("'/app/query' and '/query' are registered routes in the app. __exists __core", () => {
let exists = false
let count = 0
const stack = app._router.stack
for (const middleware of stack) {
if (middleware.regexp && middleware.regexp.toString().includes("/app/query")) {
count++
} else if (middleware.regexp && middleware.regexp.toString().includes("/query")) {
count++
}
if (count === 2) {
exists = true
break
}
}
expect(exists).toBe(true)
expect(routeExists(["/query", "/app/query"])).toBe(true)
})
})

Expand All @@ -71,23 +79,9 @@ describe("Check that the expected TinyNode query route patterns are registered."
* - /update
* - /app/update
*/
describe("Check that the expected TinyNode update route patterns are registered.", () => {
describe("Check that the expected TinyPen update route patterns are registered.", () => {
it("'/app/update' and '/update' are registered routes in the app. __exists __core", () => {
let exists = false
let count = 0
const stack = app._router.stack
for (const middleware of stack) {
if (middleware.regexp && middleware.regexp.toString().includes("/app/update")) {
count++
} else if (middleware.regexp && middleware.regexp.toString().includes("/update")) {
count++
}
if (count === 2) {
exists = true
break
}
}
expect(exists).toBe(true)
expect(routeExists(["/update", "/app/update"])).toBe(true)
})
})

Expand All @@ -97,23 +91,9 @@ describe("Check that the expected TinyNode update route patterns are registered.
* - /overwrite
* - /app/overwrite
*/
describe("Check that the expected TinyNode overwrite route patterns are registered.", () => {
describe("Check that the expected TinyPen overwrite route patterns are registered.", () => {
it("'/app/overwrite' and '/overwrite' are registered routes in the app. __exists __core", () => {
let exists = false
let count = 0
const stack = app._router.stack
for (const middleware of stack) {
if (middleware.regexp && middleware.regexp.toString().includes("/app/overwrite")) {
count++
} else if (middleware.regexp && middleware.regexp.toString().includes("/overwrite")) {
count++
}
if (count === 2) {
exists = true
break
}
}
expect(exists).toBe(true)
expect(routeExists(["/overwrite", "/app/overwrite"])).toBe(true)
})
})

Expand All @@ -124,20 +104,6 @@ describe("Check that the expected TinyNode overwrite route patterns are register
*/
describe("Combined unit tests for the '/delete' route.", () => {
it("'/app/delete' and '/delete' are registered routes in the app. __exists __core", () => {
let exists = false
let count = 0
const stack = app._router.stack
for (const middleware of stack) {
if (middleware.regexp && middleware.regexp.toString().includes("/app/delete")) {
count++
} else if (middleware.regexp && middleware.regexp.toString().includes("/delete")) {
count++
}
if (count === 2) {
exists = true
break
}
}
expect(exists).toBe(true)
expect(routeExists(["/delete", "/app/delete"])).toBe(true)
})
})
5 changes: 2 additions & 3 deletions bin/testApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
import dotenv from "dotenv"
const storedEnv = dotenv.config()

import jest from "jest"
import runCLI from "jest-cli"
import { runCLI } from '@jest/core'
import app from "../app.js"
import http from "http"

Expand Down Expand Up @@ -99,7 +98,7 @@ function onError(error) {

async function onListening() {
console.log(`LISTENING ON ${port}`)
jest.runCLI(
runCLI(
{
"colors" : "true"
},
Expand Down
Loading