test(server): port core's UO suite onto the ctx harness
22 test files moved from core, plus the two that were split out of files core keeps. 351 tests pass. One change runs through every moved test, and it is the boundary rather than a chore: core internals can no longer be stubbed by requiring them, because there are none to require. `../utils/db` and `../model/settings` do not exist here. What a test controls instead is the ctx core would have handed over, installed once by test/_setup.js -- which is a better seam anyway, since it is exactly the surface the contract promises and nothing wider. The ctx _setup installs is deliberately unfrozen. Core freezes what it hands a module and entry.test.js still asserts against a frozen one; but a test that needs settings.get to return a path has to be able to say so. Two tests changed SHAPE, and that is the boundary too. fromShardEvent used to assert through publish() into pushDevices and a captured fetch -- which endpoints were hit, how many requests went out. None of that is this module's any more: publish is ctx.push.publish, and the device registry and the relay are behind it. Reaching for them from here would be reaching past ctx. What remains is what the module owns and is the part worth guarding: a game account resolves to a website user, a personal target that resolves to nobody is dropped rather than published, and a sensitive kind never reaches publish at all. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
32
server/test/_helper.js
Normal file
32
server/test/_helper.js
Normal file
@@ -0,0 +1,32 @@
|
||||
// Test helper: start a throwaway Express app on an ephemeral port and return its
|
||||
// base URL + a close(). Uses the built-in fetch (Node 18+) so tests need no
|
||||
// extra HTTP dependency. Tests here exercise middleware in isolation and do NOT
|
||||
// touch the database.
|
||||
// The module takes express off ctx in shipped code; a test may resolve it
|
||||
// directly, because test/ never runs inside core's process (checkImports.js
|
||||
// allows devDependencies there). Same express either way — this repo pins the
|
||||
// version core declares.
|
||||
const express = require('express')
|
||||
|
||||
async function startApp(configure) {
|
||||
const app = express()
|
||||
app.use(express.json())
|
||||
configure(app)
|
||||
const server = await new Promise((resolve) => {
|
||||
const s = app.listen(0, '127.0.0.1', () => resolve(s))
|
||||
})
|
||||
const { port } = server.address()
|
||||
return {
|
||||
url: `http://127.0.0.1:${port}`,
|
||||
// `server.close()` stops accepting and waits for open connections to end on
|
||||
// their own — and node's global fetch keeps its sockets alive, so nothing
|
||||
// ever ends them. The listener then outlives the test that made it, which
|
||||
// used to be invisible because the pool held the process open anyway.
|
||||
close: () => new Promise((resolve) => {
|
||||
server.closeAllConnections()
|
||||
server.close(resolve)
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { startApp }
|
||||
Reference in New Issue
Block a user