- Connection pool and a small migration runner (schema_migrations, one transaction per migration, advisory lock) - games and game_players tables with indexes for a user's games and for popular games - PostgresGameHistoryRepository: idempotent save, get, recent games of a user, popular games - Integration tests against a real Postgres via testcontainers; a custom Jest environment gives tests Node's web globals, which Jest 27 leaves out - GameRecord carries the number of distinct spectators
20 lines
809 B
JavaScript
20 lines
809 B
JavaScript
// Jest 27's node environment runs tests in a context that lacks Node's newer web globals (ReadableStream, Blob,
|
|
// ...), which the HTTP client used by testcontainers needs. Copy whatever the context is missing from Node.
|
|
const NodeEnvironment = require("jest-environment-node");
|
|
|
|
// Reading these makes Node warn about its experimental web storage.
|
|
const SKIPPED = new Set(["localStorage", "sessionStorage"]);
|
|
|
|
class NodeEnvironmentWithWebGlobals extends NodeEnvironment {
|
|
constructor(config, context) {
|
|
super(config, context);
|
|
for (const name of Object.getOwnPropertyNames(globalThis)) {
|
|
if (!SKIPPED.has(name) && !(name in this.global)) {
|
|
this.global[name] = globalThis[name];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = NodeEnvironmentWithWebGlobals;
|